当前位置:网站首页>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
边栏推荐
- 如何在IDEA中自定義模板、快速生成完整的代碼?
- Twitter launches the test of anti abuse tool "safe mode" and adds enabling prompt
- Simple pages
- A Si's mood swings
- Ml: introduction to confidence interval (the difference and relationship between precision / accuracy / accuracy), use method, and detailed introduction to case application
- DL:深度学习模型优化之模型训练技巧总结之适时自动调整学习率实现代码
- Analysis of IM instant messaging development technology on modern web
- Yunna | fixed assets system management, NC system management where are the fixed assets
- 赛芯电子冲刺科创板上市:拟募资6.23亿元,共有64项专利申请信息
- 利用tsne将不同句子关于相似度可视化出来
猜你喜欢

numpy的索引和图片的索引一样吗?

How to switch to root in xshell

测试用例设计方法之等价类划分方法

UDP servers and clients in go

Programmers with a monthly salary of less than 30K must recite the interview stereotype. I will eat it first!

传统微服务框架如何无缝过渡到服务网格 ASM

81. 搜索旋转排序数组 II

【深度学习编译】算子编译 IR 转换

Analysis of natural frequency and buckling load of cylinder by finite element method

Top performance version 2 reading notes (IV) -- memory monitoring
随机推荐
[deep learning compilation] operator compilation IR conversion
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
【Spark】scala基础操作(持续更新)
Ml: introduction to confidence interval (the difference and relationship between precision / accuracy / accuracy), use method, and detailed introduction to case application
英伟达Jetson Nano的初步了解
VIM编辑器常用指令
The first unlucky person watching eth 2.0
Video to image -cv2 Videocapture() usage
[three.js] Web3D first experience
Comparison between strings localecompare
2022年最新最详细IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
In 2022, the latest and most detailed idea associated database method and visual operation of database in idea (including graphic process)
田口实验法
Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend
Seata 与三大平台携手编程之夏,百万奖金等你来拿
Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper
Sfdp 超级表单开发平台 V6.0.4 正式发布
DL:深度学习模型优化之模型训练技巧总结之适时自动调整学习率实现代码
UDP servers and clients in go
Crmeb SMS for program configuration of knowledge payment system