Skip to content

Commit 23f9915

Browse files
authored
Create 2486. Append Characters to String to Make Subsequence (#493)
2 parents db44b4c + f237298 commit 23f9915

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int appendCharacters(string s, string t) {
4+
int i = 0, j = 0;
5+
int len_s = s.size(), len_t = t.size();
6+
7+
// Traverse both strings
8+
while (i < len_s && j < len_t) {
9+
if (s[i] == t[j]) {
10+
j++;
11+
}
12+
i++;
13+
}
14+
15+
// The characters that need to be appended
16+
return len_t - j;
17+
}
18+
};

0 commit comments

Comments
 (0)