Skip to content

Commit 3070ce0

Browse files
Time: 163 ms (92.29%) | Memory: 29.7 MB (93.66%) - LeetSync
1 parent 29d618a commit 3070ce0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def countStableSubsequences(self, nums: List[int]) -> int:
3+
e1 = 0
4+
e2 = 0
5+
o1 = 0
6+
o2 = 0
7+
8+
mod = 10 ** 9 + 7
9+
10+
for num in nums:
11+
if num % 2 == 0:
12+
e2 += e1
13+
e1 += 1 + o1 + o2
14+
e2 %= mod
15+
e1 %= mod
16+
else:
17+
o2 += o1
18+
o1 += 1 + e1 + e2
19+
o2 %= mod
20+
o1 %= mod
21+
22+
return (e1 + e2 + o1 + o2) % mod

0 commit comments

Comments
 (0)