1public boolean isSubsequence(String s, String t) {
2 // Initialize pointer for s
3 int i = 0;
4
5 // Traverse through t
6 for (int j = 0; j < t.length(); j++) {
7 // If we found all characters in s
8 if (i == s.length()) {
9 return true;
10 }
11 // If characters match, move pointer in s
12 if (s.charAt(i) == t.charAt(j)) {
13 i++;
14 }
15 }
16
17 // Check if we found all characters
18 return i == s.length();
19}