Leetcode打卡——day1

485.最大连续 1 的个数

class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
        int maxCount = 0, count = 0;
        int n = nums.length;
        for(int i = 0; i < n; i++) {
            if(nums[i] == 1) {
                count++;
            } else {
                maxCount = Math.max(maxCount, count);
                count = 0;
            }
        }
        maxCount = Math.max(maxCount, count);
        return maxCount;
    }
}

495. 提莫攻击

class Solution {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        int endtime = timeSeries[0];
        int total = 0;
        for(int i = 0; i < n; i++) {
            if(timeSeries[i] < endtime) {
                total += duration - (endtime - timeSeries[i]);
            } else {
                total += duration;
            }
            endtime = timeSeries[i] + duration;
        }
        return total;
    }
}
posted @ 2021-08-30 22:15  来一块小饼干  阅读(17)  评论(0编辑  收藏  举报