leetcode965

public class Solution
    {
        List<int> list = new List<int>();

        private void postTree(TreeNode root)
        {
            if (root != null)
            {
                list.Add(root.val);
                if (root.left != null)
                {
                    postTree(root.left);
                }
                if (root.right != null)
                {
                    postTree(root.right);
                }
            }
        }

        public bool IsUnivalTree(TreeNode root)
        {
            postTree(root);
            var count = list.GroupBy(x => x).Count();
            if (count == 1)
            {
                return true;
            }
            return false;
        }
    }

猜你喜欢

转载自www.cnblogs.com/asenyang/p/10238347.html