Skip to content

Commit 0f72ecc

Browse files
authored
Update longest-path-with-different-adjacent-characters.py
1 parent f840cb1 commit 0f72ecc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Python/longest-path-with-different-adjacent-characters.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ def longestPath(self, parent, s):
1212
:type s: str
1313
:rtype: int
1414
"""
15-
def topological_sort(adj, q):
16-
top2 = collections.defaultdict(lambda:[0]*2)
15+
def topological_sort(s, adj, in_degree):
1716
result = 1
17+
top2 = collections.defaultdict(lambda:[0]*2)
18+
q = [(i, 1) for i, d in enumerate(in_degree) if not d]
1819
while q:
1920
new_q = []
2021
for (u, l) in q:
@@ -38,7 +39,7 @@ def topological_sort(adj, q):
3839
for i in xrange(1, len(parent)):
3940
adj[i].append(parent[i])
4041
in_degree[parent[i]] += 1
41-
return topological_sort(adj, [(i, 1) for i, d in enumerate(in_degree) if not d])
42+
return topological_sort(s, adj, in_degree)
4243

4344

4445
# Time: O(n)

0 commit comments

Comments
 (0)