We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f26e679 commit a879238Copy full SHA for a879238
solution/0115.Distinct Subsequences/Solution.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int numDistinct(String s, String t) {
3
+ int[][] hash = new int[256][t.length() + 1];
4
+ int[] cnt = new int[t.length() + 1];
5
+ cnt[0] = 1;
6
+ for (int i = 0; i < t.length();) {
7
+ char c = t.charAt(i);
8
+ hash[c][++hash[c][0]] = ++i;
9
+ }
10
+ for(char c : s.toCharArray()) {
11
+ for(int i = hash[c][0]; i > 0; i--) {
12
+ cnt[hash[c][i]] += cnt[hash[c][i] - 1];
13
14
15
+ return cnt[t.length()];
16
17
+}
0 commit comments