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 900bf67 commit 646e044Copy full SHA for 646e044
scripts/algorithms/C/Count Good Nodes in Binary Tree/Count Good Nodes in Binary Tree.java
@@ -1,19 +1,20 @@
1
+// Runtime: 2 ms (Top 100.00%) | Memory: 50.3 MB (Top 97.37%)
2
class Solution {
3
int ans = 0;
4
public int goodNodes(TreeNode root) {
5
if (root == null) return 0;
6
dfs(root, root.val);
7
return ans;
8
}
-
9
+
10
void dfs(TreeNode root, int mx) {
11
if (root == null) return;
12
13
mx = Math.max(mx, root.val);
14
if(mx <= root.val) ans++;
15
16
dfs(root.left, mx);
17
dfs(root.right, mx);
18
19
-}
20
+}
0 commit comments