1999. Longer Contiguous Segments of Ones than Zeros
My accepted Python solution to LeetCode problem 1999, Longer Contiguous Segments of Ones than Zeros, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 17.1MB, accepted 2025-12-30.
class Solution:
def checkZeroOnes(self, s: str) -> bool:
max_ones = max_zeros = 0
current_ones = current_zeros = 0
for c in s:
if c == '1':
current_ones += 1
current_zeros = 0
else:
current_zeros += 1
current_ones = 0
max_ones = max(max_ones, current_ones)
max_zeros = max(max_zeros, current_zeros)
return max_ones > max_zeros