495 Teemo Attacking Javascript solution with detailed explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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```\n/**\n * @param {number[]} timeSeries\n * @param {number} duration\n * @return {number}\n */\n /**\n if timeSeries[i]\u2212timeSeries[i\u22121]>duration, it means the previous poison\n effect ends, the poisoned time for the previous attack is duration;\n if not, which means the poison effect not ends, still poisoned, \n the posisoned time for the previous attack is:\n timeSeries[i]\u2212timeSeries[i\u22121];\n  \n We need to go through the array from index =1, \nbecause we need to check if the previous poison effect ends or not.\n Tips: We don\'t add the last poison effect duration, so we need to add it\nafter the for loop.\n\n  */\nvar findPoisonedDuration = function(timeSeries, duration) {\n    let poison = 0;\n    if(!duration||!timeSeries.length) return 0;\n    for(let i=1;i<timeSeries.length;i++) {\n        if(timeSeries[i]-timeSeries[i-1]>duration) {\n            poison+=duration;\n        }\n        else {\n            let exist=timeSeries[i]-timeSeries[i-1];\n            poison+=exist;\n        }        \n    }\n     poison+=duration;\n    return poison;\n};\n```
['JavaScript']