Skip to content

Commit 1da6b0c

Browse files
authored
[20251213] PGM / Lv2 / 다음 큰 숫자 / 이종환
1 parent 8c45364 commit 1da6b0c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
class Solution {
6+
public int solution(int n) {
7+
8+
int goalCnt = getTwoCnt(n);
9+
10+
int num = n+1;
11+
12+
while (true){
13+
int target = num;
14+
int tempTwoCnt = getTwoCnt(target);
15+
if (tempTwoCnt == goalCnt) {
16+
break;
17+
}
18+
num++;
19+
}
20+
return num;
21+
}
22+
23+
public int getTwoCnt(int n){
24+
int result = 0;
25+
while (n > 0){
26+
if (n%2 != 0) result++;
27+
n /=2;
28+
}
29+
30+
return result;
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)