C# Solution


  • 0
    public class Solution {
        public bool IsSymmetric(TreeNode root) {
            if (root == null || (root.left == null && root.right == null))
                return true;
            else
                return CheckSymmetric(root.left, root.right);
        }
        
        private bool CheckSymmetric(TreeNode leftNode, TreeNode rightNode)
        {
            if (leftNode == null && rightNode == null)
                return true;
            else if (leftNode != null && rightNode != null && leftNode.val == rightNode.val)
                return CheckSymmetric(leftNode.left, rightNode.right) && CheckSymmetric(leftNode.right, rightNode.left);
            else
                return false;
        }
    }

Log in to reply
 

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