diff --git a/Easy/is_Subsequence_TWO_POINTERS/Solution.cpp b/Easy/is_Subsequence_TWO_POINTERS/Solution.cpp new file mode 100644 index 0000000..bbc6539 --- /dev/null +++ b/Easy/is_Subsequence_TWO_POINTERS/Solution.cpp @@ -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()); + + } +}; \ No newline at end of file