Is Subsequence

 https://leetcode.com/problems/is-subsequence/

class Solution {
public:
    bool isSubsequence(string s, string t) {
       int m=s.size();
       int n=t.size();
        int i=0,j=0;
        while(i<m && j<n){
            if(s[i]==t[j]){
                i++;
            }
            j++;
        }
        return (i==m) ? 1 : 0;
    }
};

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!