File tree 1 file changed +5
-6
lines changed
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 5
5
const lengthOfLongestSubstring = ( s ) => {
6
6
let charList = s . split ( '' ) ,
7
7
tmpList = [ ] ,
8
- result = [ ] ,
9
- prevTmpList = [ ] ;
8
+ prevTmpList = [ ] ,
9
+ result = [ ] ;
10
10
11
11
for ( let i = 0 ; i < charList . length ; i ++ ) {
12
- let currChar = charList [ i ] ;
13
12
14
- if ( tmpList . includes ( currChar ) && tmpList . length > prevTmpList . length ) prevTmpList = [ ...tmpList ] ;
13
+ if ( tmpList . includes ( charList [ i ] ) && tmpList . length > prevTmpList . length ) prevTmpList = [ ...tmpList ] ;
15
14
16
- let nbRemove = tmpList . indexOf ( currChar ) ;
15
+ let nbRemove = tmpList . indexOf ( charList [ i ] ) ;
17
16
for ( let j = 0 ; j <= nbRemove ; j ++ ) {
18
17
tmpList . shift ( ) ;
19
18
}
20
19
21
- tmpList . push ( currChar ) ;
20
+ tmpList . push ( charList [ i ] ) ;
22
21
23
22
result = prevTmpList . length > tmpList . length ? prevTmpList : tmpList ;
24
23
}
You can’t perform that action at this time.
0 commit comments