Leetcode 495 提莫攻击 线性扫描
JAVA:
public final int findPoisonedDuration(int[] timeSeries, int duration) { if (timeSeries.length == 0 || duration == 0) { return 0; } int cur = 1; int re = duration; while (cur < timeSeries.length) { int time = timeSeries[cur] - timeSeries[cur - 1] + 1; if (time > duration) { re += duration; } else { re += time - 1; } cur++; } return re; }
JS:
var findPoisonedDuration = function (timeSeries, duration) { if (timeSeries.length == 0 || duration == 0) { return 0; } let cur = 1; let re = duration; while (cur < timeSeries.length) { let time = timeSeries[cur] - timeSeries[cur - 1] + 1; if (timeSeries > duration) { re += duration; } else { re += time - 1; } cur++; } return re; };
当你看清人们的真相,于是你知道了,你可以忍受孤独