Memory limit exceeded for recursion solution


#1

The output is showing Memory limit exceeded for simple recursion solution and I got only partial points. Please resolve the matter asap.


#2

Try this method

public class Solution {
public int isMirror(TreeNode first , TreeNode scnd)
{
if(first==null && scnd==null)
return 1;
if(first!=null && scnd!=null)
return (first.val==scnd.val?1:0) & isMirror(first.left,scnd.right) & isMirror(first.right,scnd.left);
return 0;
}

public int isSymmetric(TreeNode A) {
    if(A==null || (A.left==null && A.right==null))
        return 1;
    if(A.left!=null && A.right!=null)
        return isMirror(A.left,A.right);
    return 0;
}

}