We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5070481 + 7a70926 commit 496a1f2Copy full SHA for 496a1f2
1 file changed
ksinji/202601/PGM 21 다음 큰 숫자.md
@@ -0,0 +1,26 @@
1
+```java
2
+class Solution {
3
+ public int solution(int n) {
4
+ int answer = n+1;
5
+ int cnt = countOne(n);
6
+
7
+ while (answer > n) {
8
+ if (countOne(answer) == cnt){
9
+ break;
10
+ }
11
+ answer++;
12
13
14
+ return answer;
15
16
17
+ int countOne(int x) {
18
+ String s = Integer.toBinaryString(x);
19
+ int cnt = 0;
20
+ for (int i = 0; i < s.length(); i++) {
21
+ if (s.charAt(i) == '1') cnt++;
22
23
+ return cnt;
24
25
+}
26
+```
0 commit comments