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;
        }
    }

 

posted on 2019-01-08 12:38  Sempron2800+  阅读(126)  评论(0编辑  收藏  举报