Skip to content

Commit 0c5cbac

Browse files
committed
✨ [q5] 90+% beats
1 parent 913a63f commit 0c5cbac

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

3/solution.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
const lengthOfLongestSubstring = (s) => {
66
let charList = s.split(''),
77
tmpList = [],
8-
result = [],
9-
prevTmpList = [];
8+
prevTmpList = [],
9+
result = [];
1010

1111
for (let i = 0; i < charList.length; i++) {
12-
let currChar = charList[i];
1312

14-
if (tmpList.includes(currChar) && tmpList.length > prevTmpList.length) prevTmpList = [...tmpList];
13+
if (tmpList.includes(charList[i]) && tmpList.length > prevTmpList.length) prevTmpList = [...tmpList];
1514

16-
let nbRemove = tmpList.indexOf(currChar);
15+
let nbRemove = tmpList.indexOf(charList[i]);
1716
for (let j = 0; j <= nbRemove; j++) {
1817
tmpList.shift();
1918
}
2019

21-
tmpList.push(currChar);
20+
tmpList.push(charList[i]);
2221

2322
result = prevTmpList.length > tmpList.length ? prevTmpList : tmpList;
2423
}

0 commit comments

Comments
 (0)