8000 Code cleanup. · anubhavcoder/practice-python@6816597 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6816597

Browse files
committed
Code cleanup.
1 parent 247c359 commit 6816597

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

graphs/undirected_graph_matrix.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,24 @@ def bfs(self):
102102
def is_bipartite(self):
103103
"""
104104
Returns true if graph is bipartite
105-
:return:
105+
:rtype: bool
106106
"""
107-
is_bipartite = True
108107
colorings = {}
109108
to_visit = queue.Queue()
110109
to_visit.put(0)
111110
colorings[0] = 0
112111

113-
while not to_visit.empty() and is_bipartite:
112+
while not to_visit.empty():
114113
v = to_visit.get()
115114

116115
for u in self.get_neighbor(v):
117116
if u not in colorings:
118117
colorings[u] = 1 - colorings[v]
119118
to_visit.put(u)
120119
elif colorings[u] == colorings[v]:
121-
is_bipartite = False
122-
break
120+
return False
123121

124-
return is_bipartite
122+
return True
125123

126124

127125
def get_test_graph_1():

0 commit comments

Comments
 (0)
0