https://school.programmers.co.kr/learn/courses/30/lessons/12911
class Solution {
public int solution(int n) {
int answer = 0;
String temp = Integer.toBinaryString(n);
int tempCount = temp.length() - temp.replace("1", "").length();
int num = n+1;
while(true){
String num_temp = Integer.toBinaryString(num);
int num_count = num_temp.length() - num_temp.replace("1","").length();
if(tempCount == num_count) {
answer = num;
break;
}
else {
num++;
}
}
return answer;
}
}
'๐ ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ (0) | 2023.04.03 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ํผ๋ณด๋์น ์ (0) | 2023.04.03 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ซ์์ ํํ (0) | 2023.04.02 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐ (0) | 2023.03.31 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ฌ๋ฐ๋ฅธ ๊ดํธ (0) | 2023.03.30 |