Skip to content

Commit 9739cc2

Browse files
committed
committed from zkp
1 parent 941997e commit 9739cc2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

LeetCode/search.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def search(self, nums, target):
3+
"""
4+
:type nums: List[int]
5+
:type target: int
6+
:rtype: int
7+
"""
8+
left = 0
9+
right = len(nums) - 1
10+
while left <= right:
11+
mid = (left + right) // 2
12+
if nums[mid] == target:
13+
return mid
14+
elif nums[mid] > target:
15+
right -= 1
16+
else:
17+
left += 1
18+
return -1
19+
if __name__ == '__main__':
20+
a = Solution()
21+
print(a.search([-1,0,3,5,9,12],3))

0 commit comments

Comments
 (0)