diff --git a/notes/38. 字符串的排列.md b/notes/38. 字符串的排列.md index 149b3772..73de06ae 100644 --- a/notes/38. 字符串的排列.md +++ b/notes/38. 字符串的排列.md @@ -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 ret = new ArrayList<>(); +private List ret = new ArrayList<>(); -public ArrayList 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) {