-
Notifications
You must be signed in to change notification settings - Fork 0
/
104.go
60 lines (44 loc) · 864 Bytes
/
104.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
# ------------------------------ #
# #
# version 0.0.1 #
# #
# Aleksiej Ostrowski, 2022 #
# #
# https://aleksiej.com #
# #
# ------------------------------ #
*/
package main
import (
"fmt"
)
/**
* Definition for a binary tree node.
**/
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func maxDepth_recc(root *TreeNode, cnt int) int {
if root == nil {
return cnt
}
cnt += 1
c1 := maxDepth_recc(root.Left, cnt)
c2 := maxDepth_recc(root.Right, cnt)
if c1 > c2 {
return c1
} else {
return c2
}
}
func maxDepth(root *TreeNode) int {
return maxDepth_recc(root, 0)
}
func main() {
tree := &TreeNode{0, nil, nil}
res := maxDepth(tree)
fmt.Println(res)
}