Clean Java code easy to understand

  • 0
        public boolean isSymmetric(TreeNode root) {
            if(root==null) return true;
            if(root.left==null && root.right==null) return true;
            return isSame(root.left, root.right);
        public boolean isSame(TreeNode left, TreeNode right){
            if(left==null && right==null) return true;
            else if(left==null || right==null) return false;
                if(left.val != right.val) return false;
                    return isSame(left.left, right.right)
                        &&isSame(left.right, right.left);

Log in to reply

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