def solution(key, lock):
# 시계방향 회전
def rotate(cur):
new = [[0 for _ in range(len(key))] for _ in range(len(key))]
for i in range(len(key)):
for j in range(len(key)):
new[j][len(key)-i-1] = cur[i][j]
return new
def isMatch(key, l, x, y):
for i in range(len(l)):
for j in range(len(l)):
if 0<= i-x < len(key) and 0<= j-y<len(key):
l[i][j] += key[i-x][j-y]
if l[i][j] != 1:
return False
return True
for _ in range(4):
for x in range(-1*len(key)+1,len(lock)+len(key)):
for y in range(-1*len(key)+1,len(lock)+len(key)):
if isMatch(key, [k[:] for k in lock], x, y):
return True
key = rotate(key)
return False
rotate
: 회전된 열쇠를 return 한다
isMatch
: 열쇠와 자물쇠가 맞는 지 확인한다
[k[:] for k in list]
처럼 deep copy 를 해줘야 한다는 것.