Skip to content

Commit

Permalink
feat: 0110.Balanced-Binary-Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
kimi0230 committed Feb 20, 2024
1 parent 780bc37 commit cea1ba9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion Leetcode/0110.Balanced-Binary-Tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func IsBalanced(root *TreeNode) bool {
leftHight := depth(root.Left)
rightHight := depth(root.Right)

// return abs(leftHight-rightHight) <= 1
return abs(leftHight-rightHight) <= 1 && IsBalanced(root.Left) && IsBalanced(root.Right)
}

Expand Down
1 change: 0 additions & 1 deletion Leetcode/0110.Balanced-Binary-Tree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func IsBalanced(root *TreeNode) bool {
leftHight := depth(root.Left)
rightHight := depth(root.Right)

// return abs(leftHight-rightHight) <= 1
return abs(leftHight-rightHight) <= 1 && IsBalanced(root.Left) && IsBalanced(root.Right)
}

Expand Down
8 changes: 8 additions & 0 deletions Leetcode/0110.Balanced-Binary-Tree/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ var tests = []struct {
[]int{1, 2, 2, 3, structures.NULL, structures.NULL, 3, 4, structures.NULL, structures.NULL, 4},
false,
},
{
[]int{1, 2, 2, 3, structures.NULL, structures.NULL, 3, 4, structures.NULL, structures.NULL, 4},
false,
},
{
[]int{3, 9, 20, structures.NULL, structures.NULL, 15, 7},
true,
},
}

func TestIsBalanced(t *testing.T) {
Expand Down

0 comments on commit cea1ba9

Please sign in to comment.