Created
January 10, 2017 00:07
-
-
Save liondancer/3240bbdbd31487a1bdb0f7f7b89d6a49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def searchRange(nums, target): | |
""" | |
:type nums: List[int] | |
:type target: int | |
:rtype: List[int] | |
""" | |
if nums: | |
return search(nums, 0, len(nums) - 1, target) | |
return [-1,-1] | |
def search(nums, L, R, target): | |
if nums[L] == target and nums[R] == target: | |
return [L, R] | |
if nums[L] <= target and target <= nums[R]: | |
mid = (L + R) // 2 | |
left = search(nums, L, mid, target) | |
right = search(nums, mid + 1, R, target) | |
if left[0] == -1: | |
return right | |
if right[0] == -1: | |
return left | |
return [left[0], right[1]] | |
return [-1,-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment