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;
}
}
作者:lykxbg —— 来一块小饼干
出处:http://www.cnblogs.com/lykxbg/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。