Skip to content

Commit e010122

Browse files
committed
Runtime: 997 ms (Top 62.25%) | Memory: 22.2 MB (Top 22.99%)
1 parent 26fd993 commit e010122

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/algorithms/P/Possible Bipartition/Possible Bipartition.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
# Runtime: 997 ms (Top 62.25%) | Memory: 22.2 MB (Top 22.99%)
12
class Solution:
23
def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:
34
def dfs(i, c):
45
if color[i] != 0:
56
if color[i] != c:
67
return False
78
return True
8-
9+
910
color[i] = c
1011
for u in e[i]:
1112
if not dfs(u, 3 - c):
1213
return False
1314
return True
14-
15+
1516
e = [[] for _ in range(n)]
1617
for u, v in dislikes:
1718
u -= 1
@@ -23,4 +24,4 @@ def dfs(i, c):
2324
if color[i] == 0:
2425
if not dfs(i, 1):
2526
return False
26-
return True
27+
return True

0 commit comments

Comments
 (0)