예제 #1
0
        public bool IsSymmetric(TreeNode root)
        {
            bool ok;
            if (root == null)
            {
                return true;
            }

            ok = Rec(root.left, root.right);

            return ok;
        }
예제 #2
0
        public static bool Rec(TreeNode one, TreeNode two)
        {
            if (one == null && two == null)
            {
                return true;
            }
            else if (one == null || two == null)
            {
                return false;
            }
            else if (one.val != two.val)
            {
                return false;
            }

            bool ok = Rec(one.left, two.right)
                && Rec(one.right, two.left);

            return ok;
        }