-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0671.go
70 lines (61 loc) · 1.25 KB
/
0671.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
61
62
63
64
65
66
67
68
69
70
package main
func findSecondMinimumValue(root *TreeNode) int {
if root.Left == nil && root.Right == nil {
return -1
}
leftVal := root.Left.Val
rightVal := root.Right.Val
if root.Val == leftVal {
leftVal = findSecondMinimumValue(root.Left)
}
if rightVal == root.Val {
rightVal = findSecondMinimumValue(root.Right)
}
if leftVal == -1 && rightVal == -1 {
return getTwoMinNumber(leftVal, rightVal)
}
if leftVal == -1 {
return rightVal
}
if rightVal == -1 {
return leftVal
}
return 0
}
//第二大
//func findSecondMinimumValue(root *TreeNode) int {
// leafNodes := getLeafNode(root)
//
// var maxNodeVal = 0
// var secNodeVal = 0
//
// for _, node := range leafNodes {
// if node.Val > maxNodeVal {
// secNodeVal = maxNodeVal
// maxNodeVal = node.Val
// } else {
// if node.Val > secNodeVal {
// secNodeVal = node.Val
// }
// }
// }
// return secNodeVal
//}
//
//func getLeafNode(root *TreeNode) []*TreeNode {
//
// var leafList []*TreeNode
//
// if root == nil {
// return nil
// }
//
// if root.Left == nil && root.Right == nil {
// leafList = append(leafList, root)
// return leafList
// }
//
// leafList = append(leafList, getLeafNode(root.Left)...)
// leafList = append(leafList, getLeafNode(root.Right)...)
// return leafList
//}