프로그래머스 - 소인수분해]

차관호·2023년 3월 28일
0

문제링크 - 프로그래머스 - 소인수분해

import java.util.HashSet;

class Solution {
    public int[] solution(int n) {
        HashSet<Integer> set = new HashSet<>();

       for(int i=2; i<=n; i++){
           while(n%i==0){
               set.add(i);
               n /= i;
           }
       }
       if(n!=1) set.add(n);
       return set.stream().mapToInt(Integer::intValue).sorted().toArray();
  }
}
profile
안녕하세요 :-)

0개의 댓글