Re: [閒聊] 每日leetcode
我最近真的好爛
這個我也寫老半天
==
一二三四五
我去死
def countUnguarded(self, m: int, n: int, guards: List[List[int]], walls:
List[List[int]]) -> int:
wall_guard_set = set()
for wall in walls:
wall_guard_set.add((wall[0], wall[1]))
for guard in guards:
wall_guard_set.add((guard[0], guard[1]))
arr = [[0 for _ in range(n)] for _ in range(m)]
sft = [1, 0, -1, 0, 1]
for guard in guards:
for i in range(4):
cur_i, cur_j = guard[0]+sft[i], guard[1]+sft[i+1]
while 0<=cur_i<m and 0<=cur_j<n and ((cur_i,cur_j) not in
wall_guard_set):
arr[cur_i][cur_j] = 1
cur_i += sft[i]
cur_j += sft[i+1]
return sum([sum([1 if row[i]==0 else 0 for i in range(n)]) for row in
arr]) - len(wall_guard_set)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1732200249.A.28A.html
留言