From 631bd9a3c6f630395988e2ef3b28a2484374d14b Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:06 +0800 Subject: [PATCH] =?UTF-8?q?Update=2045.=20=E6=8A=8A=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E6=8E=92=E6=88=90=E6=9C=80=E5=B0=8F=E7=9A=84=E6=95=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/45. 把数组排成最小的数.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/notes/45. 把数组排成最小的数.md b/notes/45. 把数组排成最小的数.md index a8b26184..7edfb267 100644 --- a/notes/45. 把数组排成最小的数.md +++ b/notes/45. 把数组排成最小的数.md @@ -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(); } ```