File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -4,22 +4,21 @@ package main
4
4
import "math"
5
5
6
6
type TreeBalance struct {
7
- IsBalanced bool
8
- Height int
7
+ isBalanced bool
8
+ height int
9
9
}
10
10
11
11
func isBalanced (root * TreeNode ) bool {
12
- return checkBalance (root ).IsBalanced
12
+ return checkBalance (root ).isBalanced
13
13
}
14
14
15
- func checkBalance (root * TreeNode ) TreeBalance {
15
+ func checkBalance (root * TreeNode ) * TreeBalance {
16
16
if root == nil {
17
- return TreeBalance {true , 0 }
17
+ return & TreeBalance {true , 0 }
18
18
}
19
-
20
- l , r := checkBalance (root .Left ), checkBalance (root .Right )
21
- b := l .IsBalanced && r .IsBalanced &&
22
- math .Abs (float64 (l .Height - r .Height )) <= 1.0
23
- h := max (l .Height , r .Height ) + 1
24
- return TreeBalance {b , h }
19
+ left , right := checkBalance (root .Left ), checkBalance (root .Right )
20
+ isBalanced := left .isBalanced && right .isBalanced &&
21
+ math .Abs (float64 (left .height - right .height )) <= 1.0
22
+ height := max (left .height , right .height ) + 1
23
+ return & TreeBalance {isBalanced , height }
25
24
}
You can’t perform that action at this time.
0 commit comments