package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev

# README

739. Daily Temperatures

Solution idea

Stack

  • 套用单调栈模版 - 从后往前看,挤掉栈顶矮个子!
  • 这里,Stack 内存入元素的index, 而不是元素本身!!!
    • 原因: 题目要求算距离 ==> 算距离用index ==> 保存元素index

Time complexity = $O(n)$

Similar question: 503. Next Greater Element II

Resource

单调栈结构解决三道算法题