leetcode1020】的更多相关文章

Given a 2D array A, each cell is 0 (representing sea) or 1 (representing land) A move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid. Return the number of land squares in the grid for…
class Solution(object): def __init__(self): self.cons = 0 self.S = list() def dfs(self,m,n,v,A): while len(self.S) > 0: cur = self.S.pop(-1) cur_x = cur[0] cur_y = cur[1] v[cur_x][cur_y] = 1 self.cons += 1 if cur_x > 0 and A[cur_x-1][cur_y]==1 and v…