simple rough direct code
is easy to understand with console, the code is as follows:
var lengthOfLongestSubstring = function (s) {
var arr = [];
var max = 0;
for (let index = 0; index < s.length; index++) {
var a = arr.indexOf(s[index]);
console.log(a, s[index], 222)
if (a != -1) {
arr.splice(0, a + 1)
console.log(111, arr, max)
}
arr.push(s.charAt(index))
console.log(arr, 222)
max = Math.max(arr.length, max)
}
return console.log(max, arr)
};
lengthOfLongestSubstring('abcdeasasas')
div>
Read More:
- JavaScript removes the number specified in the array
- String index out of range: 100 error report details and Solutions
- 43. Implementation of the shortest code of multiply strings | Java
- If JavaScript exceeds the length of the array, no error will be reported
- Python TypeError: return arrays must be of ArrayType
- Error 1: Vue quickly clicks the route to jump. Error: uncaught (in promise) error: request aborted
- [Two Sigma OA] Longest Chain
- Android studio push project to GitHub
- Deep understanding of async await asynchronous programming synchronization
- Vue3 uses element plus package to solve the problem of occasionally disordered code on the icon after it goes online
- Drawing cube with OpenGL
- Common attributes and methods of list and map in Dar
- Binary tree traversal (preorder, middle order, postorder, hierarchy traversal, depth first, breadth first)
- Vue—— Error: Redirected when going from “/“ to “/directory/tree“ via a navigation guard
- Error in comparing the size function of STL with negative number
- JavaScript emoticon package encryption
- vector length_error
- Java retainAll throws an unsupported operation exception record
- Exploring the streaming call of underscore
- Solution of vs program flashback problem