leetcode Max Consecutive Ones 最大连续长度
2017-09-28 19:48
417 查看
Given a binary array, find the maximum number of consecutive 1s in this array.
Note:
1、The input array will only contain 0 and 1.
2、The length of input array is a positive integer and will not exceed 10,000
题意:数字1的最大连续长度
思路:遍历
Note:
1、The input array will only contain 0 and 1.
2、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 max = 0; int temp = 0; for (int i = 0; i < nums.size(); ++i) { if (nums[i] == 1) { temp++; if (temp > max) max = temp; } else temp = 0; } return max; } };
相关文章推荐
- LeetCode 485 Max Consecutive Ones 最大连续1的个数
- Leetcode 485. Max Consecutive Ones 最大连续1 解题报告
- [LeetCode] Max Consecutive Ones II 最大连续1的个数之二
- [LeetCode] Max Consecutive Ones 最大连续1的个数
- [LeetCode] Max Consecutive Ones 最大的“1”连续个数
- [LeetCode]485. Max Consecutive Ones(最大连续为1的数量)
- Leetcode:485. Max Consecutive Ones 找二进制串连续1最多是多少
- LeetCode 485:Max Consecutive Ones(连续1的最大个数,边界条件)
- 【LeetCode】485. Max Consecutive Ones(最大连续数之和)
- LeetCode 485. Max Consecutive Ones (最长连续1)
- 485.Max Consecutive Ones 最大连续1的个数
- LeetCode 485. Max Consecutive Ones
- leetcode[Max Consecutive Ones]//待整理多种解法
- LeetCode 485. Max Consecutive Ones
- LeetCode 485. Max Consecutive Ones
- LeetCode 485 Max Consecutive Ones
- 485. Max Consecutive Ones leetcode array
- Leetcode: Max Consecutive Ones II(unsolved locked problem)
- LeetCode Max Consecutive Ones
- LeetCode 485. Max Consecutive Ones