import java.util.ArrayList;
class Solution {
public int[] solution(int n, int m) {
int[] answer = new int[2];
int max=Math.max(n,m);
int min=Math.min(n,m);
int maxMeasure=0;
ArrayList<Integer> nList=new ArrayList<Integer>();
ArrayList<Integer> mList=new ArrayList<Integer>();
for(int i=1;i<n/2+1;i++){
if(n%i==0){
nList.add(i);
}
}
nList.add(n);
for(int i=1;i<m/2+1;i++){
if(m%i==0){
mList.add(i);
}
}
mList.add(m);
for(Integer num:nList){
if(mList.contains(num))
maxMeasure=Math.max(num,maxMeasure);
}
answer[0]=maxMeasure;
while(true){
if(min==max){
answer[1]=min;
break;
}
if(min<max){
min+=Math.min(n,m);
continue;
}
if(min>max){
max+=Math.max(n,m);
continue;
}
}
return answer;
}
}
자바로 풀면 js보다 오래 걸린다.
내가 js에 많이 익숙해졌나보다