Untitled
unknown
java
4 years ago
648 B
4
Indexable
class Solution {
int max;
int cant;
public int goodNodes(TreeNode root) {
if(root==null) return 0;
max=root.val;
cant=0;
preOrder(root);
return cant;
}
private void preOrder(TreeNode root){
if(root.val>=max){
max=root.val;
cant++;
}
int localMax=max;
if(root.left!=null)
preOrder(root.left);
max=localMax;
if(root.right!=null)
preOrder(root.right);
}
}Editor is loading...