import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param strs string字符串一维数组 the strings
* @return string字符串
*/
public String minString (String[] strs) {
// write code here
// 解题思路:1.对所有字符串排序,采用优先级队列。
// 2.拼接排序后的字符串
if (strs == null ) {
return null;
}
if ( strs.length <= 1) {
return strs[0];
}
PriorityQueue<String> queue = new PriorityQueue<>(new Comparator<String>() {
public int compare(String str1, String str2) {
return (str1 + str2).compareTo(str2 + str1);
}
});
for (String s : strs) {
queue.offer(s);
}
StringBuilder strBuilder = new StringBuilder();
while (!queue.isEmpty()) {
strBuilder.append(queue.poll());
}
return strBuilder.toString();
}
}