We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 26fd993 commit e010122Copy full SHA for e010122
scripts/algorithms/P/Possible Bipartition/Possible Bipartition.py
@@ -1,17 +1,18 @@
1
+# Runtime: 997 ms (Top 62.25%) | Memory: 22.2 MB (Top 22.99%)
2
class Solution:
3
def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:
4
def dfs(i, c):
5
if color[i] != 0:
6
if color[i] != c:
7
return False
8
return True
-
9
+
10
color[i] = c
11
for u in e[i]:
12
if not dfs(u, 3 - c):
13
14
15
16
e = [[] for _ in range(n)]
17
for u, v in dislikes:
18
u -= 1
@@ -23,4 +24,4 @@ def dfs(i, c):
23
24
if color[i] == 0:
25
if not dfs(i, 1):
26
- return True
27
+ return True
0 commit comments