Skip to content

Commit e6a2f21

Browse files
committed
leetcode
1 parent c09e314 commit e6a2f21

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
bool isSubsequence(string s, string t) {
4+
int n=s.length();
5+
int m=t.length();
6+
int dp[n+1][m+1];
7+
for(int i=0;i<=n;i++){
8+
for(int j=0;j<=m;j++){
9+
if(i==0 || j==0){
10+
dp[i][j]=0;
11+
}
12+
else if(s[i-1]==t[j-1]){
13+
dp[i][j]=dp[i-1][j-1] +1 ;
14+
}
15+
else {
16+
dp[i][j]=max(dp[i-1][j] , dp[i][j-1] );
17+
}
18+
}
19+
}
20+
if(dp[n][m]==s.length()){
21+
return 1;
22+
}
23+
return 0;
24+
}
25+
};

0 commit comments

Comments
 (0)