leetcode-495. 提莫攻击
题目
495. 提莫攻击
解法
返回中毒秒数
class Solution {
/**
* @param Integer[] $timeSeries
* @param Integer $duration
* @return Integer
*/
function findPoisonedDuration($timeSeries, $duration) {
if (empty($timeSeries) || empty($duration)) {
return 0;
}
$len = count($timeSeries);
$ret = 0;
foreach ($timeSeries as $key => $point) {
if (!isset($timeSeries[$key+1])) {
$ret += $duration;
continue;
}
if ($point + $duration - 1 >= $timeSeries[$key+1]) {
$ret += $timeSeries[$key+1] - $point;
} else {
$ret += $duration;
}
}
return $ret;
}
}
写完之后,默默打开了 lolm