-
[PCCE 기출문제] 9번 / 이웃한 칸코딩 테스트/Level 1 2024. 4. 3. 14:09반응형
https://school.programmers.co.kr/learn/courses/30/lessons/250125
def solution(board, h, w): answer = 0 for dh, dw in ((0, 1), (1, 0), (-1, 0), (0, -1)): if 0 <= (h_check := h + dh) < len(board) and 0 <= (w_check := w + dw) < len(board) and board[h_check][w_check] == board[h][w]: answer += 1 return answer print(solution( [["blue", "red", "orange", "red"], ["red", "red", "blue", "orange"], ["blue", "orange", "red", "red"], ["orange", "orange", "red", "blue"]], 0, 0 ))
반응형