From 9a2ac21baccc71f3cbbe5b1e3b1e9483631a0f60 Mon Sep 17 00:00:00 2001 From: aestheticw3 <48285878+aestheticw3@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:30:54 +0700 Subject: [PATCH] additional condition within the for loop the loop should stop once it has traversed the substring --- javascript/0392-is-subsequence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/0392-is-subsequence.js b/javascript/0392-is-subsequence.js index 41bc09cdc..6f8fee951 100644 --- a/javascript/0392-is-subsequence.js +++ b/javascript/0392-is-subsequence.js @@ -11,7 +11,7 @@ var isSubsequence = function(s, t) { let j = 0; - for(let i = 0; i < t.length; i++) { + for(let i = 0; i < t.length && j < s.length; i++) { if(s[j] === t[i]) { j++; }