Skip to content

Commit 6c1d424

Browse files
update 392
1 parent 4aecda7 commit 6c1d424

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

  • src/main/java/com/fishercoder/solutions/firstthousand

src/main/java/com/fishercoder/solutions/firstthousand/_392.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@ public class _392 {
44

55
public static class Solution1 {
66
public boolean isSubsequence(String s, String t) {
7-
int left = 0;
8-
for (int i = 0; i < s.length(); i++) {
9-
boolean foundI = false;
10-
int j = left;
11-
for (; j < t.length(); j++) {
12-
if (s.charAt(i) == t.charAt(j)) {
13-
left = j + 1;
14-
foundI = true;
15-
break;
16-
}
17-
}
18-
if (j == t.length() && !foundI) {
19-
return false;
7+
int i = 0;
8+
for (int j = 0; i < s.length() && j < t.length(); j++) {
9+
if (s.charAt(i) == t.charAt(j)) {
10+
i++;
2011
}
2112
}
22-
return true;
13+
return i == s.length();
2314
}
2415
}
2516
}

0 commit comments

Comments
 (0)