Simple Java Solution using Recursion


  • 2
    public boolean isSymmetric(TreeNode root) {
            if(root==null) return true;
            return isSame(root.left,root.right);
        }
        
        public static Boolean isSame(TreeNode t1,TreeNode t2){
            if(t1==null && t2 == null)return true;
            if(t1==null || t2 == null)return false;
            if(t1.val == t2.val) 
                return isSame(t1.left,t2.right) && isSame(t1.right,t2.left);
            else 
                return false;
            
        }
    

Log in to reply
 

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