785. Is Graph Bipartite?
There is an undirected graph with
n nodes, where each node is numbered between
n - 1. You are given a 2D array
graph[u] is an array of nodes that node
u is adjacent to. More formally, for each
graph[u], there is an undirected edge between node
u and node
v. The graph has the following properties:
- There are no self-edges (
graph[u]does not contain
- There are no parallel edges (
graph[u]does not contain duplicate values).
graph[v](the graph is undirected).
- The graph may not be connected, meaning there may be two nodes
vsuch that there is no path between them.
A graph is bipartite if the nodes can be partitioned into two independent sets
B such that every edge in the graph connects a node in set
A and a node in set
true if and only if it is bipartite.