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:
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- [Two Sigma OA] Longest Chain
- Solve the problem of using logback console to print log Chinese characters in IDEA as garbled characters
- Finding the longest connection path of a string
- JavaScript removes the number specified in the array
- Type error: cannot unpack non Iterable non type object appears when starting Bert server in Ubuntu system
- Cannot read property ‘substring’ of undefined in Vue
- Vue: cannot read property ‘substring’ of undefined“
- Remove M Characters “Control M” or “^M” or “CTRL M” Characters in a UNIX file
- To solve the problem of repeated password input when operating sourcetree on MAC
- The function of structured shuffleplit() in SK learn realizes the division of data set
- Numpy realizes the forward propagation process of CNN
- If JavaScript exceeds the length of the array, no error will be reported
- Spring MVC realizes page upload file
- JavaScript emoticon package encryption
- Mac realizes file interaction (upload and download) between terminal and server
- Remove spaces after characters in Excel cells
- Tdengine failed to start, start request repeated too quickly for taosd.service
- After vscode installs ts, TSC compiles and generates JS, and an error is reported (repeated variables, etc.)
- C / C + + library function (tower / tower) realizes the conversion of letter case