Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def __init__(self):
- self.res_outcome = True
- def dfs(self, visited, graph, i, color):
- visited[i] = color
- for each in graph[i]:
- if visited[each] == 0:
- if not self.dfs(visited, graph, each, 3-color):
- return False
- if visited[each] == color:
- return False
- return True
- def isBipartite(self, graph: List[List[int]]) -> bool:
- visited = [0]*len(graph)
- for i in range(len(graph)):
- if visited[i] == 0:
- if not self.dfs(visited, graph, i, 1): # == False
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement