算法冲刺
单调栈 stack
https://leetcode-cn.com/problems/daily-tempratures/
根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高超过该日的天数。如果之后都不会升高,请在该位置用 0 来代替。
例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]。
提示:气温 列表长度的范围是 [1, 30000]。每个气温的值的均为华氏度,都是在 [30, 100] 范围内的整数。
使用单调递减stack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class Solution( object ): def dailyTemperatures( self , T): """ :type T: List[int] :rtype: List[int] """ stack = [] ans = [ 0 ] * len (T) for i,t in enumerate (T): while stack and t > T[stack[ - 1 ]]: ans[stack[ - 1 ]] = i - stack[ - 1 ] stack.pop() stack.append(i) return ans |
形象说明的例子:
拓扑排序
https://leetcode-cn.com/problems/queue-reconstruction-by-height/
时间复杂度O(N^2)
当然使用先排序再插入的思路也可以!!!时间复杂度一样。
/**
* 解题思路:先排序再插入
* 1.排序规则:按照先H高度降序,K个数升序排序
* 2.遍历排序后的数组,根据K插入到K的位置上
*
* 核心思想:高个子先站好位,矮个子插入到K位置上,前面肯定有K个高个子,矮个子再插到前面也满足K的要求
*
* @param people
* @return
*/
public int[][] reconstructQueue(int[][] people) {
// [7,0], [7,1], [6,1], [5,0], [5,2], [4,4]
// 再一个一个插入。
// [7,0]
// [7,0], [7,1]
// [7,0], [6,1], [7,1]
// [5,0], [7,0], [6,1], [7,1]
// [5,0], [7,0], [5,2], [6,1], [7,1]
// [5,0], [7,0], [5,2], [6,1], [4,4], [7,1]
Arrays.sort(people, (o1, o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o2[0] - o1[0]);
LinkedList<int[]> list = new LinkedList<>();
for (int[] i : people) {
list.add(i[1], i);
}
return list.toArray(new int[list.size()][2]);
}
DP类题目
https://leetcode-cn.com/problems/as-far-from-land-as-possible/ 推导公式
双指针题目
https://leetcode-cn.com/problems/subarrays-with-k-different-integers/
https://leetcode-cn.com/problems/game-of-life/
https://leetcode-cn.com/problems/brick-wall/
就一个trick,没啥说的。
https://leetcode-cn.com/problems/task-scheduler/
贪心,数学题目,非常死,不是好题目。
https://leetcode-cn.com/problems/find-the-town-judge/
https://leetcode-cn.com/problems/decrease-elements-to-make-array-zigzag/
https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters/ 属于简单题目 直接统计字母表 chars 中每个字母出现的次数,然后检查词汇表 words 中的每个单词,如果该单词中每个字母出现的次数都小于等于词汇表中对应字母出现的次数,就将该单词长度加入答案中。
https://leetcode-cn.com/problems/subarrays-with-k-different-integers/
题意理解完全无误即可简单解。
二进制中最大的矩形
https://leetcode-cn.com/problems/design-log-storage-system/ ???会员???貌似二分查找上下界
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
2017-12-15 PowerShell让系统可以执行.ps1文件
2017-12-15 ssh tunnel 上网
2017-12-15 OzymanDNS 使用——perl 5.22没有成功。。。
2016-12-15 开源软件架构总结之——Bash(readline做输入交互式,词法语法分析,进程交互)
2016-12-15 python——使用readline库实现tab自动补全
2016-12-15 声明式编程——抽象程度更高,关注是什么(what),而非如何做(how)