From 94738fd3b29cf75f10625b19127f34960d9f4b64 Mon Sep 17 00:00:00 2001 From: Azureki Date: Fri, 28 Sep 2018 22:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lc485. Max Consecutive Ones.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lc485. Max Consecutive Ones.py diff --git a/lc485. Max Consecutive Ones.py b/lc485. Max Consecutive Ones.py new file mode 100644 index 0000000..345dae4 --- /dev/null +++ b/lc485. Max Consecutive Ones.py @@ -0,0 +1,21 @@ +class Solution: + def findMaxConsecutiveOnes(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + res = 0 + ress = [] + for x in nums: + if x == 1: + res += 1 + else: + ress.append(res) + res = 0 + ress.append(res) + return max(ress) + + +nums = [1, 1, 0, 1, 1, 1] +s = Solution() +print(s.findMaxConsecutiveOnes(nums))