forked from algorithm009-class01/algorithm009-class01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumDistinct.java
More file actions
28 lines (26 loc) · 857 Bytes
/
NumDistinct.java
File metadata and controls
28 lines (26 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package str;
public class NumDistinct {
public int numDistinct(String s,String t){
int[][] meme = new int[t.length()+1][s.length()+1];
for (int j = 0; j <= s.length() ; j++) {
meme[0][j] = 1;
}
for (int i = 0; i < t.length(); i++) {
for (int j = 0; j < s.length(); j++) {
if (t.charAt(i) == s.charAt(j)){
meme[i+1][j+1] = meme[i][j] + meme[i+1][j];
}else {
meme[i+1][j+1] = meme[i+1][j];
}
}
}
return meme[t.length()][s.length()];
}
public static void main(String[] args) {
String s = "rabbbit";
String t = "rabbit";
NumDistinct numDistinct = new NumDistinct();
int r = numDistinct.numDistinct(s,t);
System.out.println(r);
}
}