#include <stdio.h>
#include <algorithm>
struct {
bool operator()(string o1, string o2){
return o1 + o2 < o2 + o1;
}
}MyComp;
class Solution {
public:
string PrintMinNumber(vector<int> numbers) {
vector<string> vec;
char str[50];
for(int i = 0; i < numbers.size(); ++i){
snprintf(str, 50, "%d", numbers[i]);
vec.push_back(str);
}
sort(vec.begin(), vec.end(), MyComp);
string ret = "";
for(int i = 0; i < vec.size(); ++i)
ret += vec[i];
return ret;
}
};
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Collections;
public class Solution {
public String PrintMinNumber(int[] numbers) {
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < numbers.length; ++i)
list.add(String.valueOf(numbers[i]));
Collections.sort(list, new StrComp());
StringBuilder builder = new StringBuilder();
for(String num : list)
builder.append(num);
return builder.toString();
}
class StrComp implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
return (o1 + o2).compareTo(o2 + o1);
}
}
}