프로그래머스5 - 방의 개수
def solution(arrows): direction = [ [0,1], [1,1], [1,0], [1,-1], [0,-1], [-1,-1], [-1,0], [-1,1], ] answer = 0 dic = {} path = {} x, y = 0, 0 dic[str([x, y])] = True for item in arrows: for i in range(2) : nextx, nexty = x + direction[item][0], y + direction[item][1] pathKey = str([x, y, nextx, nexty]) pathKey2 = str([nextx, nexty, x, y]) dicKey = str([nextx, nexty]) if not dicKey in dic : path[..
더보기
릿코드200 - 섬의 수
class Solution: def numIslands(self, grid: List[List[str]]) -> int: ans = 0 m = len(grid) n = len(grid[0]) for i in range(m) : for j in range(n) : if grid[i][j] == "1" : ans += 1 self.check(grid, i, j) return ans def check(self, grid, i, j) : dir = [ [1, 0], [0, 1], [-1, 0], [0, -1] ] stack = [[i,j]] while stack : i, j = stack.pop() grid[i][j] = 0 for direction in dir : X, Y = direction nextX, n..
더보기