当前位置:网站首页>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 !
边栏推荐
- 模拟卷Leetcode【普通】061. 旋转链表
- Salesforce中过滤器Filter使用的相对日期
- Embedding理解+代码
- CNN convolutional neural network
- 【冷冻电镜】RELION4.0之subtomogram对位功能源码分析(自用)
- 2022年SQL经典面试题总结(带解析)
- 好文佳句摘录
- Teacher Wang Shuyao's notes on operations research 09 linear programming and simplex method (Application of simplex table)
- Why does 5g N2 interface control plane use SCTP protocol?
- Understanding of access, hybrid and trunk modes
猜你喜欢

Hongke shares | testing and verifying complex FPGA design (2) -- how to perform global oriented simulation in IP core

【经验】通过跳板机远程连接内网服务器的相关配置

Analysis of four isolation levels of MySQL things

【冷冻电镜|论文阅读】A feature-guided, focused 3D signal permutation method for subtomogram averaging

【冷冻电镜|论文阅读】emClarity:用于高分辨率冷冻电子断层扫描和子断层平均的软件

The core of openresty and cosocket

实战!聊聊如何解决MySQL深分页问题

Hongke shares | how to test and verify complex FPGA designs (1) -- entity or block oriented simulation

Teacher wangshuyao's notes on operations research course 10 linear programming and simplex method (discussion on detection number and degradation)

Idea cannot find a database solution
随机推荐
JMM memory model concept
【冷冻电镜】RELION4.0 pipeline命令总结(自用)
Teacher wangshuyao's notes on operations research 03 KKT theorem
Hongke share | let you have a comprehensive understanding of "can bus error" (III) -- can node status and error counter
Understanding of access, hybrid and trunk modes
Teacher wangshuyao's notes on operations research 06 linear programming and simplex method (geometric significance)
Hongke shares | testing and verifying complex FPGA design (2) -- how to perform global oriented simulation in IP core
Dbasql interview questions
Share some tips for better code, smooth coding and improve efficiency
二次元卡通渲染——进阶技巧
leetcode-592:分数加减运算
Introduction to OSPF theory
Etcd principle
The difference between pairs and ipairs
CNN convolutional neural network
Thinkphp5 frequently asked questions
C语言数据类型
IDEA找不到Database解决方法
【解决方案】ERROR: lib/bridge_generated.dart:837:9: Error: The parameter ‘ptr‘ of the method ‘FlutterRustB
数据库持久化+JDBC数据库连接