成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[LintCode] Teemo Attacking

whjin / 3584人閱讀

Problem

In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo"s attacking ascending time series towards Ashe and the poisoning time duration per Teemo"s attacking, you need to output the total time that Ashe is in poisoned condition.

You may assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.

Example

Example 1:
Input: [1,4], 2
Output: 4
Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately.
This poisoned status will last 2 seconds until the end of time point 2.
And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds.
So you finally need to output 4.

Example 2:
Input: [1,2], 2
Output: 3
Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned.
This poisoned status will last 2 seconds until the end of time point 2.
However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status.
Since the poisoned status won"t add up together, though the second poisoning attack will still work at time point 2, it will stop at the end of time point 3.
So you finally need to output 3.

Solution
public class Solution {
    /**
     * @param timeSeries: the Teemo"s attacking ascending time series towards Ashe
     * @param duration: the poisoning time duration per Teemo"s attacking
     * @return: the total time that Ashe is in poisoned condition
     */
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        // Write your code here
        int total = 0;
        for (int i = 0; i < timeSeries.length; i++) {
            if (i == 0) total += duration;
            else {
                int interval = timeSeries[i] - timeSeries[i-1];
                if (interval < duration) total += interval;
                else total += duration;
            }
        }
        return total;
    }
}

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

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/71401.html

相關(guān)文章

  • 【Java】第二章 面向?qū)ο?/b>

    摘要:類和對象設(shè)計英雄這個類有一些共同的狀態(tài),比如名字,,護甲,移動速度等等,這樣我們就可以設(shè)計一種東西,叫做類,代表英雄這樣一種事物類英雄狀態(tài)名字血量,護甲,移動速度這個類沒有主方法,不要試圖運行它。并不是所有的類都是有主方法的。 1 類和對象 (1) 設(shè)計英雄這個類 有一些共同的狀態(tài),比如名字,hp,護甲,移動速度等等,這樣我們就可以設(shè)計一種東西,叫做類,代表英雄這樣一種事物 類:英...

    MyFaith 評論0 收藏0
  • cookie和localStorage那些事

    摘要:它的大小限制為左右,是網(wǎng)景公司的前雇員在年月的發(fā)明。字符串轉(zhuǎn)義通過來設(shè)置的有效期。和的用法和屬性允許在瀏覽器中存儲對的數(shù)據(jù)。用于臨時保存同一窗口或標(biāo)簽頁的數(shù)據(jù),在關(guān)閉窗口或標(biāo)簽頁之后將會刪除這些數(shù)據(jù)。是瀏覽器關(guān)閉后就立即清除。 一、localStorage、cookie、sessionStorage的區(qū)別與練習(xí) showImg(https://segmentfault.com/img/...

    Jeffrrey 評論0 收藏0
  • 劍指offer/LintCode12_最小棧

    摘要:劍指最小棧聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處解題思路實現(xiàn)功能實現(xiàn)一個最小棧,要求操作均為復(fù)雜度,解題思路用棧存儲數(shù)據(jù)用最小棧存儲中最小元素,保證棧頂元素與棧頂元素同步,表示此時最小值將與此時最小值比較,將更小的一方壓棧,保證中棧頂始終 劍指offer/LintCode12_最小棧 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處https://segmentfault.com/u/yz...

    Betta 評論0 收藏0
  • 劍指offer/LintCode40_用兩個棧模擬隊列

    摘要:劍指用兩個棧模擬隊列聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處解題思路實現(xiàn)功能用兩個棧模擬實現(xiàn)一個隊列的,和操作解題思路假設(shè)有兩個棧隊列實現(xiàn)始終用入棧實現(xiàn)隊列和實現(xiàn)由于依次出棧并壓入中,恰好保證中順序與模擬隊列順序一致,始終保證棧頂元素為模擬 劍指offer/LintCode40_用兩個棧模擬隊列 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處https://segmentfault.com...

    bawn 評論0 收藏0
  • 劍指offer/LintCode494_用兩個隊列實現(xiàn)一個棧

    摘要:劍指用兩個隊列實現(xiàn)一個棧聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處解題思路實現(xiàn)功能用兩個隊列實現(xiàn)一個棧,實現(xiàn),,和方法解題思路假設(shè)有隊列和實現(xiàn)棧的操作實現(xiàn)棧操作始終用來入隊實現(xiàn)實現(xiàn)棧的方法模擬棧的過程中,保證兩個隊列中始終有一個隊列為空,另一 劍指offer/LintCode494_用兩個隊列實現(xiàn)一個棧 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請注明出處https://segmentfault....

    rose 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<