[LeetCode] 200. Number of Islands
import collections class Solution: def numIslands(self, grid: List[List[str]]) -> int: visit = [ [False] *len(grid[0]) for i in range(len(grid))] cnt = 0 for i in range(len(grid)): for j in range(len(grid[0])): if visit[i][j] == False and grid[i][j]=="1": self.bfs(i,j,grid, visit, cnt) cnt = cnt+1 return cnt def bfs(self,i,j, grid,visit, cnt): direction = [(-1,0), (1,0), (0,1), (0,-1)] visit[i][..
2022. 3. 18.