Re: [閒聊] 每日leetcode
原本想開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)
-----
Sent from JPTT on my iPad
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728536377.A.FA8.html
討論串 (同標題文章)
完整討論串 (本文為第 969 之 1554 篇):