当前位置:网站首页>81. search rotation sort array II
81. search rotation sort array II
2022-06-30 01:02:00 【Melody2050】
after A spin Find the given value in an ordered array of , And there may be repeat Elements . The difficulty here is that there may be repeating elements , It makes it difficult to judge the position of the rotation point . If there are no repeating elements , Then just compare left, mid, right Three position values , You can determine which half the rotation point is on .
Ideas
1. Try to find the point of rotation
First , To try to find the rotation point in this array , Divide the entire array into left and right sides , And then determine :
- Can you confirm that the rotation point is on the left half ?
- Can you confirm that the rotation point is on the right half ?
- If you can't be sure on the left half / Right half , that l++.
How to determine the rotation point ? Remember a trick : When reverse order occurs at both ends of the interval , Represents that the rotation point is inside the interval .
When nums[left] > nums[mid] when , The point of rotation must be on the left half , Why? ? Because the reverse order appears on the left half , Then there is at least one rotation point on the left side . There is at most one rotation point in the array , So the right side must be sequential .
Empathy , When nums[mid] > nums[right] when , The point of rotation must be on the right half .
Why is it only when there is a reverse order between the endpoint and the midpoint , To determine that the rotation point is sitting in the half zone ? because Only in reverse order , To determine that there is a rotation point in this interval , If
边栏推荐
- Lower expectations
- Comment personnaliser les modèles et générer rapidement le code complet dans l'idée?
- About the case of SQL statements
- Quick Pow: 如何快速求幂
- 阿四的情绪波动
- 清洁、对话、带娃,扫地机摆脱“人工智障”标签
- 如何在IDEA中自定義模板、快速生成完整的代碼?
- [cloud native] kernel security in container scenario
- I / o initial et son fonctionnement de base
- 【Spark】scala基础操作(持续更新)
猜你喜欢

How to seamlessly transition from traditional microservice framework to service grid ASM

In depth analysis of a large number of clos on the server_ The root of wait

How to view the size of all files in a folder?

Initial i/o and its basic operations

Time does not spare

优秀的测试/开发程序员与普通的程序员对比......

The SQL statement concat cannot find the result

Go 中的 UDP 服务器和客户端

字节面试惨遭滑铁卢:一面就被吊打,幸得华为内推,三面拿到offer
![Cantilever beam calculation [matlab code]](/img/f6/9a1338e00777e91f6c340eae9d52ba.jpg)
Cantilever beam calculation [matlab code]
随机推荐
[MySQL basic] general syntax 2
CSV文件格式——方便好用个头最小的数据传递方式
阿四的情绪波动
Text classification using huggingface
阿洛觉得自己迷茫
Interviewer: how to solve the problem of massive requests for data that does not exist in redis, which affects the database?
Unity编辑器随机生成物体,更换场景之后物体丢失问题解决
2022年最新最详细IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
[three.js] Web3D first experience
十大券商有哪些?另外,手机开户安全么?
The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications
The first unlucky person watching eth 2.0
Arlo felt lost
VIM editor common instructions
网易云音乐内测音乐社交 App“MUS”,通过音乐匹配同频朋友
解决choice金融终端Excel/Wps插件修复visual basic异常
Bytek suffered a disastrous defeat in the interview: he was hanged on one side, but fortunately Huawei pushed him in, and he got an offer on three sides
[proteus simulation] 8-bit port detection 8 independent keys
ResizeKit2.NET大小和分辨率独立
Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper