Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. class Solution(object):
  2. def pacificAtlantic(self, matrix):
  3. """
  4. :type matrix: List[List[int]]
  5. :rtype: List[List[int]]
  6. """
  7. def dfs(i, j, visited):
  8. if not visited[i][j]:
  9. print i, j
  10. for row in visited:
  11. print row
  12. for x, y in ((0,1),(1,0),(-1,0),(0,-1)):
  13. x_coord, y_coord = x + i, j + y
  14. if 0<=x_coord<m and 0<=y_coord<n:
  15. if matrix[x_coord][y_coord] >= matrix[i][j]:
  16. dfs(x_coord,y_coord,visited)
  17.  
  18. if not matrix or not matrix[0]:
  19. return [[]]
  20.  
  21. m, n = len(matrix), len(matrix[0])
  22.  
  23. p = [[False] * n] * m
  24. a = [[False] * n] * m
  25.  
  26. #for row in p:
  27. # print row
  28.  
  29. dfs(0,0,p)
  30.  
  31. #for row in p:
  32. # print row
  33.  
  34. #for i in range(m):
  35. # dfs(i, 0, p)
  36. # dfs(i, n-1, a)
  37.  
  38. #for j in range(n):
  39. # dfs(0, j, p)
  40. # dfs(m-1, j, a)
  41.  
  42. #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