mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-07 18:30:20 +00:00
sol
This commit is contained in:
1 parent
f0643a0f10
commit
5d2c2664cc
1 file changed
+23
@@ -0,0 +1,23 @@
|
|||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user