192. 소인수분해

김해준's avatar
Jan 06, 2026
192. 소인수분해

사용언어 : Java

문제
notion image
풀이
class Solution { public int[] solution(int n) { int[] temp = new int[n/2]; int val = n; int index = 0; int cur = 2; while(val > 1) { if(val % cur == 0) { temp[index] = cur; index++; while(val % cur == 0) { val /= cur; if(val <= 1)break; } } cur++; } int[] answer = new int[index]; for(int i = 0 ; i < answer.length; i++) { answer[i] = temp[i]; } return answer; } }
notion image
Share article