반응형
def rotate(board):
board = zip(*board[::-1])
return [list(b) for b in board]
def solution(key, lock):
n, m = len(key), len(lock)
zero = sum(lock, []).count(0)
lock = [[0] * 3 * m for _ in range(m)] +\
[[0] * m + lock[i] + [0] * m for i in range(m)] +\
[[0] * 3 * m for _ in range(m)]
for _ in range(4):
key = rotate(key)
for i in range(3 * m - n):
for j in range(3 * m - n):
temp, count = 0, 0
for k in range(n):
for l in range(n):
if m <= i + k < 2 * m and m <= j + l < 2 * m and key[k][l]:
if lock[i + k][j + l]:
temp = 1
break
else:
count += 1
if temp:
break
if count == zero:
return True
return False
구현, 완전탐색
lock을 가로세로로 세배 늘린뒤에 key를 한칸씩 대보면서 조건과 일치할 경우 True 리턴