您的位置:首页 > 其它

leetcode485. Max Consecutive Ones

2017-09-11 11:17 453 查看
Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s.
The maximum number of consecutive 1s is 3.
public int findMaxConsecutiveOnes(int[] nums) {
int max_ones = 0;
for (int i = 0; i < nums.length; i++) {
int cur_max = 0;
while (i < nums.length && nums[i] == 1) {
cur_max++;
i++;
}
max_ones = Math.max(cur_max, max_ones);
}
return max_ones;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode