u
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package top100liked
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// https://leetcode.cn/problems/maximum-depth-of-binary-tree/description/?envType=study-plan-v2&envId=top-100-liked
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func maxDepth(root *TreeNode) int {
|
||||
if root == nil {
|
||||
return 0
|
||||
}
|
||||
if root.Left == nil && root.Right == nil {
|
||||
return 1
|
||||
}
|
||||
md := 0
|
||||
if root.Left != nil {
|
||||
md = maxDepth(root.Left) + 1
|
||||
}
|
||||
if root.Right != nil {
|
||||
md = max(maxDepth(root.Right)+1, md)
|
||||
}
|
||||
return md
|
||||
}
|
||||
|
||||
func Test1(t *testing.T) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user