[C++] || Simple Solution
Approach\n- Iterate thorugh all the elements of the list except the last\n- Find the timeDiff between the adjacent elements\n- If it is less the duration of the
# Approach\n- Iterate thorugh all the elements of the list except the last\n- Find the timeDiff between the adjacent elements\n- If it is less the duration of the attack, then the attack will not work for it\'s entire duration and it resets at the adjacent time value. So, we only add the duration of this attack which is $timeSeries[i+1] - timeSeries[i]$\n- If the timeDiff is greater than the duration, it means that the attack will work for the entire duration. In this case, we add the given duration\n- After we exit the loop, regardless of previous durations, the last attack will for the entire duration because there are no further attacks\n\n![image.png](https://assets.leetcode.com/users/images/c20c123c-8aba-4a6c-a0fc-8e91d5cebcc6_1685355687.953393.png)\n\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int findPoisonedDuration(vector<int>& timeSeries, int duration)\n    {\n        int time=0;\n\n        for(int i=0; i<timeSeries.size()-1; i++)\n        {\n            int timeDiff = timeSeries[i+1]-timeSeries[i];\n\n            time += (timeDiff < duration) ? (timeDiff) : (duration);\n        }\n\n        time += duration;\n\n        return time;\n    }\n};\n```
['C++']