문제
나의 생각
소인수분해 알고리즘을 이용하면서 List 자료구조를 사용하는 방식으로 접근.
나의 답안
public static int[] solution(int n) {
List<Integer> a = new ArrayList<>();
for (int i = 2; i <= n; i++) {
while (n % i == 0) {
n = n / i;
if (!a.contains(i)){
a.add(i);
}
}
}
return a.stream().mapToInt(value -> value.intValue()).toArray();
}
'Programmers 문제풀이 > Lv.0' 카테고리의 다른 글
영어가 싫어요 (0) | 2023.03.02 |
---|---|
공 던지기 (0) | 2023.03.02 |
7의 개수 (0) | 2023.03.02 |
이진수 더하기 (0) | 2023.03.02 |
숨어있는 숫자의 덧셈 (2) (0) | 2023.03.01 |