최대 1 분 소요

문제 링크

프로그래머스 - 안전지대

문제 풀이

def noBomb(board,r,c):
    plusList = [-1,0,1]
    
    rowLen = len(board)
    colLen = len(board[0])
    
    for i in plusList:
        for j in plusList:
            row = r+i
            col = c+j
            
            if row>=0 and row<rowLen and col>=0 and col<colLen:
                if board[row][col]:
                    return 0
    return 1
            
def solution(board):
    answer = 0
    
    row = len(board)
    col = len(board[0])
    
    for i in range(row):
        for j in range(col):
            if board[i][j]==0 and noBomb(board,i,j):
                answer = answer +1
    
    return answer

댓글남기기