当前位置:网站首页>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) 的情况下解决一些问题。 - 应用:
- 单调递增栈可以找到左起第一个比当前数字小的元素
- 单调递减栈可以找到左起第一个比当前数字大的元素
边栏推荐
- Su embedded training - C language programming practice (implementation of address book)
- Chapter improvement of clock -- multi-purpose signal modulation generation system based on ambient optical signal detection and custom signal rules
- 2021-04-12 - new features lambda expression and function functional interface programming
- Redis master-slave replication
- 2、TD+Learning
- The combination of relay and led small night light realizes the control of small night light cycle on and off
- For the first time in China, three Tsinghua Yaoban undergraduates won the stoc best student thesis award
- The solution of frame dropping problem in gnuradio OFDM operation
- Application of state mode in JSF source code
- Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
猜你喜欢

Content of one frame

Four digit nixie tube display multi digit timing

Ag9310 design USB type C to hdmi+u2+5v slow charging scheme design | ag9310 expansion dock scheme circuit | type-C dongle design data

How to transfer Netease cloud music /qq music to Apple Music

Chapter 16 intensive learning

General configuration toolbox

Application of state mode in JSF source code

Parade ps8625 | replace ps8625 | EDP to LVDS screen adapter or screen drive board

The examination contents of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge) in 2021 and the free examination questions of the third batch of Guangdong Prov

Macro definition and multiple parameters
随机推荐
Chapter IV decision tree
Macro definition and multiple parameters
On the concept and application of filtering in radar signal processing
2、TD+Learning
Two methods for full screen adaptation of background pictures, background size: cover; Or (background size: 100% 100%;)
Guojingxin center "APEC investment +": some things about the Internet sector today | observation on stabilizing strategic industrial funds
Cs5261type-c to HDMI alternative ag9310 | ag9310 alternative
Definition and classification of energy
Application of state mode in JSF source code
2021-04-12 - new features lambda expression and function functional interface programming
14. Draw network model structure
Authorization code of Axure rp9
2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination
Codeforces Round #804 (Div. 2)
Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
Kuntai ch7511b scheme design | ch7511b design EDP to LVDS data | pin to pin replaces ch7511b circuit design
Four digit nixie tube display multi digit timing
Understanding of sidelobe cancellation
USB type-C docking design | design USB type-C docking scheme | USB type-C docking circuit reference
Markdown learning (entry level)