https://app.codesignal.com/interview-practice/task/SKZ45AF99NpbnvgTn
sudoku2 | CodeSignal
Press space bar to start a drag. When dragging you can use the arrow keys to move the item around and escape to cancel. Some screen readers may require you to be in focus mode or to use your pass through key
app.codesignal.com
✔️문제 요약
1.가로 세로의 중복이 없고, (3x3) 사각형 내에서도 중복이 없으면 True, 있으면 False
✔️풀이 방법
1.3X3 중복체크
2.가로 중복체크
3.세로 중복체크
(좋은 풀이는 아닌 것 같다)
#'.'을 지우고, 리스트내에 중복이 있으면 True, 중복이 없으면 False를 반환하는 함수 생성
def duplicate(list):
while '.' in list:
list.remove('.')
return len(list) != len(set(list))
def solution(grid):
#3x3 중복체크
#3x3에 있는 요소들을 한 리스트에 집어넣은뒤, duplicate함수 때리기
check_3x3=[]
for i in (3,6,9):
for j in (3,6,9):
for l in range(i-3,i):
for m in range(j-3,j):
check_3x3.append(grid[l][m])
if duplicate(check_3x3) == True:
return False
else:
check_3x3=[]
#세로 체크용 행/열 전환
trans_grid=list(map(list,zip(*grid)))
#가로 체크
for i in grid:
for j in grid:
if duplicate(j) == True:
return False
#세로 체크
for i in trans_grid:
for j in trans_grid:
if duplicate(j) == True:
return False
return True
✔️고찰
-좋은 풀이는 아닌 것 같다..그래도 내 딴에 제일 직관적으로 풀이안보고 풀었는데 나중에 실력이 늘고 다시 풀어봐야겠다 ㅜㅠㅠ 그래도 뿌듯!
'코딩테스트 > 코딩테스트 Python' 카테고리의 다른 글
[CodeSignal] simplifyPath (Python) (0) | 2022.10.21 |
---|---|
[CodeSignal] isTreeSymmetric (Python) (0) | 2022.10.07 |
[CodeSignal] firstNotRepeatingCharacter (Python) (0) | 2022.09.19 |
[CodeSignal] findProfession (Python) (0) | 2022.09.19 |
[CodeSignal] rotateImage (Python) (0) | 2022.09.14 |
댓글