0ms java recursive solution


  • 0
    V
    public boolean isSymmetric(TreeNode root) {
            
            if(root == null)
                return true;
           return check(root, root);
        }
        
        public boolean check(TreeNode node1, TreeNode node2)
        {
            if(node1 == null && node2 == null)
                return true;
            if(node1 != null && node2 != null && node1.val == node2.val)
                return (check(node1.left, node2.right) && check(node1.right, node2.left));
            return false;
        }
    

Log in to reply
 

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