当前位置:网站首页>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 - Day7
- 2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
- About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware
- How to write mark down on vscode
- Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
- 1. Linear regression
- Redis master-slave replication
- C# ?,?.,?? .....
- Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products
- Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
猜你喜欢

Four digit nixie tube display multi digit timing

Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"

Definition and classification of energy

Smart grid overview

About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware

3. MNIST dataset classification

2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination

Know how to get the traffic password

130. Surrounding area

7. Regularization application
随机推荐
For the first time in China, three Tsinghua Yaoban undergraduates won the stoc best student thesis award
swift获取url参数
Apt get error
2、TD+Learning
Understanding of sidelobe cancellation
2022 low voltage electrician examination content and low voltage electrician simulation examination question bank
Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
2021-04-12 - new features lambda expression and function functional interface programming
Several frequently used OCR document scanning tools | no watermark | avoid IQ tax
Complete model training routine
130. Surrounding area
A little experience from reading "civilization, modernization, value investment and China"
2021-03-06 - play with the application of reflection in the framework
5、離散控制與連續控制
[loss function] entropy / relative entropy / cross entropy
3. MNIST dataset classification
Introduction to the types and repair methods of chip Eco
Chapter 7 Bayesian classifier
Chapter VIII integrated learning
Basic implementation of pie chart