[Python] [Algorithm] 단순탐색
2021. 6. 24. 14:00ㆍ🧑🏻💻/Python
arr에 찾고자 하는 숫자가 있으면 index 리턴.
없으면 -1 리턴
O(n)
arr = [1,2,3,5,6,7,8,9,10,11]
def simpleSearch(arr, targetNum):
for index in range(0, len(arr)):
if arr[index] == targetNum:
return index
return -1
print(simpleSearch(arr, 8))
print(simpleSearch(arr, 4))
'🧑🏻💻 > Python' 카테고리의 다른 글
[Python] Dictionary sorted (0) | 2021.06.24 |
---|---|
[Python] list sort / sorted (0) | 2021.06.24 |
[Python] [Algorithm] 이진탐색 (0) | 2021.06.24 |
[Python] [Algorithm] 리스트에서 가장 큰 수 / 가장 작은 수 찾기 (0) | 2021.06.24 |
[Python] [Algorithm] 가장 많이 등장하는 알파벳 갯수 세기 (0) | 2021.06.24 |