[PCCE 기출문제] 9번 / 이웃한 칸

Seohyun·2024년 8월 21일
0

알고리즘

목록 보기
22/36

문제 링크

def solution(board, h, w):
    n = len(board)
    count = 0
    
    move = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    
    for i in move:
        dh, dw = h + i[0], w + i[1]
        if dh >= 0 and dh < n and dw >= 0 and dw < n:
            if board[h][w] == board[dh][dw]:
                count += 1
                
    return count
profile
Hail hamster

0개의 댓글