Skip to content

Commit c60aadd

Browse files
authored
Merge pull request #1037 from bus710/week11
[bus710] Week 11
2 parents fd1ca34 + 68879e5 commit c60aadd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package hello
2+
3+
type TreeNode struct {
4+
Val int
5+
Left *TreeNode
6+
Right *TreeNode
7+
}
8+
9+
func maxDepth(root *TreeNode) int {
10+
if root == nil {
11+
return 0
12+
}
13+
return count(root)
14+
}
15+
16+
func count(node *TreeNode) int {
17+
if node == nil {
18+
return 0
19+
}
20+
21+
lc := count(node.Left) + 1
22+
rc := count(node.Right) + 1
23+
24+
if lc > rc {
25+
return lc
26+
}
27+
return rc
28+
}

0 commit comments

Comments
 (0)