Skip to content

Commit 05ced80

Browse files
add 115
1 parent 8145f92 commit 05ced80

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ LeetCode
8484
|0111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | c | [c++](./src/0111-Minimum-Depth-of-Binary-Tree/0111.cpp) |[python](./src/0111-Minimum-Depth-of-Binary-Tree/0111.py)|||Easy|
8585
|0112|[Path Sum](https://leetcode.com/problems/path-sum/) | c | [c++](./src/0112-Path-Sum/0112.cpp) |[python](./src/0112-Path-Sum/0112.py)|||Easy|
8686
|0113|[Path Sum II](https://leetcode.com/problems/path-sum-ii/) | c | [c++](./src/0113-Path-Sum-II/0113.cpp) |[python](./src/0113-Path-Sum-II/0113.py)|||Medium|
87+
|0115|[Distinct Subsequences](https://leetcode.com/problems/distinct-subsequences/) | c | [c++](./src/0115-Distinct-Subsequences/0115.cpp) |[python](./src/0115-Distinct-Subsequences/0115.py)|||Hard|
8788
|0118|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | c | [c++](./src/0118-Pascal's-Triangle/0118.cpp) |[python](./src/0118-Pascal's-Triangle/0118.py)|||Easy|
8889
|0119|[Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/) | c | [c++](./src/0119-Pascal's-Triangle-II/0119.cpp) |[python](./src/0119-Pascal's-Triangle-II/0119.py)|||Easy|
8990
|0120|[Triangle](https://leetcode.com/problems/triangle/) | c | [c++](./src/0120-Triangle/0120.cpp) |[python](./src/0120-Triangle/0120.py)|||Medium|
@@ -197,4 +198,5 @@ LeetCode
197198
|0935|[Knight Dialer](https://leetcode.com/problems/knight-dialer/) | c | [c++](./src/0935-Knight-Dialer/0935.cpp) |[python](./src/0935-Knight-Dialer/0935.py)|||Medium|
198199
|0936|[Stamping The Sequence](https://leetcode.com/problems/stamping-the-sequence/) | c | [c++](./src/0936-Stamping-The-Sequence/0936.cpp) |[python](./src/0936-Stamping-The-Sequence/0936.py)|||Hard|
199200
|0937|[Reorder Log Files](https://leetcode.com/problems/reorder-log-files/) | c | [c++](./src/0937-Reorder-Log-Files/0937.cpp) |[python](./src/0937-Reorder-Log-Files/0937.py)|||Easy|
200-
|0938|[Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst/) | c | [c++](./src/0938-Range-Sum-of-BST/0938.cpp) |[python](./src/0938-Range-Sum-of-BST/0938.py)|||Medium|
201+
|0938|[Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst/) | c | [c++](./src/0938-Range-Sum-of-BST/0938.cpp) |[python](./src/0938-Range-Sum-of-BST/0938.py)|||Medium|
202+
|0939|[Minimum Area Rectangle](https://leetcode.com/problems/minimum-area-rectangle/) | c | [c++](./src/0939-Minimum-Area-Rectangle/0939.cpp) |[python](./src/0939-Minimum-Area-Rectangle/0939.py)|||Medium|
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
using namespace std;
5+
6+
7+
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
8+
class Solution
9+
{
10+
public:
11+
int numDistinct(string s, string t)
12+
{
13+
vector<int> mem(t.size()+1, 0);
14+
mem[0] = 1;
15+
for (auto s_c : s)
16+
{
17+
for (int i = t.size() - 1; i >= 0; --i)
18+
{
19+
if (t[i] == s_c) mem[i+1] += mem[i];
20+
}
21+
}
22+
return *mem.rbegin();
23+
}
24+
};
25+
int main(int argc, char const *argv[])
26+
{
27+
string s = "rabbbit";
28+
string t = "rabbit";
29+
cout << Solution().numDistinct(s, t);
30+
return 0;
31+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def numDistinct(self, s, t):
3+
"""
4+
:type s: str
5+
:type t: str
6+
:rtype: int
7+
"""
8+
t_len = len(t)
9+
mem = [0]*(t_len+1)
10+
mem[0] = 1
11+
for s_c in s:
12+
for i in range(t_len-1, -1, -1):
13+
if t[i] == s_c:
14+
mem[i+1] += mem[i]
15+
16+
return mem[-1]
17+
18+
if __name__ == "__main__":
19+
s = "rabbbit"
20+
t = "rabbit"
21+
print(Solution().numDistinct(s, t))

0 commit comments

Comments
 (0)