Skip to content

Commit 1fed3d6

Browse files
committed
Time: 56 ms (70.06%), Space: 18.1 MB (54.49%) - LeetHub
1 parent 6f41312 commit 1fed3d6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
4+
class Solution:
5+
def maxOperations(self, s: str) -> int:
6+
count = 0
7+
result = 0
8+
for i, c in enumerate(s):
9+
if c == '1':
10+
count += 1
11+
elif i > 0 and s[i - 1] == '1':
12+
result += count
13+
return result
14+
15+
16+
s = "1001101"
17+
print(Solution().maxOperations(s))
18+
s = "00111"
19+
print(Solution().maxOperations(s))

0 commit comments

Comments
 (0)