2. Is Subsequence
Input: s = "abc", t = "ahbgdc"
Output: trueInput: s = "axc", t = "ahbgdc"
Output: falseSolution: (Greedy)
class Solution
{
public:
bool isSubsequence(string s, string t)
{
int n = t.length();
int m = s.length();
int i = 0, j = 0;
while (i < n)
{
if (s[j] == t[i])
{
j++;
i++;
}
else
{
i++;
}
}
if (j == m)
{
return true;
}
return false;
}
};Last updated