From c6060983ec801ce4e2adf5c302635230c87a2ddf Mon Sep 17 00:00:00 2001 From: lucifer Date: Mon, 26 Apr 2021 14:52:03 +0800 Subject: [PATCH] =?UTF-8?q?Update=20leetcode485=E6=9C=80=E5=A4=A7=E8=BF=9E?= =?UTF-8?q?=E7=BB=AD1=E7=9A=84=E4=B8=AA=E6=95=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../数组篇/leetcode485最大连续1的个数.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/animation-simulation/数组篇/leetcode485最大连续1的个数.md b/animation-simulation/数组篇/leetcode485最大连续1的个数.md index 1212710..6157b54 100644 --- a/animation-simulation/数组篇/leetcode485最大连续1的个数.md +++ b/animation-simulation/数组篇/leetcode485最大连续1的个数.md @@ -66,6 +66,8 @@ class Solution { 好啦,下面我们直接看代码吧。 +Java Code: + ```java class Solution { public int findMaxConsecutiveOnes(int[] nums) { @@ -88,3 +90,20 @@ class Solution { } ``` +Python3 Code: + + +```py +class Solution: + def findMaxConsecutiveOnes(self, nums: List[int]) -> int: + ans = i = t = 0 + for j in range(len(nums)): + if nums[j] == 1: + t += 1 + ans = max(ans, t) + else: + i = j + 1 + t = 0 + return ans +``` +