1ms 2 liner DFS Java Solution


  • 0
    K
    public class Solution {
        public boolean isSymmetric(TreeNode root) {
            if(root == null) return true;
            return isSymmetric(root.left, root.right);
        }
        
        private boolean isSymmetric(TreeNode left, TreeNode right) {
            if(left == null && right == null) return true;
            return (left != null && right != null && 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.