Skip to content

Commit a879238

Browse files
115. Distinct Subsequences (java)
1 parent f26e679 commit a879238

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)