Skip to content

Commit 8bb8fe7

Browse files
committed
Fix ruff lint issues and add package init file
1 parent 2427e79 commit 8bb8fe7

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

data_structures/sort/topological_sort.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
"""
1111

1212
from collections import deque
13-
from typing import List
1413

1514

1615
def _dfs(
1716
node: int,
18-
graph: List[List[int]],
19-
visited: List[int],
20-
result: List[int],
17+
graph: list[list[int]],
18+
visited: list[int],
19+
result: list[int],
2120
) -> None:
2221
"""
2322
Helper DFS function for topological sorting.
@@ -41,7 +40,7 @@ def _dfs(
4140
result.append(node)
4241

4342

44-
def topological_sort_dfs(vertices: int, edges: List[List[int]]) -> List[int]:
43+
def topological_sort_dfs(vertices: int, edges: list[list[int]]) -> list[int]:
4544
"""
4645
Perform topological sort using DFS.
4746
@@ -51,12 +50,12 @@ def topological_sort_dfs(vertices: int, edges: List[List[int]]) -> List[int]:
5150
>>> len(order) == 6
5251
True
5352
"""
54-
graph: List[List[int]] = [[] for _ in range(vertices)]
53+
graph: list[list[int]] = [[] for _ in range(vertices)]
5554
for u, v in edges:
5655
graph[u].append(v)
5756

5857
visited = [0] * vertices
59-
result: List[int] = []
58+
result: list[int] = []
6059

6160
for vertex in range(vertices):
6261
if visited[vertex] == 0:
@@ -65,7 +64,7 @@ def topological_sort_dfs(vertices: int, edges: List[List[int]]) -> List[int]:
6564
return result[::-1]
6665

6766

68-
def topological_sort_kahn(vertices: int, edges: List[List[int]]) -> List[int]:
67+
def topological_sort_kahn(vertices: int, edges: list[list[int]]) -> list[int]:
6968
"""
7069
Perform topological sort using Kahn's Algorithm.
7170
@@ -75,15 +74,15 @@ def topological_sort_kahn(vertices: int, edges: List[List[int]]) -> List[int]:
7574
>>> len(order) == 6
7675
True
7776
"""
78-
graph: List[List[int]] = [[] for _ in range(vertices)]
77+
graph: list[list[int]] = [[] for _ in range(vertices)]
7978
in_degree = [0] * vertices
8079

8180
for u, v in edges:
8281
graph[u].append(v)
8382
in_degree[v] += 1
8483

8584
queue = deque(i for i in range(vertices) if in_degree[i] == 0)
86-
topo_order: List[int] = []
85+
topo_order: list[int] = []
8786

8887
while queue:
8988
node = queue.popleft()

0 commit comments

Comments
 (0)