Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def pacificAtlantic(self, matrix):
- """
- :type matrix: List[List[int]]
- :rtype: List[List[int]]
- """
- def dfs(i, j, visited):
- if not visited[i][j]:
- visited[i][j] = True
- print "I AM ONLY SETTING THE FOLLOWING COORDINATES TO TRUE", i, j
- for row in visited:
- print row
- for x, y in ((0,1),(1,0),(-1,0),(0,-1)):
- x_coord, y_coord = i + x, j + y
- if 0<=x_coord<m and 0<=y_coord<n:
- if matrix[x_coord][y_coord] >= matrix[i][j]:
- dfs(x_coord,y_coord,visited)
- if not matrix or not matrix[0]:
- return [[]]
- m, n = len(matrix), len(matrix[0])
- p = [[False] * n] * m
- a = [[False] * n] * m
- #for row in p:
- # print row
- dfs(0,0,p)
- #for row in p:
- # print row
- #for i in range(m):
- # dfs(i, 0, p)
- # dfs(i, n-1, a)
- #for j in range(n):
- # dfs(0, j, p)
- # dfs(m-1, j, a)
- #return [(i,j) for i in range(m) for j in range(n) if a[i][j] and p[i][j]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement