Skip to content

Commit 849579b

Browse files
solves max consecutive ones
1 parent 168c906 commit 849579b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) |
129129
| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) |
130130
| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/license_key_formatting.py) |
131-
| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) |
131+
| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/max_consecutive_ones.py) |
132132
| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) |
133133
| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) |
134134
| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) |

Diff for: python/max_consecutive_ones.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
6+
max_ones, current = 0, 0
7+
for number in nums:
8+
if number == 1:
9+
current += 1
10+
else:
11+
max_ones = max(max_ones, current)
12+
current = 0
13+
max_ones = max(max_ones, current)
14+
return max_ones

0 commit comments

Comments
 (0)