Skip to content

Commit a7dbc44

Browse files
authored
Create number-of-substrings-with-all-zeroes.py
1 parent 6d9ebd6 commit a7dbc44

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
"""
3+
@param str: the string
4+
@return: the number of substrings
5+
"""
6+
def stringCount(self, str):
7+
# Write your code here.
8+
r = 0
9+
zeros = 0
10+
prev = 'x'
11+
for c in str:
12+
if (prev == '0') and (c != '0'):
13+
zeros = 0
14+
elif c == '0':
15+
if prev != '0':
16+
zeros = 1
17+
else:
18+
zeros += 1
19+
r += zeros
20+
prev = c
21+
return r
22+
23+
# medium: https://www.lintcode.com/problem/1870

0 commit comments

Comments
 (0)