leetcode 485. Max Consecutive Ones(easy)
2017-04-18 15:25
519 查看
Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
Note:
The input array will only contain
The length of input array is a positive integer and will not exceed 10,000
题目是要找最大连续1的个数
Example 1:
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.
Note:
The input array will only contain
0and
1.
The length of input array is a positive integer and will not exceed 10,000
题目是要找最大连续1的个数
class Solution { public: int findMaxConsecutiveOnes(vector<int>& nums) { int maxValue = 0; int len = nums.size(); if(len <= 0) return 0; for(int i=0;i<len;i++) { int temp = 0; if(nums[i] == 1) { while(i<len&& nums[i] == 1) { ++temp; ++i; } if(temp>maxValue) maxValue = temp; } } return maxValue; } };
相关文章推荐
- 【LeetCode】485.Max Consecutive Ones_EASY(九)
- 495. Teemo Attacking【middle】&& 485. Max Consecutive Ones【easy】 02-24
- leetcode 485. Max Consecutive Ones(C语言)
- LeetCode 485. Max Consecutive Ones
- leetcode 485. Max Consecutive Ones
- leetcode485. Max Consecutive Ones
- LeetCode 485. Max Consecutive Ones
- Leetcode 485. Max Consecutive Ones
- LeetCode 485. Max Consecutive Ones(Java)
- 【LeetCode】485. Max Consecutive Ones(最大连续数之和)
- [LeetCode]485. Max Consecutive Ones(最大连续为1的数量)
- leetcode485. Max Consecutive Ones
- 【LeetCode】485.Max Consecutive Ones解题报告
- LeetCode -485. Max Consecutive Ones - 思路详解 - C++
- LeetCode 485:Max Consecutive Ones(连续1的最大个数,边界条件)
- [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