mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2024-11-24 13:03:41 +00:00
Merge pull request #15 from azl397985856/patch-4
feat(ml): leetcode485最大连续1的个数 添加 Python3 Code
This commit is contained in:
commit
9a7580e39b
@ -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
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user