Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
20 lines (15 loc) · 679 Bytes

File metadata and controls

20 lines (15 loc) · 679 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package leetcode.dp;
public class leetcode115 {
public int numDistinct(String s, String t) {
int [][] dp=new int[t.length()+1][s.length()+1];
for (int j = 0; j < s.length() + 1; j++) dp[0][j] = 1;
for (int i = 1; i <t.length() + 1 ; i++) {
for (int j = 1; j <s.length() + 1 ; j++) {
if (t.charAt(i-1)==s.charAt(j-1)){ //匹配时,用此匹配或者不用此匹配 两种情况均可以
dp[i][j]=dp[i-1][j-1]+dp[i][j-1]; //不匹配时,回退到 s 的前j-1 表示 t 的前i位
}else dp[i][j]=dp[i][j-1];
}
}
return dp[t.length()][s.length()];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.