Skip to content

Instantly share code, notes, and snippets.

@tuanna-hsp
Created February 16, 2020 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuanna-hsp/7e44f8c3b5a0c74561bfe6d837cec74e to your computer and use it in GitHub Desktop.
Save tuanna-hsp/7e44f8c3b5a0c74561bfe6d837cec74e to your computer and use it in GitHub Desktop.
Is subsequence
class Solution {
public boolean isSubsequence(String s, String t) {
if (s.isEmpty()) {
return true;
}
int lastBreak = 0;
int sIndex = 0;
int tIndex = 0;
int sLength = s.length();
int tLength = t.length();
while (sIndex < sLength) {
char sChar = s.charAt(sIndex);
while (tIndex < tLength) {
if (t.charAt(tIndex) == sChar) {
if (sIndex == sLength - 1) {
return true;
}
tIndex++;
break;
}
tIndex++;
}
sIndex++;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment