字符所有组合
2014-11-09 21:22
183 查看
package com.vic.string; import java.util.ArrayList; import java.util.List; public class Combination { private static int count = 0; static void combination(char[] s){ for(int i=1;i<=s.length;i++){ combination(s,new ArrayList<String>(),0,i); } } private static void combination(char[] s,List<String> comList,int start, int length) { if(start>=s.length&&length>0) return; if(length==0||start>=s.length){ for(String str:comList){ System.out.print(str); } System.out.println(); count++; }else{ List<String> tmpList = new ArrayList<String>(comList);//保留之前的状态 //包含当前字符,剩余字符里选length-1个 comList.add(s[start]+""); combination(s,comList,start+1,length-1); //不包含当前字符 combination(s,tmpList,start+1,length); } } public static void main(String[] args) { char[] s = "abc".toCharArray(); combination(s); System.out.println(count); } }
相关文章推荐
- LeetCodet题解--17. Letter Combinations of a Phone Number(所有数字键盘组合所对应的所有字符集合)
- 输入一个字符串,输出该字符串中字符的所有组合
- 找出一个字符数组(元素不重复)所有可能字符的组合
- 字符串中字符的所有组合(组合中的先后顺序不考虑)
- 用JAVA编写一个算法实现对一个字符数组的所有元素的所有组合
- 打印n个字符的所有组合
- 网新国际2008春季招聘笔试题 打印电话号码所对应的字符的所有可能组合
- 从文件读取字符串,并求出该字符串包含的字符集中所有字符的全部组合
- [小算法]从M个不同字符中任取N个字符的所有组合
- LeetCode--438. Find All Anagrams in a String(找到所有字符组合)Python
- 字符串中字符的所有组合(递归方式)
- 剑指offer:求字符的所有组合
- 【算法题】字符的所有组合
- 组合问题(从M个不同字符中任取N个字符的所有组合)
- 打印一个字符串中字符的所有组合
- 面试题28—相关题目(字符所有的组合)
- 显示字符串中所有字符的排列组合。
- 输出该字符串中字符的所有组合
- 题目:输入一个字符串,输出该字符串中字符的所有组合
- 显示字符串中所有字符的排列组合。