mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-07 18:30:20 +00:00
23 lines
475 B
C++
23 lines
475 B
C++
class Solution {
|
|
public:
|
|
bool isSubsequence(string s, string t) {
|
|
|
|
int si = 0; // s index
|
|
int ti = 0; // t index
|
|
int matches = 0;
|
|
|
|
while ( ( matches != s.size() ) && (ti != t.size()) ) // does loop until matches = s.size() or t index reaches end of t string
|
|
{
|
|
if (s[si] == t[ti])
|
|
{
|
|
matches++;
|
|
si++;
|
|
}
|
|
ti++;
|
|
}
|
|
|
|
cout << "Matches = " << matches ;
|
|
return (matches == s.size());
|
|
|
|
}
|
|
}; |