题目:
题解:
class Solution:
def leastBricks(self, wall: List[List[int]]) -> int:
n = len(wall)
# heap内存放的格式为(前缀和、行、列)
heap = list()
ans = n
for i in range(n):
if len(wall[i]) > 1:
heapq.heappush(heap, [wall[i][0], i, 1])
while heap:
# 最左边的位置
count = 0
cur = heap[0][0]
while heap and heap[0][0] == cur:
count += 1
tmp = heapq.heappop(heap)
if tmp[2] + 1 < len(wall[tmp[1]]):
tmp[0] += wall[tmp[1]][tmp[2]]
tmp[2] += 1
heapq.heappush(heap, tmp)
if n - count < ans:
ans = n - count
return ans