Skip to content

Commit 3045ac8

Browse files
committed
Time: 3 ms (66.85%), Space: 17.2 MB (7.53%) - LeetHub
1 parent 364309e commit 3045ac8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
bool canMakeSubsequence(string str1, string str2) {
4+
int n = str1.size(), m = str2.size();
5+
if (m > n) return false;
6+
for (int j = 0, i = 0; j < m; j++) {
7+
bool ok = false;
8+
while (i < n) {
9+
char a = str1[i];
10+
char b = ((str1[i] - 'a' + 1) % 26) + 'a';
11+
if (str2[j] == a || str2[j] == b) {
12+
ok = true;
13+
i++;
14+
break;
15+
}
16+
i++;
17+
}
18+
if (!ok && i >= n) return false;
19+
}
20+
return true;
21+
}
22+
};

0 commit comments

Comments
 (0)