Skip to content

Commit e2f7a3a

Browse files
committed
Runtime: 26 ms (Top 90.8%) | Memory: 26.10 MB (Top 93.66%)
1 parent 82396c1 commit e2f7a3a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
// Runtime: 26 ms (Top 90.8%) | Memory: 26.10 MB (Top 93.66%)
2+
13
class Solution {
24
public:
35
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
4-
int ans=0;
5-
int n=timeSeries.size();
6-
for(int i=0;i<n;i++){
7-
ans+=min(duration,(i==n-1?duration:timeSeries[i+1]-timeSeries[i]));
6+
if (timeSeries.size() == 0)
7+
return 0;
8+
int res = 0;
9+
for(int i=0; i<timeSeries.size()-1; i++) {
10+
if (timeSeries[i+1] - timeSeries[i] < duration)
11+
res += timeSeries[i+1] - timeSeries[i];
12+
else
13+
res += duration;
814
}
9-
return ans;
15+
return res+duration;
1016
}
11-
};
17+
};

0 commit comments

Comments
 (0)