思路:
经典的快拍思路!
class Solution {
public String minNumber(int[] nums) {
String[] strs = new String[nums.length];
for (int i = 0; i < nums.length; i++)
strs[i] = String.valueOf(nums[i]);
quickSort(strs, 0, strs.length - 1);
StringBuilder res = new StringBuilder();
for (String s : strs)
res.append(s);
return res.toString();
}
public void quickSort(String[] strs, int l, int r) {
if (l >= r) {
return;
}
int pos = partition(strs, l, r);
quickSort(strs, l, pos - 1);
quickSort(strs, pos + 1, r);
}
int partition(String[] strs, int l, int r) {
int i = l, j = r;
String tmp = strs[i];
while (i < j) {
while (i < j &&(strs[j] + tmp).compareTo(tmp + strs[j]) >= 0 ) {
j--;
}
strs[i] = strs[j];
while (i < j && (strs[i] + tmp).compareTo(tmp + strs[i]) <= 0 ) {
i++;
}
strs[j] = strs[i];
}
strs[i] = tmp;
return i;
}
}