Skip to content

Commit b19dc14

Browse files
authored
java语言版本
1 parent 9cbb439 commit b19dc14

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

problems/0392.判断子序列.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,29 @@ public:
140140
## 其他语言版本
141141
142142
143-
Java:
144-
143+
Java:
144+
```
145+
class Solution {
146+
public boolean isSubsequence(String s, String t) {
147+
int length1 = s.length(); int length2 = t.length();
148+
int[][] dp = new int[length1+1][length2+1];
149+
for(int i = 1; i <= length1; i++){
150+
for(int j = 1; j <= length2; j++){
151+
if(s.charAt(i-1) == t.charAt(j-1)){
152+
dp[i][j] = dp[i-1][j-1] + 1;
153+
}else{
154+
dp[i][j] = dp[i][j-1];
155+
}
156+
}
157+
}
158+
if(dp[length1][length2] == length1){
159+
return true;
160+
}else{
161+
return false;
162+
}
163+
}
164+
}
165+
```
145166
146167
Python:
147168
```python

0 commit comments

Comments
 (0)