One Line Recursive Java Solution


  • 0
    D
    public boolean isSymmetric(TreeNode root) {
      return root == null || isSymmetric(root.left, root.right);
    }
        
    private boolean isSymmetric(TreeNode left, TreeNode right) {
      return (left == null || right == null) ? left == right : left.val == right.val 
        && isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
    }
    

Log in to reply
 

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