import java.util.*;
class Solution {
public int[] solution(int n) {
List<Integer> list = new ArrayList();
int temp=n;
for(int i=2;i<=n;i++)
{
boolean chk=false;
while(temp%i==0)
{
temp/=i;
if(!chk) list.add(i);
chk=true;
}
}
int[] answer = new int[list.size()];
for(int i=0;i<list.size();i++)
{
answer[i] = list.get(i);
}
return answer;
}
}
'코딩테스트 > lv0' 카테고리의 다른 글
[프로그래머스 코딩테스트] java Lv.0 삼각형의 완성조건(2) (0) | 2024.08.09 |
---|---|
[프로그래머스 코딩테스트] java Lv.0 문자열 계산하기 (0) | 2024.08.09 |
[프로그래머스 코딩테스트] java Lv.0 이진수 더하기 (0) | 2024.08.08 |
[프로그래머스 코딩테스트] java Lv.0 잘라서 배열로 저장하기 (0) | 2024.08.08 |
[프로그래머스 코딩테스트] java Lv.0 컨트롤 제트 (0) | 2024.08.07 |