Files
LeetCode-Go/Algorithms/0104. Maximum Depth of Binary Tree/104. Maximum Depth of Binary Tree.go
2019-06-09 14:09:02 +08:00

17 lines
284 B
Go

package leetcode
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func maxDepth(root *TreeNode) int {
if root == nil {
return 0
}
return max(maxDepth(root.Left), maxDepth(root.Right)) + 1
}