-
[TIL] Algorithm 3Develope/Algorithm 2020. 5. 19. 11:32
1. 문제
2. 결과
const getLengthOfStr = str => { if(!str){return 0} let arr = []; let sliced = ""; for (let i in str) { if (sliced.includes(str[i])) { //for문을 돌면서 만약 같은 알파벳이 있다면 sliced = sliced.slice(sliced.indexOf(str[i]) + 1); }//빈문자열인 sliced for문을 돌면서 하나씩 잘라준다. sliced += str[i]; arr.push(sliced.length); } return Math.max(...arr); // 14 } getLengthOfStr("abcdefghcijklmnop");
'Develope > Algorithm' 카테고리의 다른 글
[TIL] Algorithm 6 (0) 2020.07.20 [TIL] Algorithm 5 (0) 2020.05.20 [TIL] Algorithm 4 (0) 2020.05.19 [TIL] Algorithm 2 (0) 2020.05.13 [TIL] Algorithm 1 (0) 2020.05.13