public String solution(String X, String Y) {
StringBuilder sb = new StringBuilder();
int[] xArr = new int[10];
int[] yArr = new int[10];
for (char x : X.toCharArray()) {
xArr[x - '0']++;
}
for (char y : Y.toCharArray()) {
yArr[y - '0']++;
}
for (int i = 9; i >= 0; i--) {
while (xArr[i] > 0 && yArr[i] > 0) {
sb.append(i);
xArr[i]--;
yArr[i]--;
}
}
if (sb.length() == 0) {
return "-1";
}
if (sb.charAt(0) == '0') {
return "0";
}
return sb.toString();
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/131128