As seen in the image , the evaluation of the same test case after RU and after SUBMIT are different.
I have encountered with this problem many times.
I dont see any trouble in my code:
class A{
boolean found=false;
}
class Solution {
private void f(TreeNode root,int currentsum, int targetsum,A a){
if (a.found) return;
if (root==null){
if (currentsum==targetsum){
a.found=true;
}
return;
}
currentsum=currentsum+root.val;
f(root.left,currentsum,targetsum,a);
f(root.right,currentsum,targetsum,a);
}
public boolean hasPathSum(TreeNode root, int targetSum) {
if (root==null) return false;
if (root.val==targetSum) return true;
A a=new A();
int currentsum=0;
f(root,currentsum,targetSum,a);
return a.found;
}}