-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLc115.java
More file actions
28 lines (25 loc) · 732 Bytes
/
Lc115.java
File metadata and controls
28 lines (25 loc) · 732 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 leetcode;
import java.util.Arrays;
/**
* @author Kuma
* @date 2021年3月17日
* 115.不同的子序列
*/
public class Lc115 {
public int numDistinct(String s, String t) {
char[] srr = s.toCharArray();
char[] trr = t.toCharArray();
int[][] dp = new int[trr.length + 1][srr.length + 1];
Arrays.fill(dp[0],1);
for (int i = 1; i < dp.length; i++) {
for (int j = 1; j < dp[0].length; j++) {
if (trr[i - 1] == srr[j - 1]){
dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
}else {
dp[i][j] = dp[i][j - 1];
}
}
}
return dp[trr.length][srr.length];
}
}