Skip to content

Commit 71e3783

Browse files
committed
2020-07-27
1 parent 2a11d53 commit 71e3783

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

.DS_Store

0 Bytes
Binary file not shown.

0392.判断子序列/0392-判断子序列.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ def isSubsequence(self, s, t):
1010
if s[i] == t[j]:
1111
i += 1
1212
j += 1
13-
return i == len(s)
13+
# test
14+
return i == len(s)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution(object):
2+
def countOdds(self, low, high):
3+
"""
4+
:type low: int
5+
:type high: int
6+
:rtype: int
7+
"""
8+
if low % 2 + high % 2 == 0:
9+
return (high - low) // 2
10+
return 1 + (high - low) // 2
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution(object):
2+
def numOfSubarrays(self, arr):
3+
"""
4+
:type arr: List[int]
5+
:rtype: int
6+
"""
7+
prefix_sum = [0 for _ in arr]
8+
prefix_sum[0] = arr[0]
9+
10+
for i in range(1, len(arr)):
11+
prefix_sum[i] = prefix_sum[i - 1] + arr[i]
12+
13+
MOD = 10 ** 9 + 7
14+
even, odd = 1, 0
15+
res = 0
16+
for i in range(len(arr)):
17+
if prefix_sum[i] % 2 == 0:
18+
res += odd
19+
even += 1
20+
else:
21+
res += even
22+
odd += 1
23+
res = res % MOD
24+
return res
25+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution(object):
2+
def numSplits(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
from collections import defaultdict
8+
import copy
9+
rs = defaultdict(set)
10+
11+
for i in range(len(s) - 1, -1, -1):
12+
if i == len(s) - 1:
13+
rs[i] = set(s[i])
14+
else:
15+
rs[i] = copy.deepcopy(rs[i + 1])
16+
rs[i].add(s[i])
17+
18+
ls = set(s[0])
19+
res = 0
20+
for i in range(len(s) - 1):
21+
ls.add(s[i])
22+
if len(ls) == len(rs[i + 1]):
23+
res += 1
24+
25+
return res

0 commit comments

Comments
 (0)