Clean Java solution


  • 8
    J
    public class Solution {
        public boolean isSymmetric(TreeNode root) {
            return isSymmetric(root, root);
        }
        
        boolean isSymmetric(TreeNode n1, TreeNode n2) {
            if(n1 == null && n2 == null) return true;
            if(n1 == null || n2 == null) return false;
            if(n1.val != n2.val) return false;
            return isSymmetric(n1.left, n2.right) && isSymmetric(n2.right, n1.left);
        }
    }

Log in to reply
 

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