Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class Solution:
  2. def __init__(self):
  3. self.res_outcome = True
  4.  
  5. def dfs(self, visited, graph, i, color):
  6. visited[i] = color
  7. for each in graph[i]:
  8. if visited[each] == 0:
  9. if not self.dfs(visited, graph, each, 3-color):
  10. return False
  11. if visited[each] == color:
  12. return False
  13. return True
  14.  
  15.  
  16. def isBipartite(self, graph: List[List[int]]) -> bool:
  17. visited = [0]*len(graph)
  18. for i in range(len(graph)):
  19. if visited[i] == 0:
  20. if not self.dfs(visited, graph, i, 1): # == False
  21. return False
  22. return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement