Skip to content

Commit 646e044

Browse files
committed
Runtime: 2 ms (Top 100.00%) | Memory: 50.3 MB (Top 97.37%)
1 parent 900bf67 commit 646e044

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
// Runtime: 2 ms (Top 100.00%) | Memory: 50.3 MB (Top 97.37%)
12
class Solution {
23
int ans = 0;
34
public int goodNodes(TreeNode root) {
45
if (root == null) return 0;
56
dfs(root, root.val);
67
return ans;
78
}
8-
9+
910
void dfs(TreeNode root, int mx) {
1011
if (root == null) return;
11-
12+
1213
mx = Math.max(mx, root.val);
1314
if(mx <= root.val) ans++;
14-
15+
1516
dfs(root.left, mx);
1617
dfs(root.right, mx);
17-
18+
1819
}
19-
}
20+
}

0 commit comments

Comments
 (0)