Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions maximum-depth-of-binary-tree/bus710.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package hello

type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}

func maxDepth(root *TreeNode) int {
if root == nil {
return 0
}
return count(root)
}

func count(node *TreeNode) int {
if node == nil {
return 0
}

lc := count(node.Left) + 1
rc := count(node.Right) + 1

if lc > rc {
return lc
}
return rc
}