Easiest Java 1-Liner Logic | Commented | Easy to understand
We need to find the time for which opponent was poisoned.\nTherefore,\n1. If array is empty, return 0\n2. As the timeframes are in ascending order, we find Mini
We need to find the time for which opponent was poisoned.\nTherefore,\n1. If array is empty, return 0\n2. As the timeframes are in ascending order, we find Minimum of duration and timeSeries[i] - timeSeries[i-1]. This is because either he will be poisoned for complete duration, or till he was poisoned again.\n3. At the last timeframe, the opponent will be poisoned for the complete duration. So, add duration at the end.\n\n\n\nclass Solution {\n    \n\tpublic int findPoisonedDuration(int[] timeSeries, int duration) {\n        \n        int pTime = 0;\n        \n\t\t// If array is empty, return 0\n        if(timeSeries.length == 0)\n            return 0;\n        \n        for(int i = 1; i < timeSeries.length; i++) {\n            \n\t\t\t// Find minimum of duration and difference between timeframes.\n            pTime += Math.min(duration, timeSeries[i] - timeSeries[i-1]);\n            \n        }\n        \n\t\t// Add the last complete duration of poisoned\n        pTime += duration;\n        \n        return pTime;\n        \n    }\n}
['Java']