import java.util.Arrays;
import java.util.stream.Collectors;
/**
* @author xienl
* @description
* @date 2022/8/4
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
String[] str = {"abc","de", "ab", "aa", "asd", "a", "b", "dfs"};
System.out.println(solution.minString(str));
}
public String minString (String[] strs) {
// write code here
return Arrays.stream(strs).sorted((a, b) -> (a + b).compareTo(b + a)).collect(Collectors.joining());
}
}
牛客网:NC85 拼接所有的字符串产生字典序最小的字符串
最新推荐文章于 2023-08-04 21:50:18 发布
本文介绍了一种Java实现的方法,通过Stream API对字符串数组进行排序,以求得两个字符串拼接后字典序最小的组合。Solution类的minString方法展示了如何使用(a+b).compareTo(b+a)比较字符串。

1671

被折叠的 条评论
为什么被折叠?



