Problem
Given a list of daily temperatures, produce a list 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 temperatures = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].
ExampleInput:
temperatures = [73, 74, 75, 71, 69, 72, 76, 73]
Output:
[1, 1, 4, 2, 1, 1, 0, 0]
public class Solution { /** * @param temperatures: a list of daily temperatures * @return: a list of how many days you would have to wait until a warmer temperature */ public int[] dailyTemperatures(int[] input) { // for input[i], return the number of days in the future // that have a higher temperature int record[] = new int[input.length]; for (int i = 0; i < record.length; i++) { for (int j = i+1; j < record.length; j++) { if (input[j] > input[i]) { record[i] = j-i; break; } } } return record; } }
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/71519.html
摘要:提示氣溫列表長度的范圍是。第二次遍歷棧頂對應(yīng)索引的溫度索引出棧此時(shí)棧為空,。索引入棧,第三次遍歷棧頂對應(yīng)索引的溫度滿足要求當(dāng)前索引入棧。每個氣溫的值的均為華氏度,都是在范圍內(nèi)的整數(shù)。 題目: 根據(jù)每日 氣溫 列表,請重新生成一個列表,對應(yīng)位置的輸入是你需要再等待多久溫度才會升高超過該日的天數(shù)。如果之后都不會升高,請?jiān)谠撐恢糜?0 來代替。 例如,給定一個列表 temperatures ...
Problem 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 f...
摘要:劍指最小棧聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處解題思路實(shí)現(xiàn)功能實(shí)現(xiàn)一個最小棧,要求操作均為復(fù)雜度,解題思路用棧存儲數(shù)據(jù)用最小棧存儲中最小元素,保證棧頂元素與棧頂元素同步,表示此時(shí)最小值將與此時(shí)最小值比較,將更小的一方壓棧,保證中棧頂始終 劍指offer/LintCode12_最小棧 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處https://segmentfault.com/u/yz...
摘要:劍指用兩個棧模擬隊(duì)列聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處解題思路實(shí)現(xiàn)功能用兩個棧模擬實(shí)現(xiàn)一個隊(duì)列的,和操作解題思路假設(shè)有兩個棧隊(duì)列實(shí)現(xiàn)始終用入棧實(shí)現(xiàn)隊(duì)列和實(shí)現(xiàn)由于依次出棧并壓入中,恰好保證中順序與模擬隊(duì)列順序一致,始終保證棧頂元素為模擬 劍指offer/LintCode40_用兩個棧模擬隊(duì)列 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處https://segmentfault.com...
摘要:劍指用兩個隊(duì)列實(shí)現(xiàn)一個棧聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處解題思路實(shí)現(xiàn)功能用兩個隊(duì)列實(shí)現(xiàn)一個棧,實(shí)現(xiàn),,和方法解題思路假設(shè)有隊(duì)列和實(shí)現(xiàn)棧的操作實(shí)現(xiàn)棧操作始終用來入隊(duì)實(shí)現(xiàn)實(shí)現(xiàn)棧的方法模擬棧的過程中,保證兩個隊(duì)列中始終有一個隊(duì)列為空,另一 劍指offer/LintCode494_用兩個隊(duì)列實(shí)現(xiàn)一個棧 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處https://segmentfault....
閱讀 2205·2021-11-25 09:43
閱讀 1172·2021-11-23 09:51
閱讀 3506·2021-11-23 09:51
閱讀 3633·2021-11-22 09:34
閱讀 1567·2021-10-09 09:43
閱讀 2129·2019-08-30 15:53
閱讀 3169·2019-08-30 14:07
閱讀 577·2019-08-28 18:14