为什么80%的码农都做不了架构师?>>>   

Description

Tag:Stack, Hash Table
Difficulty: Medium

Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.

For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].

Note: The length of temperatures will be in the range [1, 30000]. Each temperature will be an integer in the range [30, 100].

Solution

从后向前,将大值压入栈中,在压栈过程中,将小值pop出去,然后依次查找即可。

type ele struct {index inttemperature int
}
var stack []ele
var top = -1
func dailyTemperatures(T []int) []int {size := len(T)stack = make([]ele, size)result := make([]int, size)for i:= size -1; i>=0;i-- {result[i] = find(T[i], i)push(T[i], i)}return result
}func find(t int, index int) int {for i:=top; i>=0; i-- {if stack[i].temperature > t {return stack[i].index - index}}return 0
}func push(t int, i int) {for top >=0 && stack[top].temperature <= t {top--}top++element := ele{i, t}stack[top] = element
}

转载于:https://my.oschina.net/liufq/blog/2961411

739. Daily Temperatures相关推荐

  1. 739. Daily Temperatures - LeetCode

    Question 739. Daily Temperatures Solution 题目大意:比今天温度还要高还需要几天 思路:笨方法实现,每次遍历未来几天,比今天温度高,就坐标减 Java实现: p ...

  2. LeetCode #739 - Daily Temperatures

    题目描述: Given a list of daily temperatures T, return a list such that, for each day in the input, tell ...

  3. 69.Daily Temperatures(日常气温)

    Level:   Medium 题目描述: Given a list of daily temperatures T, return a list such that, for each day in ...

  4. LeetCode739. Daily Temperatures

    题目: Given a list of daily temperatures, produce a list that, for each day in the input, tells you ho ...

  5. 单调队列 Monotonic Queue / 单调栈 Monotonic Stack

    2018-11-16 22:45:48 一.单调队列 Monotone Queue 239. Sliding Window Maximum 问题描述: 问题求解: 本题是一个经典的可以使用双端队列或者 ...

  6. leetcode刷题规划

    LeetCode精华题目列表[刷题规划系列] – TuringPlanet 目录 算法题到底在考察什么? 题目列表 Array String Linked List Queue Stack Advan ...

  7. LeetCode刷题之python解法(持续更新)

    1. Two Sum 4行 class Solution:def twoSum(self, nums: List[int], target: int) -> List[int]:d = {}fo ...

  8. Leetcode算法题-解法转载

    版权声明:本文为博主原创文章,未经博主允许不得转载.    https://blog.csdn.net/fuxuemingzhu/article/details/85112591 作者: 负雪明烛 i ...

  9. Leetcode题解(超赞!!!)

    我是技术搬运工,好东西当然要和大家分享啦.原文地址 算法思想 二分查找 二分查找思想简单,但是在实现时有一些需要注意的细节: 在计算 mid 时不能使用 mid = (l + h) / 2 这种方式, ...

最新文章

  1. 028_jdbc-mysql大文本
  2. pytorch保存模型时报错***object has no attribute 'state_dict'
  3. html 正则表达式验证金额,js金额校验,js正则表达式,包含正负,小数点后两位...
  4. 2020年日历电子版(打印版)_灵感 | 快来康康——2020年的日历设计的这么有创意?...
  5. 【SQL】SELECT 语句
  6. python小说爬虫练习
  7. 【ZigBee】JN5169 ZigBee3.0设备入网过程
  8. [ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
  9. 她力量系列四丨读博6年两次换导师,靠一点点“倔”,俞舟成为social chatbot的开拓者之一
  10. 供应链金融你了解多少?
  11. #vue#element-ui文件上传(格式校验)
  12. the mid-autumn festival
  13. 打印机在不同操作系统的打印区别
  14. 微营销培训,微营销师职业培训
  15. 你有Gmail邮箱吗?
  16. T46:字符串转换成整数(Java)
  17. ZooKeeper——Curator客户端基本使用(笔记)
  18. VC 资源文件 Resource.h *.rc *.rc2
  19. java怎么跑游戏_RunGame java赛跑小游戏源代码和素材,适合新手入门练手。 Develop 272万源代码下载- www.pudn.com...
  20. 【JavaScript 逆向】521 加速乐多层响应 Cookie 逆向

热门文章

  1. IBM Watson 的中国生意
  2. 因融资失败,应用崩溃,3 名程序员被“祭天”!
  3. 如果不当程序员,你会在做什么? | 每日趣闻
  4. Mozilla 财报:2017年收入增长超过 4000 万美元
  5. JVM指令分析实例四(数组、switch)
  6. Python之路----迭代器与生成器
  7. Linux安装python3.6
  8. idea debug使用
  9. 细说Java主流日志工具库
  10. Devexpress 10.2.3 Demo 批量生成脚本