leetcode554

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

原文地址:https://www.cnblogs.com/asenyang/p/6970207.html