leetcode554

public class Solution {
    public int LeastBricks(IListint>> 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

你可能感兴趣的:(leetcode554)