3 LeetCode 485 3.1 题目 先上英文版的题目,再看中文版。 3.2 解法一:逐个元素判断 fromtypingimportListclassSolution:deffindMaxConsecutiveOnes(self,nums:List[int])->int:##注意这里是“List“,而不是”list“;ifnumsisNoneorlen(nums)==0:## 如果列表 lis 为空return0count=result=0## 计数变量,结果...
[LeetCode] 485. Max Consecutive Ones Given a binary array, find the maximum number of consecutive 1s in this array. 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. ...
i+= 1ones+= 1ans=max(ones, ans)returnans 解法2: 使用计数器,看到1就+1,看到0就reset计数器为0. classSolution(object):deffindMaxConsecutiveOnes(self, nums):""":type nums: List[int] :rtype: int"""ans=0 ones=0forninnums:ifn ==0: ones=0else: ones+= 1ans=max(ones, ans)returnan...
【Code】关关的刷题日记21——Leetcode 485. Max Consecutive Ones 其他 关小刷刷题 21——Leetcode 485. Max Consecutive Ones 题目 Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits ...
485. 最大连续 1 的个数 - 给定一个二进制数组 nums , 计算其中最大连续 1 的个数。 示例 1: 输入:nums = [1,1,0,1,1,1] 输出:3 解释:开头的两位和最后的三位都是连续 1 ,所以最大连续 1 的个数是 3. 示例 2: 输入:nums = [1,0,1,1,0,1] 输出:2 提示
else if(nums[i]!=1) { if(max<ans) max = ans; ans = 0; } } return max>ans ? max : ans; } }; 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 参考 1. Leetcode_485. Max Consecutive Ones; ...
LeetCode-485. Max Consecutive Ones Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s....
[LC] 485. Max Consecutive Ones 2019-12-18 21:59 − Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two dig... xuan_abc 0 128 Max Tree 2019-12-21 15:59 − Description...
View gloriayang07's solution of Max Consecutive Ones III on LeetCode, the world's largest programming community.
My Solutions to Leetcode problems. All solutions support C++ language, some support Java and Python. Multiple solutions will be given by most problems. Enjoy:) 我的Leetcode解答。所有的问题都支持C++语言,一部分问题支持Java语言。近乎所有问题都会提供多个算