Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Isn't it 'Easy'?

class Solution {
public:
    int findPoisonedDuration(vector<int>& ts, int d) 
    {
        int ret = 0, s = 0, e = 0;
        for(auto t : ts)
        {
            if(t > e) 
            {
                ret += e - s;
                s = t;
            }
            
            e = t + d;
        }
        ret += e - s;
        
        return ret;
    }
};

 

posted on 2017-02-01 01:31  Tonix  阅读(155)  评论(0编辑  收藏  举报