Concise Recursive Java Solution

  • 7

    This method is my best recursive try. Use two TreeNode as parameters.

    If you are willing to help,

    Please go to
    to see my another recursive solution and give some comment on that recursive method.

    public class Solution {
            public boolean isSymmetric(TreeNode root) {
                if(root==null){return true;}
                return isSymmetric(root.left, root.right);
            private boolean isSymmetric(TreeNode a, TreeNode b){
                if(a==null&&b==null){return true;}
                if(a==null||b==null){return false;}
                if(a.val!=b.val){return false;}
                return isSymmetric(a.left,b.right)&&isSymmetric(a.right,b.left);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.