Skip to content

Commit dded362

Browse files
add 940
1 parent 7cbea89 commit dded362

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
7+
class Solution
8+
{
9+
public:
10+
int distinctSubseqII(string S)
11+
{
12+
int ends[26] = {}, mod = 1e9 + 7;
13+
auto lambda = [&](int s, int i) { return (s + i) % mod; };
14+
for (auto c : S)
15+
ends[c - 97] = accumulate(begin(ends), end(ends), 1, lambda);
16+
return accumulate(begin(ends), end(ends), 0, lambda);
17+
}
18+
};
19+
20+
int main()
21+
{
22+
vector<vector<int>> points = {{1,1},{1,3},{3,1},{3,3},{4,1},{4,3}};
23+
cout << Solution().minAreaRect(points);
24+
return 0;
25+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def distinctSubseqII(self, S):
3+
"""
4+
:type S: str
5+
:rtype: int
6+
"""
7+
end = [0] * 26
8+
for c in S:
9+
end[ord(c) - 97] = sum(end) + 1
10+
return sum(end) % (10**9 + 7)
11+
12+
if __name__ == "__main__":
13+
S = "aba"
14+
print(Solution().distinctSubseqII(S))

0 commit comments

Comments
 (0)