当前位置:网站首页>Simulation volume leetcode [normal] 081. Search rotation sort array II
Simulation volume leetcode [normal] 081. Search rotation sort array II
2022-07-29 06:56:00 【Encounter simulation volume】
Summary : Simulation volume Leetcode Summary of questions
081. Search rotation sort array II
It is known that there is an array of integers in non descending order nums , The values in the array don't have to be different from each other .
Before passing it to a function ,nums In some unknown subscript k(0 <= k < nums.length) On the rotate , Make array [nums[k], nums[k+1], …, nums[n-1], nums[0], nums[1], …, nums[k-1]]( Subscript from 0 Start Count ). for example , [0,1,2,4,4,4,5,6,6,7] In subscript 5 It may turn into [4,5,6,6,7,0,1,2,4,4] .
Here you are. After rotation Array of nums And an integer target , Please write a function to determine whether the given target value exists in the array . If nums There is a target value in target , Then return to true , Otherwise return to false .
You must minimize the whole procedure .
Example 1:
Input :nums = [2,5,6,0,0,1,2], target = 0
Output :true
Example 2:
Input :nums = [2,5,6,0,0,1,2], target = 3
Output :false
Tips :
1 <= nums.length <= 5000
-104 <= nums[i] <= 104
Topic data assurance nums Rotated on a previously unknown subscript
-104 <= target <= 104
Advanced :
This is a Search rotation sort array The extended topic of , In this question nums It may contain repeating elements .
Does this affect the time complexity of the program ? What kind of impact will it have , Why? ?
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Code :
from leetcode_python.utils import *
class Solution:
def search(self, nums: List[int], target: int) -> bool:
return target in nums
def test(data_test):
s = Solution()
data = data_test # normal
# data = [List2Node(data_test[0])] # list turn node
return s.getResult(*data)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun,data in zip(data_test[0][1::],data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[],
]
for data_test in datas:
t0 = time.time()
print('-'*50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
remarks :
GitHub:https://github.com/monijuan/leetcode_python
CSDN Summary : Simulation volume Leetcode Summary of questions
You can add QQ Group communication :1092754609
leetcode_python.utils See the description on the summary page for details
First brush questions , Then generated by script blog, If there is any mistake, please leave a message , I see it will be revised ! thank you !
边栏推荐
- 阿里一面,给了几条SQL,问需要执行几次树搜索操作?
- Analysis of four isolation levels of MySQL things
- 新同事写了几段小代码,把系统给搞崩了,被老板爆怼一顿!
- NeuralCF-神经协同过滤网络
- Navicat for Oracle Cannot create oci environment
- CDM—码分复用(简单易懂)
- 竣达技术 | 适用于”日月元”品牌UPS微信云监控卡
- 【CryoEM】FSC, Fourier Shell Correlation简介
- Biased lock, lightweight lock test tool class level related commands
- 线程 - 线程安全 - 线程优化
猜你喜欢
随机推荐
如何优雅的写 Controller 层代码?
【冷冻电镜】Relion4.0——subtomogram教程
【解决方案】ERROR: lib/bridge_generated.dart:837:9: Error: The parameter ‘ptr‘ of the method ‘FlutterRustB
Share some tips for better code, smooth coding and improve efficiency
vscode通过remotessh结合xdebug远程调试php解决方案
二次元卡通渲染——进阶技巧
实战!聊聊如何解决MySQL深分页问题
DBAsql面试题
没那么简单的单例模式
崔雪婷老师最优化理论与方法课程笔记 00 写在前面
【冷冻电镜|论文阅读】子断层平均 M 软件解读:Multi-particle cryo-EM refinement with M
Dbasql interview questions
Teacher wangshuyao's notes on operations research 04 fundamentals of linear algebra
Let the computer run only one program setting
CVPR2022Oral专题系列(一):低光增强
Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
损失函数——交叉熵损失函数
Pytorch多GPU条件下DDP集群分布训练实现(简述-从无到有)
线程 - 线程安全 - 线程优化
吴恩达老师机器学习课程笔记 04 多元线性回归








