Skip to content

Commit 9a2ac21

Browse files
author
aestheticw3
authoredSep 7, 2023
additional condition within the for loop
the loop should stop once it has traversed the substring
1 parent 086ba0e commit 9a2ac21

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎javascript/0392-is-subsequence.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var isSubsequence = function(s, t) {
1111

1212
let j = 0;
1313

14-
for(let i = 0; i < t.length; i++) {
14+
for(let i = 0; i < t.length && j < s.length; i++) {
1515
if(s[j] === t[i]) {
1616
j++;
1717
}

0 commit comments

Comments
 (0)
Please sign in to comment.