import java.util.ArrayList; public class Test46 { public static ArrayList<String> permutationNoRepeat (String str) { ArrayList<String> res = new ArrayList<>(); if (str == null || str.length() == 0) { return res; } char[] chs = str.toCharArray(); process2(chs , 0 , res); return res; } public static void process2 (char[] str , int i , ArrayList<String> res) { if (i == str.length) { res.add(String.valueOf(str)); } boolean[] visit = new boolean[26]; for (int j = i; j < str.length; j++) { if (!visit[str[j] - 'a']) { visit[str[j] - 'a'] = true; swap(str , i , j); process2(str , i + 1 , res); swap(str , i , j); } } } public static void swap (char[] chs , int i , int j) { char temp = chs [i]; chs[i] = chs [j]; chs[j] = temp; } }
08-09
2696
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)