Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/10/10 12:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串969/1554 (看更多)
原本想開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
文章代碼(AID): #1d1ryv-e (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1d1ryv-e (Marginalman)