C# - basic recursive


  • 0
    public bool IsSymmetric(TreeNode root) 
    {
        if (root == null) return true;
        return IsEqual(root.left, root.right);
    }
    
    public bool IsEqual(TreeNode left, TreeNode right)
    {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        if (left.val != right.val) return false;
        return IsEqual(left.left, right.right) && IsEqual(left.right, right.left);
    }

Log in to reply
 

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