[Java] Programmers - Next Big Number
Finding larger numbers with identical binary 1 counts, and efficient problem solving using Java Integer.bitCount()
한국어 원문은 여기에서 볼 수 있습니다.
[Java] Programmers - Next Big Number
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public int solution(int n) {
int target = Integer.bitCount(n);
while(target != Integer.bitCount(++n)) {
}
return n;
}
}
- I continued to solve the problem using different solving methods, but it was difficult to pass the accuracy test but not the efficiency test.
Integer.bitCount(n)
- A function that immediately counts the number of 1s when the number is converted to binary in Java.