Skip to content

Commit a4b2912

Browse files
committed
improve -Implemented the first occurrence algorithm with technique.
1 parent 6273a74 commit a4b2912

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

first_occurrence.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def first_occurrence(array: list[int], target: int) -> int:
2+
pointer = 0
3+
4+
while pointer < len(array):
5+
if array[pointer] == target:
6+
return pointer
7+
pointer += 1
8+
9+
return -1
10+

0 commit comments

Comments
 (0)