We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cc9bc5e commit a6e05efCopy full SHA for a6e05ef
Python/number-of-ways-to-split-a-string.py
@@ -0,0 +1,26 @@
1
+# Time: O(n)
2
+# Space: O(1)
3
+
4
+class Solution(object):
5
+ def numWays(self, s):
6
+ """
7
+ :type s: str
8
+ :rtype: int
9
10
+ MOD = 10**9+7
11
12
+ ones = s.count('1')
13
+ if ones % 3:
14
+ return 0
15
+ ones //= 3
16
+ if ones == 0:
17
+ return (len(s)-1)*(len(s)-2)//2 % MOD
18
+ count = left = right = 0
19
+ for c in s:
20
+ if c == '1':
21
+ count += 1
22
+ if count == ones:
23
+ left += 1
24
+ elif count == 2*ones:
25
+ right += 1
26
+ return left*right % MOD
0 commit comments