java에서 Comparator 사용법을 익힐 수 있었다.
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Collections;
class Solution {
public String solution(int[] numbers) {
String answer = "";
List<String> list = new ArrayList<String>();
for(int a : numbers) list.add(String.valueOf(a));
Collections.sort(list, new numbersComparator());
if(list.get(0).equals("0")) return "0";
for (String a : list) answer += a;
return answer;
}
}
class numbersComparator implements Comparator<String> {
@Override
public int compare(String a, String b) {
return ((b + a).compareTo(a + b));
}
}
List<String> list = new ArrayList<String>();
for(int a : numbers) list.add(String.valueOf(a));
Collections.sort(list, new numbersComparator());
class numbersComparator implements Comparator<String> {
@Override
public int compare(String a, String b) {
return ((b + a).compareTo(a + b));
}
}