首页 > 其他 > 详细

leetcode554

时间:2017-06-09 09:13:37      阅读:254      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public int LeastBricks(IList<IList<int>> wall) {
        if (wall.Count == 0)
            {
                return 0;
            }
            int count = 0;
            Dictionary<int, int> map = new Dictionary<int, int>();
            foreach (var list in wall)
            {
                int length = 0;
                for (int i = 0; i < list.Count - 1; i++)
                {
                    length += list[i];
                    if (!map.ContainsKey(length))
                    {
                        map.Add(length, 1);
                    }
                    else
                    {
                        map[length]++;
                    }
                    count = Math.Max(count, map[length]);
                }
            }
            return wall.Count - count;
    }
}

https://leetcode.com/problems/brick-wall/#/description

leetcode554

原文:http://www.cnblogs.com/asenyang/p/6970207.html

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