Is the graph bipartite?
Mediumgraphbfsdfsgraph coloring
graph[i] lists the neighbours of node i (edges go both ways). Return true if the nodes can be split into two teams so that every edge joins nodes from different teams. The graph may be disconnected.
Example 1
Input: graph = [[1,3],[0,2],[1,3],[0,2]] Output: true
Example 2
Input: graph = [[1,2,3],[0,2],[0,1,3],[0,2]] Output: false
Constraints
- 1 ≤ n ≤ 100
- graph[i] has no self-loops or repeats
- If j is in graph[i], i is in graph[j]
Submit checks your solution against 9 tests, including hidden ones.
/**
* @param {int[][]} graph
* @return {bool}
*/
function isBipartite(graph) {
}