We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 155c765 commit 72da592Copy full SHA for 72da592
Medium/L1448.go
@@ -0,0 +1,28 @@
1
+package Medium
2
+
3
+func goodNodes(root *TreeNode) int {
4
+ cnt := 0
5
+ if root == nil {
6
+ return cnt
7
+ }
8
+ dfs(root, root.Val, &cnt)
9
10
+}
11
12
+func dfs(root *TreeNode, val int, cnt *int) {
13
14
+ return
15
16
17
+ if root.Val >= val {
18
+ *cnt = (*cnt) + 1
19
20
21
+ max := val
22
+ if val < root.Val {
23
+ max = root.Val
24
25
26
+ dfs(root.Left, max, cnt)
27
+ dfs(root.Right, max, cnt)
28
0 commit comments