전체 글(221)
-
[백준] 14503번 : 로봇청소기 (Python3)
from collections import deque N, M = map(int, input().split()) r, c, d = map(int, input().split()) rooms = [list(map(int, input().split())) for _ in range(N)] visited = [[False] * M for _ in range(N)] dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] cnt = 0 def bfs(x, y, d): global cnt q = deque() q.append((x, y)) visited[x][y] = True cnt += 1 while q: x, y = q.popleft() turn = 0 for i in range(4): d = (d ..
2024.03.19 -
[LeetCode] Kth Largest Element in an Array (Python)
보호되어 있는 글입니다.
2024.03.12 -
[LeetCode] Sort Colors (Python)
보호되어 있는 글입니다.
2024.03.12 -
[LeetCode] Keys and Rooms (Python)
보호되어 있는 글입니다.
2024.03.09 -
[LeetCods] 01Matrix (Python)
from collections import deque class Solution: def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]: row, col = len(mat), len(mat[0]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] INF = 1e9 q = deque() for i in range(row): for j in range(col): if mat[i][j] == 0: q.append((i, j)) else : mat[i][j] = INF while q: x, y = q.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] z = mat[x][y] + ..
2024.03.09 -
[LeetCode] Flood Fill (Python)
from collections import deque class Solution: def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]: before = image[sr][sc] row, col = len(image), len(image[0]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] if before != color: q = deque() q.append([sr, sc]) while q: x, y = q.popleft() image[x][y] = color for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0
2024.03.09