Short AC Recursive solution in Java


  • 0
    G
    public boolean isSymmetric(TreeNode root) {
        return root == null || helper(root.left, root.right);
    }
    public boolean helper(TreeNode left, TreeNode right){
        return left == null && right == null || left != null && right != null && left.val == right.val && helper(left.left, right.right) && helper(left.right, right.left);
    }

Log in to reply
 

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