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

資訊專欄INFORMATION COLUMN

[LintCode] Teemo Attacking

whjin / 3581人閱讀

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;
    }
}

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/71401.html

相關文章

  • 【Java】第二章 面向對象

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

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

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

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

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

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

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

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

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

    rose 評論0 收藏0

發表評論

0條評論

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