Skip to content

Commit 5a34b65

Browse files
committed
add lenear search algorithm
1 parent 26f1f7e commit 5a34b65

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arrays/linear_search.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
linear_search([1, 2, 5, 8, 11, 14, 18, 23, 32, 48], 11) => 4
3+
"""
4+
5+
from typing import Any
6+
7+
8+
def linear_search(array: list, target: Any) -> int:
9+
for index, element in enumerate(array):
10+
if element == target:
11+
return index
12+
return None
13+
14+
15+
if __name__ == "__main__":
16+
print(linear_search([1, 2, 5, 8, 11, 14, 18, 23, 32, 48], 11) == 4)

0 commit comments

Comments
 (0)