privatevoidperm(char[] s, int ind, ArrayList<String> res){ // 退出边界 if (ind == s.length - 1) { res.add(String.valueOf(s)); return; }
Set<Character> set = new HashSet<>(); for (int i = ind; i < s.length; i++) { if (set.contains(s[i])) continue; set.add(s[i]); swap(s, ind, i); perm(s, ind + 1, res); swap(s, ind, i); } }
privatevoidswap(char[] s, int a, int b){ // 参数检查 if (a < 0 || a >= s.length || b < 0 || b >= s.length) thrownew RuntimeException("超出数组边界");
近期评论