leetcode-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
本文来自博客园,作者:吴丹阳-V,转载请注明原文链接:https://www.cnblogs.com/wudanyang/p/15758592.html