首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
每日温度
[编程题]每日温度
热度指数:2906
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
根据往后 n 天的天气预报,计算每一天需要等待几天才会出现一次更高的气温,如果往后都没有更高的气温,则用 0 补位。
例如往后三天的气温是 [1,2,3] , 则输出 [1,1,0]
数据范围:
,每天的温度会满足
示例1
输入
[1,2,3]
输出
[1,1,0]
示例2
输入
[2,4,5,9,10,0,9]
输出
[1,1,1,1,0,1,0]
示例3
输入
[3,1,4]
输出
[2,1,0]
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(47)
分享
纠错
提交结果有问题?
17个回答
15篇题解
开通博客
youxiwang
发表于 2022-02-08 16:33:31
单调栈直接套娃 记口诀就行: 找右边的就从右往左,找左边的从左往右 找小的就单调递增,找大的就单调递减 这题是找右边的大的,那就从右往左loop, 建单调递减栈 O(n), O(n) import java.util.*; public class Solution { public in
展开全文
太阳hxy
发表于 2023-08-29 16:00:54
单调栈 class Solution { public: vector<int> temperatures(vector<int>& dailyTemperatures) { //由于要找某个元素右边最近的比这个元素大的位置,所以可以逆向遍历
展开全文
不会做题的小菜鸡
发表于 2022-03-04 21:26:31
题目分析 题目给出我们一个数组,表示每天的温度值 题目要求我们返回一个数组,每个元素表示,对于该天的温度,再经过几天温度比该天温度高,将这个天数的差值作为该元素放到返回数组中。如果不存在更高的温度了,则用0填充 方法一:暴力遍历 实现思路 我们外层循环遍历每一天 内层循环遍历该天之
展开全文
程序员学长
发表于 2021-11-29 13:02:31
每日温度 739. 每日温度 问题描述 请根据每日 气温 列表 temperatures ,计算在每一天需要等几天才会有更高的温度。如果气温在这之后都不会升高,请在该位置用 0 来代替。 示例: 输入:temperatures = [73,74,75,71,69,72,76,73] 输出:[1,1,
展开全文
代码界的小白
发表于 2022-03-10 16:29:03
每日温度 根据往后 n 天的天气预报,计算每一天需要等待几天才会出现一次更高的气温,如果往后都没有更高的气温,则用 0 补位。 例如往后三天的气温是 [1,2,3] , 则输出 [1,1,0] 方法一:暴力求解 具体方法 使用两次循环,第一层循环遍历到i位置时,从该位置的后面一个位置j = i+1开
展开全文
fred-coder
发表于 2021-12-09 22:55:17
单调栈,一次遍历数组,当 stack 为空或者当前元素和栈顶元素不满足条件时入栈,满足条件时,依次出栈 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param temperatures int整型一维数组 # @return int整型一维数组
展开全文
HSHGoodLuck
发表于 2023-01-08 16:14:29
推荐这个视频动画详解,看后就明白了:https://www.bilibili.com/video/av498397425/ class Solution: def temperatures(self,tem_arr): tem_arr_len = len(tem_arr
展开全文
牛客571923730号
发表于 2024-02-23 10:48:36
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @param dailyTemperaturesLen int dailyTemperatures数组长度
展开全文
在考古的小鱼干很有气魄
发表于 2025-03-23 21:13:03
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures i
展开全文
浪迹天涯笙箫丶
发表于 2022-02-14 21:59:12
又是0.00% 哼(¬︿̫̿¬☆) public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param temperatures int整型一维数组
展开全文
问题信息
数组
栈
单调栈
难度:
17条回答
47收藏
4337浏览
热门推荐
通过挑战的用户
查看代码
牛客55263...
2022-11-14 16:25:02
牛客40225...
2022-09-16 12:08:12
牛客32525...
2022-09-16 10:48:07
Dorae的梦
2022-09-15 22:50:38
牛客43120...
2022-09-15 19:24:41
相关试题
执行以下程序,理论上输出的结果应最...
360集团
Python
算法工程师
2019
评论
(1)
来自
360公司-2019校招...
去耦电容与旁路电容的作用及使用差异点
模拟电路
评论
(1)
什么是竞争与冒险现象?怎样判断?如...
数字电路
评论
(1)
电子系统中常用的模拟电路及其功能
模拟电路
评论
(1)
实现 k-Means 聚类算法
机器学习
评论
(1)
每日温度
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ public int[] temperatures (int[] dailyTemperatures) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型vector * @return int整型vector */ vector
temperatures(vector
& dailyTemperatures) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 每日温度 # @param dailyTemperatures int整型一维数组 # @return int整型一维数组 # class Solution: def temperatures(self , dailyTemperatures ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ public List
temperatures (List
dailyTemperatures) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ function temperatures( dailyTemperatures ) { // write code here } module.exports = { temperatures : temperatures };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 每日温度 # @param dailyTemperatures int整型一维数组 # @return int整型一维数组 # class Solution: def temperatures(self , dailyTemperatures: List[int]) -> List[int]: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ func temperatures( dailyTemperatures []int ) []int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @param dailyTemperaturesLen int dailyTemperatures数组长度 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ int* temperatures(int* dailyTemperatures, int dailyTemperaturesLen, int* returnSize ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 每日温度 # @param dailyTemperatures int整型一维数组 # @return int整型一维数组 # class Solution def temperatures(dailyTemperatures) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ def temperatures(dailyTemperatures: Array[Int]): Array[Int] = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ fun temperatures(dailyTemperatures: IntArray): IntArray { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ public int[] temperatures (int[] dailyTemperatures) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ export function temperatures(dailyTemperatures: number[]): number[] { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ func temperatures ( _ dailyTemperatures: [Int]) -> [Int] { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 每日温度 * @param dailyTemperatures int整型一维数组 * @return int整型一维数组 */ pub fn temperatures(&self, dailyTemperatures: Vec
) -> Vec
{ // write code here } }
[1,2,3]
[1,1,0]
[2,4,5,9,10,0,9]
[1,1,1,1,0,1,0]
[3,1,4]
[2,1,0]