国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LeetCode] 739. Daily Temperatures

dailybird / 665人閱讀

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 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
class Solution {
    public int[] dailyTemperatures(int[] T) {
        //use stack to save prev indexes
        int n = T.length;
        int[] res = new int[n];
        Deque stack = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            while (!stack.isEmpty() && T[stack.peek()] < T[i]) {
                int preIndex = stack.pop();
                res[preIndex] = i-preIndex;
            }
            stack.push(i);
        }
        return res;
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/72535.html

相關(guān)文章

  • LeetCode 739:每日溫度 Daily Temperatures

    摘要:提示氣溫列表長(zhǎng)度的范圍是。第二次遍歷棧頂對(duì)應(yīng)索引的溫度索引出棧此時(shí)棧為空,。索引入棧,第三次遍歷棧頂對(duì)應(yīng)索引的溫度滿足要求當(dāng)前索引入棧。每個(gè)氣溫的值的均為華氏度,都是在范圍內(nèi)的整數(shù)。 題目: 根據(jù)每日 氣溫 列表,請(qǐng)重新生成一個(gè)列表,對(duì)應(yīng)位置的輸入是你需要再等待多久溫度才會(huì)升高超過(guò)該日的天數(shù)。如果之后都不會(huì)升高,請(qǐng)?jiān)谠撐恢糜?0 來(lái)代替。 例如,給定一個(gè)列表 temperatures ...

    zhkai 評(píng)論0 收藏0
  • [LintCode] Daily Temperatures

    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 whi...

    lemon 評(píng)論0 收藏0
  • 前端每日實(shí)戰(zhàn):98# 視頻演示如何用純 CSS 創(chuàng)作一只憤怒小鳥中的綠豬

    摘要:效果預(yù)覽按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁(yè)面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽??山换ヒ曨l此視頻是可以交互的,你可以隨時(shí)暫停視頻,編輯視頻中的代碼。 showImg(https://segmentfault.com/img/bVbeUYJ?w=400&h=300); 效果預(yù)覽 按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁(yè)面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。 https://codepen.io/comehop...

    FingerLiu 評(píng)論0 收藏0
  • 前端每日實(shí)戰(zhàn):98# 視頻演示如何用純 CSS 創(chuàng)作一只憤怒小鳥中的綠豬

    摘要:效果預(yù)覽按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁(yè)面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽??山换ヒ曨l此視頻是可以交互的,你可以隨時(shí)暫停視頻,編輯視頻中的代碼。 showImg(https://segmentfault.com/img/bVbeUYJ?w=400&h=300); 效果預(yù)覽 按下右側(cè)的點(diǎn)擊預(yù)覽按鈕可以在當(dāng)前頁(yè)面預(yù)覽,點(diǎn)擊鏈接可以全屏預(yù)覽。 https://codepen.io/comehop...

    RyanQ 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<