https://school.programmers.co.kr/learn/courses/30/lessons/12953
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import java.util.*;
class Solution {
public int solution(int[] arr) {
int answer = 1;
int size = arr.length;
int max = 0;
for(int i = 0 ; i < size ; i++){
max = Math.max(max,arr[i]);
}
for(int i = 2 ; i <= max; i++){
int maxCnt = 0;
for(int j = 0 ; j < size ; j++){
int cnt = 0;
while(arr[j] % i == 0){
cnt++;
arr[j] /= i;
}
maxCnt = Math.max(maxCnt,cnt);
}
for(int j = 0 ; j < maxCnt ; j++){
answer *= i;
}
}
System.out.println(Arrays.toString(arr));
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 푸드 파이트 (JAVA) (0) | 2023.01.13 |
---|---|
프로그래머스 크기가 작은 부분 문자열 (JAVA) (0) | 2023.01.12 |
프로그래머스 분수의 덧셈 (JAVA) (0) | 2023.01.10 |
프로그래머스 영어가 싫어요 (JAVA) (0) | 2023.01.09 |
프로그래머스 직사각형 넓이 구하기 (JAVA) (0) | 2023.01.08 |