is-subsequence 1.0.0
Is Subsequence
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <bits/stdc++.h>
2
3using namespace std;
4
6{
7public:
8 bool isSubsequence(string s, string t)
9 {
10 if ((int)s.size() == 0)
11 return true;
12
13 int index = 0;
14 for (char c: t)
15 {
16 if (c == s[index])
17 {
18 index++;
19 if (index == (int)s.size())
20 return true;
21 }
22 }
23 return false;
24 }
25};
26
27int main()
28{
29 cout << "is s a subsequence of t: " << Solution().isSubsequence("abc", "ahbgdc") << endl;
30 return 0;
31}
bool isSubsequence(string s, string t)
Definition main.cpp:8
int main()
Definition main.cpp:27