您现在的位置是:主页 > news > 企业网站建设费用详情/西点培训学校

企业网站建设费用详情/西点培训学校

admin2025/6/10 7:41:47news

简介企业网站建设费用详情,西点培训学校,谷歌优化教程,做机网站在求一个字符串中所有字符的组合的时候,针对一个字符,有两种情况,假设在长度为n的字符串中选择长度为m的组合字符串, 第一是选择长度为n的字符串中的第一个字符,那么要在其余的长度n-1的字符串中选择m-1个字符 第二是不…

企业网站建设费用详情,西点培训学校,谷歌优化教程,做机网站在求一个字符串中所有字符的组合的时候,针对一个字符,有两种情况,假设在长度为n的字符串中选择长度为m的组合字符串, 第一是选择长度为n的字符串中的第一个字符,那么要在其余的长度n-1的字符串中选择m-1个字符 第二是不…

在求一个字符串中所有字符的组合的时候,针对一个字符,有两种情况,假设在长度为n的字符串中选择长度为m的组合字符串,

第一是选择长度为n的字符串中的第一个字符,那么要在其余的长度n-1的字符串中选择m-1个字符

第二是不选择长度为n的字符串中的第一个字符,那么要在其余的长度n-1的字符串中选择m个字符

递归结束的条件就是,当m为0,即从字符串中不再选出字符的时候,这个时候已经找到了m个字符的组合,输出即可。

 

import java.util.ArrayList;/*** @Author: Allen* @Version:v1.00* @CreateData:*/
public class ZiFuDeSuoYouZuHe {public static void main(String[] args) {Solution23 solution23 = new Solution23();ArrayList<ArrayList<Character>> list = solution23.Combination("abc");for(ArrayList<Character> s : list){System.out.println(s.toString());}}
}class Solution23{public ArrayList<ArrayList<Character>> Combination(String str) {ArrayList<ArrayList<Character>> list = new ArrayList<ArrayList<Character>>();char[] chArr = str.toCharArray();if(str==null || chArr.length==0){return list;}ArrayList<Character> charList = new ArrayList<Character>();for(int size=1; size<=chArr.length; size++){CombinationDetail(chArr,0,size,list,charList);}return list;}private void CombinationDetail(char[] chArr,int begin,int size,ArrayList<ArrayList<Character>> list,ArrayList<Character> charList){if(begin>chArr.length-size)return;if(size==0){ArrayList<Character> tempList = new ArrayList<Character>();for(Character character : charList){tempList.add(character);}list.add(tempList);return;}charList.add(chArr[begin]);CombinationDetail(chArr,begin+1,size-1,list,charList);charList.remove((Character)chArr[begin]);CombinationDetail(chArr,begin+1,size,list,charList);}
}

 

转载于:https://www.cnblogs.com/Allen-win/p/8951195.html