原題
跟進“搜索旋轉(zhuǎn)排序數(shù)組”指孤,假如有重復(fù)元素又將如何?
給出[3,4,4,5,7,0,1,2]和target=4贬堵,返回 true
解題思路
- 本題有重復(fù)元素恃轩,不能使用binary search
- 極端例子,[1, 1, 1, 1, 1, 1, 2, 1, 1, 1]中找2的情況
完整代碼
class Solution(object):
def search(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: bool
"""
for num in nums:
if num == target:
return True
return False