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
104. Maximum Depth of Binary Tree Go
  • Loading branch information
MaratKhakim committed Jul 26, 2022
commit 5b10fd8bc63a90c49d79c81023c98f59b4e1ed42
14 changes: 14 additions & 0 deletions go/104-Maximum-Depth-of-Binary-Tree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
func maxDepth(root *TreeNode) int {
if root == nil {
return 0
}

left := maxDepth(root.Left)
right := maxDepth(root.Right)

if left > right {
return 1 + left
}

return right + 1
}