当前位置:网站首页>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
边栏推荐
- Ml: introduction to confidence interval (the difference and relationship between precision / accuracy / accuracy), use method, and detailed introduction to case application
- Developers, why does the maturity of container technology herald the arrival of cloud native era?
- 元素使用 align-items center 和 overflow auto 之后,部分内容显示不全
- Some thoughts on life
- Traffic, but no sales? 6 steps to increase website sales
- RubyMine开发工具,重构和意图操作
- Practical application of information security
- 岁月不饶人
- 开发者,为什么说容器技术的成熟预示着云原生时代的到来?
- 手写C语言之函数的嵌套调用和链式访问
猜你喜欢

IDEA中的常用设置

Netease cloud music beta music social app "mus" matches friends of the same frequency through music

Online sql to CSV tool

Too voluminous ~ eight part essay, the strongest king of interview!

Yunna | fixed assets information system management, information-based fixed assets management

Online text digit recognition list summation tool

Common settings in idea

What if you can't write your composition well? Ape counseling: parents should pay attention to these points

Seata 与三大平台携手编程之夏,百万奖金等你来拿

练习副“产品”:自制七彩提示字符串展示工具(for循环、if条件判断)
随机推荐
Crmeb SMS for program configuration of knowledge payment system
[MRCTF2020]Ezpop-1|php序列化
英伟达Jetson Nano的初步了解
Comment personnaliser les modèles et générer rapidement le code complet dans l'idée?
作文总写不好怎么办?猿辅导:家长要注意这几点
赛芯电子冲刺科创板上市:拟募资6.23亿元,共有64项专利申请信息
在线文本数字识别列表求和工具
UDP servers and clients in go
测试用例设计方法之等价类划分方法
numpy的索引和图片的索引一样吗?
SFDP super form development platform v6.0.4 was officially released
shell 规范日期格式
Command line Basics
Traffic, but no sales? 6 steps to increase website sales
The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications
ResizeKit2.NET大小和分辨率独立
Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper
[three.js] Web3D first experience
The first unlucky person watching eth 2.0
Go 中的 UDP 服务器和客户端