Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 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. visited[i][j] = True
  10. print "I AM ONLY SETTING THE FOLLOWING COORDINATES TO TRUE", i, j
  11. for row in visited:
  12. print row
  13. for x, y in ((0,1),(1,0),(-1,0),(0,-1)):
  14. x_coord, y_coord = i + x, j + y
  15. if 0<=x_coord<m and 0<=y_coord<n:
  16. if matrix[x_coord][y_coord] >= matrix[i][j]:
  17. dfs(x_coord,y_coord,visited)
  18.  
  19. if not matrix or not matrix[0]:
  20. return [[]]
  21.  
  22. m, n = len(matrix), len(matrix[0])
  23.  
  24. p = [[False] * n] * m
  25. a = [[False] * n] * m
  26.  
  27. #for row in p:
  28. # print row
  29.  
  30. dfs(0,0,p)
  31.  
  32. #for row in p:
  33. # print row
  34.  
  35. #for i in range(m):
  36. # dfs(i, 0, p)
  37. # dfs(i, n-1, a)
  38.  
  39. #for j in range(n):
  40. # dfs(0, j, p)
  41. # dfs(m-1, j, a)
  42.  
  43. #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