[LeetCode][Python3] 33. Search in Rotated Sorted Array
2019. 4. 10. 00:23 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/search-in-rotated-sorted-array/
My Solution :
class Solution:
def search(self, nums, target):
if nums:
left, right = 0, len(nums)-1
while left < right:
mid = (left + right) // 2
if target < nums[mid]:
if nums[mid] <= nums[right] or nums[right] < target:
right = mid - 1
else:
left = mid + 1
elif nums[mid] < target:
if nums[left] <= nums[mid] or target < nums[left]:
left = mid + 1
else:
right = mid - 1
else:
return mid
if nums[left] == target:
return left
return -1
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 79. Word Search (0) | 2019.04.13 |
---|---|
[LeetCode][Python3] 313. Super Ugly Number (0) | 2019.04.13 |
[LeetCode][Python3] 218. The Skyline Problem (0) | 2019.04.11 |
[LeetCode][Python3] 150. Evaluate Reverse Polish Notation (0) | 2019.04.10 |
[LeetCode][Python3] 227. Basic Calculator II (0) | 2019.04.09 |
[LeetCode][Python3] 134. Gas Station (0) | 2019.04.08 |
[LeetCode][Python3] 23. Merge k Sorted Lists (0) | 2019.04.07 |
[LeetCode][Python3] 210. Course Schedule II (0) | 2019.04.05 |
최근에 달린 댓글 최근에 달린 댓글