随笔分类 -  算法 / 单调栈

摘要:84. 柱状图中最大的矩形 1、双指针 class Solution: def largestRectangleArea(self, heights: List[int]) -> int: n = len(heights) # 左右第一个小于 i 的下标 min_l, min_r = [0] * n 阅读全文
posted @ 2023-12-10 14:15 忆象峰飞 阅读(8) 评论(0) 推荐(0) 编辑
摘要:[503.下一个更大元素II] 循环问题用 2*n , i % n 的方式 n = len(nums) ans = [-1] * n stack = [] for i in range(2 * n): while len(stack) > 0 and nums[i % n] > nums[stack 阅读全文
posted @ 2023-12-08 15:33 忆象峰飞 阅读(8) 评论(0) 推荐(0) 编辑
摘要:739. 每日温度 class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: n = len(temperatures) ans = [0] * n # 单调增的栈 stack = [] fo 阅读全文
posted @ 2023-12-07 15:21 忆象峰飞 阅读(10) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示