가장 원시적이라고 생각했던 방법이 좋은 방법 중 하나였다.
def queensAttack(n, k, r_q, c_q, obstacles):
# Write your code here
if n == 0:
return 0
# Timeout 방지
obs = dict()
if(obstacles):
for ob in obstacles:
obs[ob[0],ob[1]] = 1
row_move = [1, -1, 0, 0, 1, -1, 1, -1]
col_move = [0, 0, -1, 1, -1, -1, 1, 1]
tot_attack = 0
for r_m, c_m in zip(row_move, col_move):
r = r_q + r_m
c = c_q + c_m
while True:
if (r, c) in obs:
break
if r < 1 or r > n or c < 1 or c > n:
break
r += r_m
c += c_m
tot_attack += 1
return tot_attack
'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글
[HackerRank - python] ACM ICPC Team (0) | 2022.09.07 |
---|---|
[HackerRank-python] Equalize the Array (0) | 2022.08.24 |
Jumping on the Clouds (0) | 2022.08.23 |
[HackerRank-python] Repeated String (0) | 2022.08.22 |
[HackerRank-python] Non-Divisible Subset (0) | 2022.08.14 |