Skip to content

Instantly share code, notes, and snippets.

@sourabh2k15
Created December 30, 2017 18:29
Show Gist options
  • Select an option

  • Save sourabh2k15/d8adba9fa17d70e2035cfbaafd39b94e to your computer and use it in GitHub Desktop.

Select an option

Save sourabh2k15/d8adba9fa17d70e2035cfbaafd39b94e to your computer and use it in GitHub Desktop.
Determines is string s2 is a subsequence of string s1
bool isSubsequence(string& s1, string& s2){
int l1 = s1.length(), l2 = s2.length();
for(int i = 0, j = 0; i < l1; i++){
if(s1[i] == s2[j] && ++j == l2) return true;
}
return s2.empty();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment