We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 82396c1 commit e2f7a3aCopy full SHA for e2f7a3a
scripts/algorithms/T/Teemo Attacking/Teemo Attacking.cpp
@@ -1,11 +1,17 @@
1
+// Runtime: 26 ms (Top 90.8%) | Memory: 26.10 MB (Top 93.66%)
2
+
3
class Solution {
4
public:
5
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
- int ans=0;
- 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]));
+ if (timeSeries.size() == 0)
+ 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;
14
}
- return ans;
15
+ return res+duration;
16
-};
17
+};
0 commit comments