Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2025-12-11 23:47:05
记下每个轴上的最大最小值
如果有在这之间 就中了
def countCoveredBuildings(self, n: int, buildings: List[List[int]]) -> int:
x_mp = defaultdict()
y_mp = defaultdict()
for bld in buildings:
if bld[0] not in x_mp:
x_mp[bld[0]] = [bld[1], bld[1]]
else:
x_mp[bld[0]][0] = min(x_mp[bld[0]][0], bld[1])
x_mp[bld[0]][1] = max(x_mp[bld[0]][1], bld[1])
if bld[1] not in y_mp:
y_mp[bld[1]] = [bld[0], bld[0]]
else:
y_mp[bld[1]][0] = min(y_mp[bld[1]][0], bld[0])
y_mp[bld[1]][1] = max(y_mp[bld[1]][1], bld[0])
rets = 0
for bld in buildings:
if x_mp[bld[0]][0] < bld[1] < x_mp[bld[0]][1] and y_mp[bld[1]][0] <
bld[0] < y_mp[bld[1]][1]:
rets += 1
return rets
作者: JIWP (JIWP)   2024-12-11 23:47:00
你好厉害
作者: sixB (6B)   2025-12-11 23:50:00
我好崇拜你

Links booklink

Contact Us: admin [ a t ] ucptt.com