当前位置:网站首页>break algorithm---刷题map
break algorithm---刷题map
2022-07-07 23:26:00 【killingwill】
资源参考:
LeetCode
中文版:https://leetcode-cn.com/problemset/all/
英文版:https://leetcode.com/problemset/all/
相关代码实现 – python语言:
https://github.com/muxintong/break-algorithm/
LeetCode题解总结
https://github.com/labuladong/fucking-algorithm
https://labuladong.gitee.io/algo/
https://grandyang.com/leetcode/1147/
Python3文档
https://docs.python.org/3/
数据结构
https://www.runoob.com/data-structures/
Problem Solving with Algorithms and Data Structures using Python
https://runestone.academy/runestone/books/published/pythonds/index.html
一.单调栈 |
1.1 单调栈介绍
单调栈:
- 定义:栈内元素单调递增或者单调递减的栈,单调栈只能在栈顶操作。
单调栈 = 单调 + 栈,因此其同时满足两个特性: 单调性、栈的特点。
单调性: 单调栈里面所存放的数据是有序的(单调递增或递减)。
栈: 后进先出。 - 实现:单调栈里的元素具有单调性,元素加入栈前,会在栈顶端把破坏栈单调性的元素都删除。
单调递减栈:找到从左起第一个比当前元素大的元素
stack<int> st;
for (遍历这个数组)
{
if (栈空 || 栈顶元素大于等于当前比较元素)
{
入栈;
}
else
{
while (栈不为空 && 栈顶元素小于当前元素)
{
栈顶元素出栈;
更新结果;
}
当前数据入栈;
}
}
上述代码优化合并:
stack<int> st;
for(遍历数组){
while(当前元素 > 栈顶元素 && 栈非空){
弹栈;//catch it!找到了从左起第一个比当前元素大的元素!
更新结果集;
}
当前元素入栈;
}
单调递增栈:找到从左起第一个比当前元素小的元素
stack<int> st;
for(int i=0; i<arr.length; i++){
while(当前元素 < 栈顶元素 && 栈非空){
弹栈;//catch it!找到了从左起第一个比当前元素小的元素!
更新结果集;
}
当前元素入栈;
}
- 时间复杂度:O(n)
线性,每个元素遍历一次。
因其满足单调性和每个数字只会入栈一次,并且出栈后再也不会进栈了,所以可以在时间复杂度 O(n) 的情况下解决一些问题。 - 应用:
- 单调递增栈可以找到左起第一个比当前数字小的元素
- 单调递减栈可以找到左起第一个比当前数字大的元素
边栏推荐
- Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
- Cross modal semantic association alignment retrieval - image text matching
- Redis 主从复制
- Ag7120 and ag7220 explain the driving scheme of HDMI signal extension amplifier | ag7120 and ag7220 design HDMI signal extension amplifier circuit reference
- 2022 high voltage electrician examination skills and high voltage electrician reexamination examination
- How to write mark down on vscode
- Vscode reading Notepad Chinese display garbled code
- 130. Zones environnantes
- Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
- USB type-C mobile phone projection scheme | USB type-C docking station scheme | TV / projector type-C converter scheme | ag9300ag9310ag9320
猜你喜欢
Basic realization of line graph
Understanding of expectation, variance, covariance and correlation coefficient
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
General configuration toolbox
2021 welder (primary) examination skills and welder (primary) operation examination question bank
Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
130. Zones environnantes
2022 safety officer-c certificate examination paper and safety officer-c certificate simulated examination question bank
High quality USB sound card / audio chip sss1700 | sss1700 design 96 kHz 24 bit sampling rate USB headset microphone scheme | sss1700 Chinese design scheme explanation
Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
随机推荐
2021 welder (primary) examination skills and welder (primary) operation examination question bank
Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
Y59. Chapter III kubernetes from entry to proficiency - continuous integration and deployment (III, II)
A speed Limited large file transmission tool for every major network disk
Several frequently used OCR document scanning tools | no watermark | avoid IQ tax
Codeforces Round #804 (Div. 2)
Smart agricultural technology framework
Basic implementation of pie chart
General configuration toolbox
Codeforces Round #804 (Div. 2)
C# ?,?.,?? .....
Frrouting BGP protocol learning
Recommend a document management tool mendely Reference Manager
2022 low voltage electrician examination content and low voltage electrician simulation examination question bank
Overall introduction of the project
Gnuradio3.9.4 create OOT module instances
Basic realization of line chart (II)
2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination
2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
Smart grid overview