class Solution:
def numIslands(self, grid: List[List[str]]) -> int:
m, n = len(grid), len(grid[0])
answer = 0
def bfs(x, y):
q = collections.deque([[x, y]])
while q:
x, y = q.popleft()
for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)):
nx = x + dx
ny = y + dy
if 0 <= nx < m and 0 <= ny < n and grid[nx][ny] == "1":
grid[nx][ny] = "0"
q.append([nx, ny])
return 1
for i in range(m):
for j in range(n):
if grid[i][j] == "1":
answer += bfs(i, j)
return answer
아 시간 뭔데