I created a solution to a Leetcode problem.
I am supposed to find the longest substring's length in a string without repeating characters.
Below is my code:
let lengthOfLongestSubstring = (s) => {
let result = [];
for (let i = 0; i < s.length; i++) {
result.push([]);
let n = i;
while (s[n] && !result[i].includes(s[n])) {
result[i].push(s[n]);
n++;
}
result[i] = result[i].length;
}
return Math.max(...result);
}
console.log(lengthOfLongestSubstring("abcabcbb")); // should get output 3 because of "abc"
console.log(lengthOfLongestSubstring("bbbbb")); // should get output 1 because of "b"
console.log(lengthOfLongestSubstring("pwwkew")); // should get output 3 because of "wke"
When I try to submit it, I get the below error message:
What is the reason for this?
PS: You are not allowed to change the name of the function.