Skip to content

Commit

Permalink
�DFS Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Nov 2, 2018
1 parent 7613856 commit c3a6bc5
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lc200. Number of Islands(DFS).py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import queue


class Solution:

def numIslands(self, grid):
Expand All @@ -9,9 +6,6 @@ def numIslands(self, grid):
:rtype: int
"""
def bfs(i, j):
# while not q.empty():

# isl = q.get()
if i < 0 or i >= length:
return
if j < 0 or j >= length0:
Expand All @@ -27,23 +21,20 @@ def bfs(i, j):
res = 0
length = len(grid)
length0 = len(grid[0])

# q = queue.Queue()
visited = [[0] * length0 for i in range(length)]

for i in range(length):
for j in range(length0):
if not visited[i][j] and grid[i][j] == '1':
bfs(i, j)
res += 1

return res


snum = '''11110
11010
snum = '''11000
11000
00000'''
00100
00011'''
slst = snum.split('\n')
grid = [[int(x) for x in list(s)] for s in slst]
soln = Solution()
Expand Down

0 comments on commit c3a6bc5

Please sign in to comment.