Skip to content

Commit 640d0d5

Browse files
authored
Create longer-contiguous-segments-of-ones-than-zeros.py
1 parent f3e0938 commit 640d0d5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def checkZeroOnes(self, s):
6+
"""
7+
:type s: str
8+
:rtype: bool
9+
"""
10+
max_cnt = [0]*2
11+
cnt = 0
12+
for i in xrange(len(s)+1):
13+
if i == len(s) or (i >= 1 and s[i] != s[i-1]):
14+
max_cnt[int(s[i-1])] = max(max_cnt[int(s[i-1])], cnt)
15+
cnt = 0
16+
cnt += 1
17+
return max_cnt[0] < max_cnt[1]

0 commit comments

Comments
 (0)