| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/Monika-R/LeetCode-Solutions/master/Python/binary-search.py | [Back] [Original] |
# Time: O(logn)
# Space: O(1)
class Solution(object):
def search(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
left, right = 0, len(nums)-1
while left target:
right = mid-1
elif nums[mid] < target:
left = mid+1
else:
return mid
return -1
| Web Proxy Viewer | New URL | Original Page |