Skip to content

Commit 70df944

Browse files
committed
2020-08-13
1 parent 0f41ca8 commit 70df944

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution(object):
2+
def numSub(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
cons_length = 0
8+
res = 0
9+
MOD = 10 ** 9 + 7
10+
for ch in s:
11+
if ch == '1':
12+
cons_length += 1
13+
else:
14+
res = (res + (1 + cons_length) * cons_length // 2) % MOD
15+
cons_length = 0
16+
return (res + (1 + cons_length) * cons_length // 2) % MOD

0 commit comments

Comments
 (0)