add new solutions
This commit is contained in:
parent
886b5e0a8e
commit
67cad91898
47 changed files with 1549 additions and 1 deletions
28
solutions/14/q1448/solution.go
Normal file
28
solutions/14/q1448/solution.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package q1448
|
||||
|
||||
import "math"
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func gn(node *TreeNode, curMax int) int {
|
||||
if node == nil {
|
||||
return 0
|
||||
}
|
||||
self := 0
|
||||
if node.Val >= curMax {
|
||||
self = 1
|
||||
}
|
||||
|
||||
curMax = max(curMax, node.Val)
|
||||
return self + gn(node.Left, curMax) + gn(node.Right, curMax)
|
||||
}
|
||||
|
||||
func goodNodes(root *TreeNode) int {
|
||||
return gn(root, math.MinInt)
|
||||
}
|
||||
|
||||
var _ = goodNodes
|
||||
Loading…
Add table
Add a link
Reference in a new issue