当前位置:网站首页>Looking for peak [Abstract dichotomy exercise]
Looking for peak [Abstract dichotomy exercise]
2022-07-23 14:32:00 【REN_ Linsen】
Abstract dichotomy exercise
Preface
It's not an examination of dead knowledge points , This kind of problem is very difficult , It's also interesting to push it out slowly . This kind of problem has abstract dichotomy / Greedy algorithm brain teaser .
One 、 Looking for peaks

Two 、 Abstract dichotomy
public int findPeakElement(int[] nums) {
// There must be a peak , It indicates that there is no continuous increase , This sum logN What's the connection ?
int low = 0,high = nums.length - 1;
while(low < high){
int mid = low + (high - low >>> 1);
int midVal = nums[mid];
// There must be a peak on the right .
if(midVal < nums[high]) low = mid + 1;
// There must be a peak on the left .
else if(midVal < nums[low])high = mid - 1;
// nums[low] <= midVal >= nums[high]
/* Give Way high--, If high It's the peak , Then there must be comparison nums[high - 1] < nums[high], and nums[low] <= midVal, be nums[high - 1] There must be a peak before . */
else --high;
}
return low;
}
summary
1) It's difficult for this / A clever question , Need to understand the description of the topic , Dig inside conditions , Find and have learned the relationship between data structures and algorithms . If you don't settle down to analyze with known conditions , There will be no idea , If not, just look at the solution , Explain that there is less exercise , I can't think of it for months , A waste of time !
2) There is no fixed formula , Give more examples on the draft paper , Simulation simulation , Find rules and feelings , Then use the data structure to express it , Last review Slowly precipitate a little routine .
3) The most important thing is to do more such topics , Take a look at these excellent solutions , Broaden the following vision , Analysis is more fluent , To draw inferences slowly .
reference
边栏推荐
- js软件卸载提示表情跟随鼠标变化js特效
- websocket通用化封装设计与实现
- Antd form - reset method does not work - Basic accumulation - importance of prop
- 初识并查集
- ValidationError: Invalid options object. Dev Server has been initialized using an options object th
- Tensor, numpy, PIL format conversion and image display
- 第2章 基础查询与排序
- antd form表单——重置方法不生效——基础积累——prop的重要性
- Chapitre 2 requête de base et tri
- 10 years of software testing engineer experience, very confused
猜你喜欢

Surrounded Regions

js软件卸载提示表情跟随鼠标变化js特效
![webstrom ERROR in [eslint] ESLint is not a constructor](/img/e9/b084512d6aa8c4116d7068fdc8fc05.png)
webstrom ERROR in [eslint] ESLint is not a constructor

JS software unloading prompt expression changes with the mouse JS special effect

494. 目标和
![[download attached] several scripts commonly used in penetration testing that are worth collecting](/img/01/3b74c5ab4168059827230578753be5.png)
[download attached] several scripts commonly used in penetration testing that are worth collecting

利用js自动解析执行xss

回文相关题目

338. 比特位计数

10 years of software testing engineer experience, very confused
随机推荐
Description of test platform and hardware design
Reinforcement learning -- understanding point of strategy gradient
Chapitre 2 requête de base et tri
手工测试如何转向自动化测试?字节5年自动化经验浅谈一下...
C语言实现课堂随机点名系统
云呐|怎样管理固定资产?如何进行固定资产管理?
[download attached] several scripts commonly used in penetration testing that are worth collecting
将我理解的web3.0讲给你听
Chapter 2 basic query and sorting
回文相关题目
10 years of software testing engineer experience, very confused
Renforcement de l'apprentissage - points de compréhension du gradient stratégique
Summary of different circulation modes and precautions in JS
js日历样式饼图统计插件
webstrom ERROR in [eslint] ESLint is not a constructor
CPU,内存,磁盘速度比较
Aruba learning notes 05 configuration architecture WLAN configuration architecture
Pycharm读取Excel文件时报错:raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+ ; not supported )
动态规划-- 背包问题
强化學習——策略梯度理解點