Skip to content

Commit 3b73627

Browse files
authored
Update typing usage (#190)
* Update typing * Fix test bug
1 parent 929dd9f commit 3b73627

112 files changed

Lines changed: 260 additions & 4073 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/settings.local.json‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎algorithm_theory/binary_search.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
the interval is empty.
77
"""
88

9-
from typing import Optional
109

11-
12-
def binary_search_iterative(array: [int], target: int) -> Optional[int]:
10+
def binary_search_iterative(array: list[int], target: int) -> int | None:
1311
"""Narrow the [left, right] bounds by half each iteration until target is found or the bounds cross."""
1412
left = 0
1513
right = len(array) - 1
@@ -26,7 +24,7 @@ def binary_search_iterative(array: [int], target: int) -> Optional[int]:
2624
return None
2725

2826

29-
def binary_search_recursive(array: [int], left: int, right: int, target: int) -> Optional[int]:
27+
def binary_search_recursive(array: list[int], left: int, right: int, target: int) -> int | None:
3028
"""Recurse into the left or right sub-array each call until target is found or the bounds cross."""
3129
if right >= left:
3230
mid = int((left + right) / 2)

‎algorithm_theory/bubble_sort.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def bubble_sort(array: [int]) -> []:
1+
def bubble_sort(array: list[int]) -> list[int]:
22
"""Bubble Sort.
33
44
The simplest sorting algorithm, working by repeatedly swapping the adjacent elements if they are

‎algorithm_theory/jump_search.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import math
2-
from typing import Optional
32

43
from algorithm_theory.linear_search import linear_search
54

65

7-
def jump_search(array: [int], target: int) -> Optional[int]:
6+
def jump_search(array: list[int], target: int) -> int | None:
87
"""Jump Search (https://www.geeksforgeeks.org/jump-search/).
98
109
A searching algorithm for sorted arrays. The basic idea is to check fewer elements (than linear

‎algorithm_theory/linear_search.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from typing import Optional
2-
3-
4-
def linear_search(array: [int], left: int, right: int, target: int) -> Optional[int]:
1+
def linear_search(array: list[int], left: int, right: int, target: int) -> int | None:
52
"""Linear Search.
63
74
The most basic search. Start from the leftmost element of the array and one by one compare the target

0 commit comments

Comments
 (0)