Is Graph Bipartite? LeetCode solution in Python
1class Solution:2def isBipartite(self, graph: List[List[int]]) -> bool:3v = len(graph)4color = [-1] * v5color[0] = 167def helper(src, q):8q.append(src)910while q:11node = q.pop(0)1213for j in graph[node]:14if color[j] == -1:15color[j] = 1 - color[node]16q.append(j)17elif color[node] == color[j]:18return False19return True2021for i in range(v):22if not helper(i, []):23return False24return True