Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 564 Bytes

File metadata and controls

27 lines (22 loc) · 564 Bytes

프로그래머스 Level2 : 연습문제 다음 큰 숫자

class Solution {
    int cntOne(int n){
        String binary = Integer.toBinaryString(n);
        int cnt = 0;
        for(char c : binary.toCharArray()){
            if(c == '1') cnt++;
        }
        return cnt;
    }
    
    public int solution(int n) {
        int cnt = cntOne(n);
        while(true){
            if(cnt == cntOne(++n)){
                return n;
            }
        }
        
    }
    
}