Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a121e7a

Browse files
aQuaaQua
aQua
authored and
aQua
committedSep 14, 2017
111 wrong answer
1 parent 359815b commit a121e7a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed
 

‎Algorithms/0111.minimum-depth-of-binary-tree/minimum-depth-of-binary-tree.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@ func minDepth(root *TreeNode) int {
1111
return 0
1212
}
1313

14+
// 题目很奇葩的规定
15+
// inorder[1] 的最短深度为 1
16+
// inorder[1, 2] 的最短深度为 2
1417
if root.Left == nil && root.Right == nil {
1518
return 1
1619
}
1720

18-
return max(2, cur(root))
19-
}
20-
21-
func cur(node *TreeNode) int {
22-
if node == nil {
23-
return 1
24-
}
25-
26-
return min(minDepth(node.Left), minDepth(node.Right)) +1
21+
return max(2, min(minDepth(root.Left),minDepth(root.Right ))+1)
2722
}
2823

2924
func max(a, b int) int {

‎Algorithms/0111.minimum-depth-of-binary-tree/minimum-depth-of-binary-tree_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ func Test_Problem0111(t *testing.T) {
1717
ans int
1818
}{
1919

20+
{
21+
[]int{1, 2, 3, 4, 5},
22+
[]int{5, 4, 3, 2, 1},
23+
5,
24+
},
25+
2026
{
2127
[]int{1, 2},
2228
[]int{2, 1},

0 commit comments

Comments
 (0)
Please sign in to comment.