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】485.Max Consecutive Ones_EASY(九)
- leetcode 485. Max Consecutive Ones(easy)
- 【LeetCode】485. Max Consecutive Ones(最大连续数之和)
- Leetcode 485. Max Consecutive Ones
- leetcode485. Max Consecutive Ones
- [LeetCode]485. Max Consecutive Ones(最大连续为1的数量)
- LeetCode 485. Max Consecutive Ones(Java)
- LeetCode 485. Max Consecutive Ones
- leetcode 485. Max Consecutive Ones(C语言)
- 【LeetCode】485.Max Consecutive Ones解题报告
- LeetCode 485. Max Consecutive Ones
- leetcode 485. Max Consecutive Ones
- python--leetcode485. Max Consecutive Ones
- Leetcode 485. Max Consecutive Ones
- leetcode 485. Max Consecutive Ones
- leetcode 485. Max Consecutive Ones
- LeetCode 485. Max Consecutive Ones
- LeetCode -485. Max Consecutive Ones - 思路详解 - C++
- 485. Max Consecutive Ones的C++解法
- leetcode 485. Max Consecutive Ones