22
rated 0 times
[
27]
[
5]
/ answers: 1 / hits: 20930
/ 7 Years ago, fri, march 24, 2017, 12:00:00
The problems asks given a string, find the longest non-repeating sub-string without repeating characters. I am a little stumped why returning my code is not working for the string dvdf for example. Here is my code :
function lengthOfLongestSubstring(check) {
var letters = check.split();
var max = 0;
var result = [];
for (var i = 0; i < letters.length; i++) {
var start = i
if (result.indexOf(letters[i]) === -1) {
result.push(letters[i])
} else {
i = i - 1
result = []
}
if (max === 0 || max < result.length) {
max = result.length
}
}
return max
}
More From » javascript