Skip to content

Commit 716bbd1

Browse files
committed
fixed solution for subsequence
1 parent 4871716 commit 716bbd1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

isSubsequence.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
const isSubsequence = (str1, str2) => {
55
let pointer1 = 0;
6-
let pointer2 = str1.length;
6+
let pointer2 = 0;
77

8-
while (pointer2 <= str2.length) {
9-
if (str2.substring(pointer1, pointer2) === str1) return true;
10-
else {
11-
pointer1++;
12-
pointer2++;
13-
}
8+
while (pointer2 < str2.length) {
9+
if (str1[pointer1] === str2[pointer2]) pointer1++;
10+
if (pointer1 === str1.length) return true;
11+
pointer2++;
1412
}
1513
return false;
1614
};

0 commit comments

Comments
 (0)