LeetCode: Is Subsequence (2ms)
public class Solution {
public boolean isSubsequence(String s, String t) {
int pos = 0;
int prevPos = 0;
for(int i = 0; i < s.length(); i++) {
if (t.indexOf(s.charAt(i), pos) == -1 || prevPos > t.indexOf(s.charAt(i), pos)) {
return false;
}
prevPos = t.indexOf(s.charAt(i), pos);
pos = prevPos + 1;
}
return true;
}
}