Skip to content

Commit 5b65690

Browse files
committed
simple traversal through the string
1 parent 85204c8 commit 5b65690

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public boolean isSubsequence(String s, String t) {
3+
if (s.length() == 0 && t.length() == 0) {
4+
return true;
5+
}
6+
if (s.length() == 0 && t.length() != 0) {
7+
return true;
8+
}
9+
int s_ptr = 0;
10+
for (int i=0; i<t.length(); i++) {
11+
if (t.charAt(i) == s.charAt(s_ptr)) {
12+
s_ptr++;
13+
}
14+
if (s_ptr == s.length()) {
15+
return true;
16+
}
17+
}
18+
return false;
19+
}
20+
}

0 commit comments

Comments
 (0)