HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
프론트엔드 스쿨 교안(1기)
/
📝
(코테준비) 자료구조 및 알고리즘
/
✌
JS 100제 - 2권
/
🔥
문제93
/
✔️
답안
✔️

답안

function solution(frame, page){ let runTime = 0; let temp = []; // frame이 0일때, page의 크기만큼 6을 곱해주고 끝낸다 if (frame === 0){ runTime = page.length * 6; return runTime; } for (let i of page){ if (temp.includes(i)){ runTime += 1 } else { // 배열이 비었으면 무조건 넣어야 하므로 if문을 사용 if (temp.length < frame){ temp.push(i); } else { // 가장 사용되지 않은 첫번째 배열을 제거하고 맨 뒤에 입력값을 저장 temp.shift(); temp.push(i); } // if문 실행에 상관없이 runTime은 10이 추가된다 runTime += 6; } } return runTime; } const f = parseInt(prompt('프레임을 입력해주세요.'), 10); const page = prompt('페이지를 입력해주세요.').split(''); console.log(solution(f, page));