思路

  • 做二叉树的题就是要学会画图,画图,画图发现递归即可

代码

public class Solution {
    boolean isSymmetrical(TreeNode pRoot)
    {if(pRoot==null){return true;}
     return isSyhelp(pRoot.left,pRoot.right);
    }

    boolean isSyhelp(TreeNode left,TreeNode right){
        if(left==null && right==null){return true;}
        if(left==null || right==null){return false;}
        return (left.val==right.val) && isSyhelp(left.left,right.right) && isSyhelp(left.right,right.left);
    }
}