Simple C++ code, running in 75ms


  • 0
    S
        class Solution{
        public:
             bool isSubsequence(string s,string t){
                  int idx=0;
                  for(char ch : s){
                      while(idx<t.size()&&s[idx]!=ch)idx++;
                      if(idx==t.size())return false;
                      else idx++;
                  }
                  return true;
            }
        };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.