- 是这一份!!!
- 这下应该完整了。
- public class test
- {
- public static void main(String[] args)
- {
- showPermString("abcd");
- }
-
-
-
- public static void showPermString(String str)
- {
- for(int i=1; i<=str.length(); i++)
- {
- List<String> list = new ArrayList<String>();
- perm(list, str.toCharArray(), 0, i);
- System.out.println(list);
- }
- }
-
-
-
- public static void perm(List<String> list,char[] chs,int k,int len)
- {
- if(k == chs.length)
- {
- String string = String.valueOf(chs, 0, len);
- if(!list.contains(string))
- list.add(string);
- }
- else
- {
- for(int i=k; i<chs.length; i++)
- {
- swap(chs, i, k);
- perm(list,chs, k+1,len);
- swap(chs, i, k);
- }
- }
-
- }
-
- public static void swap(char[] chs,int i,int j)
- {
- char tem = chs[i];
- chs[i] = chs[j];
- chs[j] = tem;
- }
- }
复制代码 |