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

Method search

Array/SearchInRotatedSortedArray.py:94–115  ·  view source on GitHub ↗

:type nums: List[int] :type target: int :rtype: int

(self, nums, target)

Source from the content-addressed store, hash-verified

92
93
94 def search(self, nums, target):
95 """
96 :type nums: List[int]
97 :type target: int
98 :rtype: int
99 """
100 if not nums:
101 return -1
102
103 rotate_index = self.find_rotate(nums)
104
105 lo = 0
106 hi = rotate_index
107 # print(hi)
108 one = self.bi_search(nums, target, lo, hi)
109 if one != -1:
110 return one
111
112 two = self.bi_search(nums, target, hi, len(nums))
113 if two != -1:
114 return two
115 return -1

Callers

nothing calls this directly

Calls 2

find_rotateMethod · 0.95
bi_searchMethod · 0.95

Tested by

no test coverage detected