Skip to content

Commit 574f279

Browse files
committed
improve cpp
1 parent 0407054 commit 574f279

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

May-LeetCoding-Challenge/27-Possible-Bipartition/Possible-Bipartition.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ class Solution {
44
vector<vector<int>> G;
55

66
bool bipartite(int u) {
7-
for (int i = 0; i < G[u].size(); i++) {
8-
int v = G[u][i];
9-
if (color[v] == color[u]) return false;
10-
if (!color[v]) {
11-
color[v] = 3 - color[u];
12-
if (!bipartite(v)) return false;
13-
}
14-
}
15-
return true;
16-
}
7+
for (int i = 0; i < G[u].size(); i++) {
8+
int v = G[u][i];
9+
if (color[v] == color[u]) return false;
10+
if (!color[v]) {
11+
color[v] = 3 - color[u];
12+
if (!bipartite(v)) return false;
13+
}
14+
}
15+
return true;
16+
}
1717

1818
bool possibleBipartition(int N, vector<vector<int>>& dislikes) {
1919
color.resize(N+1);

0 commit comments

Comments
 (0)