나의 풀이
import java.util.*;
class Solution {
public int[] solution(int n) {
int i =2;
HashSet<Integer> set = new HashSet<>();
while(n !=1){
if(n % i ==0){
n/=i;
set.add(i);
} else{
i+=1;
}
}
ArrayList<Integer> tmp = new ArrayList<>(set);
Collections.sort(tmp);
return tmp.stream().mapToInt(Integer::intValue).toArray();
}
}
▶ set을 사용하여 중복제거
▶ set을 리스트로 변환 후 정렬
▶ 리스트를 int[ ] 배열로 변환
'프로그래머스(자바) > LV.0(자바)' 카테고리의 다른 글
숨어있는 숫자의 덧셈(2)→replaceAll()+정규식, str.split() 두 번 써서 숫자 갈라치기 (0) | 2022.11.26 |
---|---|
잘라서 배열로 저장하기★★→ 한 문자씩 빈문자열 더하기 + if조건☆ (0) | 2022.11.26 |
이진수 더하기 (0) | 2022.11.26 |
한 번만 등장한 문자→frequency(), sorted(), groupingBy()★★★ (0) | 2022.11.26 |
진료순서정하기 → 인덱스 장난치기, 동기화★★, List의 indexOf() (0) | 2022.11.26 |