小编Rax*_*ume的帖子

计算天际线面积时如何减少/优化内存使用?

我正在尝试计算天际线的面积(具有相同基线的重叠矩形)

building_count = int(input())
items = {} # dictionary, location on x axis is the key, height is the value
count = 0 # total area
for j in range(building_count):
    line = input().split(' ')
    H = int(line[0]) # height
    L = int(line[1]) # left point (start of the building)
    R = int(line[2]) # right point (end of the building)
    for k in range(R - L):
        if not (L+k in  items): # if it's not there, add it
            items[L+k] = H …
Run Code Online (Sandbox Code Playgroud)

python algorithm

1
推荐指数
1
解决办法
220
查看次数

标签 统计

algorithm ×1

python ×1