(Java) 프로그래머스 다음 큰 숫자
·
코딩 테스트
문제에 나온 조건대로 작성했다. n을 2진수로 변환하고 1의 개수를 세어 ncnt에 넣었다. n을 1씩 증가시키며 2진수로 변환했을 때 1의 개수가 같으면 반환하게 했다. 다른 분 코드 Integer.bitCount 메서드를 처음 봤는데 이걸 알았다면 더 간단하게 풀었을 것 같다. import java.lang.Integer; class TryHelloWorld { public int nextBigNumber(int n) { int a = Integer.bitCount(n); int compare = n+1; while(true) { if(Integer.bitCount(compare)==a) break; compare++; } return compare; } public static void main(S..