mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-01 03:23:42 +00:00
Update 45. 把数组排成最小的数.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[牛客网](https://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993?tpId=13&tqId=11185&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
||||
[Leetcode](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -13,17 +13,17 @@
|
||||
可以看成是一个排序问题,在比较两个字符串 S1 和 S2 的大小时,应该比较的是 S1+S2 和 S2+S1 的大小,如果 S1+S2 \< S2+S1,那么应该把 S1 排在前面,否则应该把 S2 排在前面。
|
||||
|
||||
```java
|
||||
public String PrintMinNumber(int[] numbers) {
|
||||
if (numbers == null || numbers.length == 0)
|
||||
public String crackPassword(int[] password) {
|
||||
if (password == null || password.length == 0)
|
||||
return "";
|
||||
int n = numbers.length;
|
||||
int n = password.length;
|
||||
String[] nums = new String[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
nums[i] = numbers[i] + "";
|
||||
nums[i] = password[i] + "";
|
||||
Arrays.sort(nums, (s1, s2) -> (s1 + s2).compareTo(s2 + s1));
|
||||
String ret = "";
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for (String str : nums)
|
||||
ret += str;
|
||||
return ret;
|
||||
ret.append(str);
|
||||
return ret.toString();
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user