题目:
题解:
- bool isSubsequence(char* s, char* t) {
- int n = strlen(s), m = strlen(t);
- int f[m + 1][26];
- memset(f, 0, sizeof(f));
- for (int i = 0; i < 26; i++) {
- f[m][i] = m;
- }
- for (int i = m - 1; i >= 0; i--) {
- for (int j = 0; j < 26; j++) {
- if (t[i] == j + 'a')
- f[i][j] = i;
- else
- f[i][j] = f[i + 1][j];
- }
- }
- int add = 0;
- for (int i = 0; i < n; i++) {
- if (f[add][s[i] - 'a'] == m) {
- return false;
- }
- add = f[add][s[i] - 'a'] + 1;
- }
- return true;
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |