当前位置:网站首页>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) 的情况下解决一些问题。 - 应用:
- 单调递增栈可以找到左起第一个比当前数字小的元素
- 单调递减栈可以找到左起第一个比当前数字大的元素
边栏推荐
- General configuration tooltip
- Guojingxin center "APEC education +" Shanghai Jiaotong University Japan Cooperation Center x Fudan philosophy class "Zhe Yi" 2022 New Year greetings
- How to get the first and last days of a given month
- 2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
- [loss function] entropy / relative entropy / cross entropy
- Multi purpose signal modulation generation system based on environmental optical signal detection and user-defined signal rules
- Recommend a document management tool Zotero | with tutorials and learning paths
- Su embedded training - Day7
- Scalar / vector / matrix derivation method
- Vscode reading Notepad Chinese display garbled code
猜你喜欢
14. Draw network model structure
Understanding of prior probability, posterior probability and Bayesian formula
Markdown learning (entry level)
Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
解决报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Guojingxin center "APEC investment +": some things about the Internet sector today | observation on stabilizing strategic industrial funds
2021 welder (primary) examination skills and welder (primary) operation examination question bank
130. 被圍繞的區域
2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination
随机推荐
130. Zones environnantes
USB type-C docking design | design USB type-C docking scheme | USB type-C docking circuit reference
Gnuradio transmits video and displays it in real time using VLC
Kuntai ch7511b scheme design | ch7511b design EDP to LVDS data | pin to pin replaces ch7511b circuit design
Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"
Chapter VIII integrated learning
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
Redis 主从复制
5. Over fitting, dropout, regularization
Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
130. 被围绕的区域
How to write mark down on vscode
Chapter IV decision tree
Two methods for full screen adaptation of background pictures, background size: cover; Or (background size: 100% 100%;)
General configuration tooltip
Chapter 16 intensive learning
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
Complete model verification (test, demo) routine
Talk about smart Park
Su embedded training - Day9