String 형인 str 인자에서 중복되지 않은 알파벳으로 이루어진 제일 긴 단어의 길이를 반환해주세요.
str: 텍스트
return: 중복되지 않은 알파벳 길이 (숫자 반환)
예를 들어,
str = "abcabcabc"
return 은 3
=> 'abc' 가 제일 길기 때문
str = "aaaaa"
return 은 1
=> 'a' 가 제일 길기 때문
str = "sttrg"
return 은 3
=> 'trg' 가 제일 길기 때문
const getLengthOfStr = str => {
// 초기상태 설정
let countMax = 0; // 중복되지않은 문자열의 길이 초기상태
let countString = ""; // 중복되지않은 문자열 초기상태
for(let i=0; i<str.length; i++) {
let indexOfStr = countString.indexOf(str[i]);
if (indexOfStr !== -1) {
countString = countString.substr(indexOfStr + 1);
}
countString = countString + str[i];
countMax = Math.max(countMax, countString.length);
}
return countMax;
}