Update 38. 字符串的排列.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:05 +08:00
parent c4cc460f53
commit 32bf9991dc
+8 -7
View File
@@ -1,6 +1,6 @@
# 38. 字符串的排列
[NowCoder](https://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7?tpId=13&tqId=11180&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/zi-fu-chuan-de-pai-lie-lcof/)
## 题目描述
@@ -9,15 +9,16 @@
## 解题思路
```java
private ArrayList<String> ret = new ArrayList<>();
private List<String> ret = new ArrayList<>();
public ArrayList<String> Permutation(String str) {
if (str.length() == 0)
return ret;
char[] chars = str.toCharArray();
public String[] goodsOrder(String goods) {
if (goods == null || goods.length() == 0)
return new String[0];
ret.clear();
char[] chars = goods.toCharArray();
Arrays.sort(chars);
backtracking(chars, new boolean[chars.length], new StringBuilder());
return ret;
return ret.toArray(new String[ret.size()]);
}
private void backtracking(char[] chars, boolean[] hasUsed, StringBuilder s) {