全部 新建

user:thomas 由使用者建立的 Gists

title:mygist Gists 的標題

filename:myfile.txt Gists 的檔案名稱

extension:yml Gists 的副檔名

language:go Gists 的程式語言

topic:homelab gists with given topic

註冊

登錄


全部 新建 註冊 登錄

All gists matching topic interview

倒序排序 創建
順序排序 創建
倒序排序 更新
順序排序 更新

linkjobai / Monotonic Stack: The Pattern Behind "Next Greater Element" Questions

0 喜歡
0 分支
1 檔案
最後活躍 1794541558
Interview prep notes
interview

Monotonic Stack: The Pattern Behind "Next Greater Element" Questions

If a question asks for the next greater, previous smaller, or "how many days until a warmer temperature", a monotonic stack usually turns an O(n²) scan into O(n).

Core idea

Keep a stack of indices whose values are in sorted order (decreasing for "next greater"). When a new value breaks the order, it is the answer for every index you pop.

def daily_temperatures(temps):          # LeetCode 739
上一頁 下一頁

由 Opengist 提供支持 ⋅ Load: 28ms⋅

繁體中文
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文