Java easy O(n) solution with intuition
Intuition\n Describe your first thoughts on how to solve this problem. \n- Calculate total duration of attacks from teemo\n- If next attack occurs before curren
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Calculate total duration of attacks from teemo\n- If next attack occurs before current duration ends, include the difference\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 {\n    public int findPoisonedDuration(int[] timeSeries, int duration) {\n        int total = 0;\n        for (int i = 0; i < timeSeries.length-1; i++) {\n            // if next attack occurs before current duration ends, include the difference\n            if (timeSeries[i+1] <= timeSeries[i] + duration-1) {\n                total += timeSeries[i+1] - timeSeries[i];\n            } else { // add duration normally\n                total += duration;\n            }\n        }\n        total += duration; // include last attack from teemo\n        return total;\n    }\n}
['Java']