๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/12980?language=java
ํ์ด
import java.util.*;
public class Solution {
public int solution(int n) {
int ans = 0;
while(n != 0){
if(n % 2 == 0){
n /= 2;
} else {
n--;
ans++;
}
}
return ans;
}
}
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Java] [Level2] ์์ ๋์งํ (0) | 2024.01.19 |
---|---|
โฌ [Programmers] [Java] [Level2] ์์ด ๋๋ง์๊ธฐ (0) | 2024.01.11 |
โฌ [Programmers] [Java] [Level2] ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ (0) | 2024.01.07 |
โฌ [Programmers] [Java] [Level2] ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐ (1) | 2024.01.04 |
โฌ [Programmers] [Java] [Level2] ์ต์๊ฐ ๋ง๋ค๊ธฐ (2) | 2024.01.03 |