MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Array/FindMinimumInRotatedSortedArrayII.py:33–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32"""
33class Solution(object):
34 def find_rotate(self, nums):
35 target = nums[0]
36
37 lo = 1
38
39 for i in range(1, len(nums)):
40 if nums[i] == target:
41 lo += 1
42 else:
43 break
44
45 hi = len(nums)
46
47 while lo < hi:
48 mid = (lo + hi) // 2
49 if nums[mid] > target:
50 lo = mid + 1
51 else:
52 hi = mid
53
54 return lo
55
56 def findMin(self, nums):
57 """
58 :type nums: List[int]
59 :rtype: int
60 """
61
62 rotate = self.find_rotate(nums)
63
64 if rotate == len(nums):
65 return nums[0]
66
67 return nums[rotate]
68

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected