MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

C++/teemo-attacking.cpp:8–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6//similar to overlapping subintervals problems
7
8class Solution {
9public:
10 int findPoisonedDuration(vector<int>& timeSeries, int duration) {
11
12 int n = timeSeries.size();
13 if(n==0)
14 return 0;
15
16 int ans = duration;
17
18 for(int i=0; i<n-1; i++)
19 {
20 ans += duration;
21 if(timeSeries[i+1] < timeSeries[i] + duration) //overlapping condition
22 {
23 ans -= (timeSeries[i] + duration - timeSeries[i+1]); //the overlapped time subtracted
24 }
25 }
26
27 return ans;
28 }
29};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected