6 lines of Java O(n) using Math.min
\npublic class Solution {\n    /*\n    if time.length == 0: return 0\n    for i = 1...n\n        diff = time[i] - time[i-1]\n        result += diff > duration ?
```\npublic class Solution {\n    /*\n    if time.length == 0: return 0\n    for i = 1...n\n        diff = time[i] - time[i-1]\n        result += diff > duration ? duration : diff\n    result += duration\n    */\n    public int findPoisonedDuration(int[] timeSeries, int duration) {\n        if (timeSeries.length == 0) return 0;\n        int result = 0;\n        for (int i = 1; i < timeSeries.length; i += 1) \n            result += Math.min(timeSeries[i] - timeSeries[i-1], duration);\n        result += duration;\n        return result;\n```\n    }\n}
[]