HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
👻
개발 기록
/
코딩테스트 스터디
코딩테스트 스터디
/
점프와 순간이동

점프와 순간이동

문제

notion image
notion image

풀이

은찬
효성
재영
Link
https://programmers.co.kr/learn/courses/30/lessons/12980
Deadline
Dec 21, 2021
Status
Archived
Type
greedy
const solution = (n) =>{ let answer = 0; while(n){ if(Math.floor(n % 2)){ answer++; } n = Math.floor(n / 2); } return answer; }
function solution(n) { let answer = 0; while(n > 1) { if(n%2 === 0) { n = n/2; } else { n--; answer++; } } return answer+1; }
const solution = (n, res = 0) => n === 1 ? res + 1 : solution(parseInt(n / 2), res + n % 2)