Skip to content

Commit e2c2b23

Browse files
authored
Update Is Subsequence.java
1 parent 9f154a1 commit e2c2b23

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Easy/Is Subsequence.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
class Solution {
2-
public boolean isSubsequence(String s, String t) {
3-
int j = 0;
4-
for (int i = 0; i < t.length() && j < s.length(); i++) {
5-
if (s.charAt(j) == t.charAt(i)) {
6-
j++;
7-
}
2+
public boolean isSubsequence(String s, String t) {
3+
int sIdx = 0;
4+
int tIdx = 0;
5+
while (sIdx < s.length() && tIdx < t.length()) {
6+
if (s.charAt(sIdx) == t.charAt(tIdx)) {
7+
sIdx++;
8+
}
9+
tIdx++;
10+
}
11+
return sIdx == s.length();
812
}
9-
return j == s.length();
10-
}
1113
}

0 commit comments

Comments
 (0)