495. Teemo Attacking

Description:

https://leetcode.com/problems/teemo-attacking/description/

Code:

 

Time & Space:
O(n) & O(1)

One thought on “495. Teemo Attacking”

  1. A shorter version:

    class Solution {
    public:
    int findPoisonedDuration(vector& timeSeries, int duration) {
    int ans = 0, awake = 0;
    for (auto x : timeSeries) {
    ans += (x > awake) ? duration : x + duration – awake;
    awake = x + duration;
    }
    return ans;
    }
    };

Leave a Reply

Your email address will not be published. Required fields are marked *