We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4aecda7 commit 6c1d424Copy full SHA for 6c1d424
1 file changed
src/main/java/com/fishercoder/solutions/firstthousand/_392.java
@@ -4,22 +4,13 @@ public class _392 {
4
5
public static class Solution1 {
6
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;
+ int i = 0;
+ for (int j = 0; i < s.length() && j < t.length(); j++) {
+ if (s.charAt(i) == t.charAt(j)) {
+ i++;
20
}
21
22
- return true;
+ return i == s.length();
23
24
25
0 commit comments