Re: [闲聊] 每日leetcode

楼主: sixB (6B)   2024-10-10 12:59:32
原本想开treap
后来发现维护只看前一个
binary search就好ㄚ
写了一个nlogn结果TLE
三小啦 >:(
monotonic stack好难
On解太强了吧==
※ 引述《dont (dont)》之铭言:
: 962. Maximum Width Ramp
: ## 思路
: 先建个递减的stack存index
: 再从后面扫回来(j) 检查stack, 遇到<=的就pop并更新max width
: Ex. [9,8,1,0,1,9,4,0,4,1]
: stack = [0,1,2,3] # 9,8,1,0
: max_width = 9 (num:1) - 2 (num:1) = 7
: ## Code
: ```python
: class Solution:
: def maxWidthRamp(self, nums: List[int]) -> int:
: n = len(nums)

Links booklink

Contact Us: admin [ a t ] ucptt.com