본문 바로가기
💻 하나씩 차곡차곡/프로그래머스 (Python)

[프로그래머스/python/Lv1] [PCCE 기출문제] 9번 이웃한 칸

by 뚜루리 2023. 12. 29.
728x90
320x100
def solution(board, h, w):
    n = len(board)
    count = 0
    dh,dw = [0, 1, -1, 0], [1, 0, 0, -1]
    
    for i in range(4):
        h_check, w_check = h + dh[i], w + dw[i]
        if 0 <= h_check < n  and  0 <= w_check < n and board[h][w] == board[h_check][w_check]:
            count += 1

    return count

 

728x90
320x100