We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents fd1ca34 + 68879e5 commit c60aaddCopy full SHA for c60aadd
maximum-depth-of-binary-tree/bus710.go
@@ -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
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