当前位置:网站首页>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) 的情况下解决一些问题。 - 应用:
- 单调递增栈可以找到左起第一个比当前数字小的元素
- 单调递减栈可以找到左起第一个比当前数字大的元素
边栏推荐
- Chapter 16 intensive learning
- Su embedded training - Day6
- Gnuradio transmits video and displays it in real time using VLC
- Markdown learning (entry level)
- Multi purpose signal modulation generation system based on environmental optical signal detection and user-defined signal rules
- 2022 examination for safety production management personnel of hazardous chemical production units and new version of examination questions for safety production management personnel of hazardous chem
- 2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
- The communication clock (electronic time-frequency or electronic time-frequency auxiliary device) writes something casually
- 4. Strategic Learning
- 130. Surrounding area
猜你喜欢
5、离散控制与连续控制
Arm bare metal
4、策略学习
Redis 主从复制
130. Zones environnantes
Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
Know how to get the traffic password
2021-03-14 - play with generics
Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
5. Over fitting, dropout, regularization
随机推荐
10. CNN applied to handwritten digit recognition
Two methods for full screen adaptation of background pictures, background size: cover; Or (background size: 100% 100%;)
EDP to LVDS conversion design circuit | EDP to LVDS adapter board circuit | capstone/cs5211 chip circuit schematic reference
Kaptcha generates verification code on Web page
USB type-C docking design | design USB type-C docking scheme | USB type-C docking circuit reference
Share a latex online editor | with latex common templates
General configuration toolbox
A little experience from reading "civilization, modernization, value investment and China"
About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware
Arm bare metal
2021 welder (primary) examination skills and welder (primary) operation examination question bank
解决报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination
How to transfer Netease cloud music /qq music to Apple Music
Common configurations in rectangular coordinate system
Ag9311maq design 100W USB type C docking station data | ag9311maq is used for 100W USB type C to HDMI with PD fast charging +u3+sd/cf docking station scheme description
2022 safety officer-c certificate examination summary and safety officer-c certificate reexamination examination
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
General configuration title
Basic implementation of pie chart