글자 반복없이 가장 긴 부분문자열의 길이를 리턴하시오.
var lengthOfLongestSubstring = function (s) {
let count = 0;
let stack = [];
let answer = 0;
if (stack.length === 0) {
stack.push(s[0]);
count = 1;
}
for (let i = 1; i < s.length; i++)
if (stack.length != 0) {
if (s[i] != s[i - 1]) {
stack.push(s[i]);
count++;
} else {
count = 1;
}
console.log(i, count);
}
answer = count;
return answer;
};
let s = "abccabcbb";
console.log(lengthOfLongestSubstring(s));