mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-14 16:14:52 +08:00
17 lines
284 B
Go
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
|
|
}
|