프로그래머스 연습문제 다음 큰 숫자 [JAVA] - 22년 10월 2일

Denia·2022년 10월 2일
0

코딩테스트 준비

목록 보기
85/201
class Solution {
    public int solution(int n) {
        int answer = 0;

        int oldNBit1Count = Integer.bitCount(n);

        for (int i = n + 1; i <= 1_000_000; i++) {
            if(Integer.bitCount(i) == Integer.bitCount(n)) {
                answer = i;
                break;
            }
        }
        
        return answer;
    }
}

profile
HW -> FW -> Web

0개의 댓글