[JAVA 문제 풀이] 264. 점프와 순간 이동

프로그래머스 (12980)
Stupefyee's avatar
May 19, 2025
[JAVA 문제 풀이] 264. 점프와 순간 이동
notion image
 

내가 작성한 코드

public class Solution { public int solution(int n) { // 1의 개수를 세면 됨 // 홀수가 나올때마다 한칸만 전진하고 순간이동을 반복하기 때문 return Integer.bitCount(n); } }
 

다른 사람의 코드

public class Solution { public int solution(int n) { int ans = 0; while (n > 0) { if (n % 2 == 1) { ans++; } n /= 2; } return ans; } }
 
Share article

stupefyee