首页 > 其他 > 详细

leetcode965

时间:2019-01-08 14:50:00      阅读:146      评论:0      收藏:0      [点我收藏+]
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;
        }
    }

 

leetcode965

原文:https://www.cnblogs.com/asenyang/p/10238347.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!