java 数字组合代码 按顺序,每组无重复,形成一个无重复的字符串
2016-04-28 22:08
411 查看
public class test { static String[] str = { "11", "12", "13", "14", "15" }; static int num = 4; public static void main(String[] args) { ArrayList<String[]> result = noteCount(str,4); for (int i = 0; i < result.size(); i++) { System.out.println(i+"--"+result.size()+"-"+Arrays.toString(result.get(i))); } } public static ArrayList<String[]> noteCount(String[] source, int n) { ArrayList<String[]> result = new ArrayList<String[]>(); if (n == 1) { for (int i = 0; i < source.length; i++) { result.add(new String[] { source[i] }); } } else if (source.length == n) { result.add(source); } else { String[] psource = new String[source.length - 1]; for (int i = 0; i < psource.length; i++) { psource[i] = source[i]; } result = noteCount(psource, n); ArrayList<String[]> tmp = noteCount(psource, n - 1); for (int i = 0; i < tmp.size(); i++) { String[] rs = new String ; for (int j = 0; j < n - 1; j++) { rs[j] = tmp.get(i)[j]; } rs[n - 1] = source[source.length - 1]; result.add(rs); } } return result; } }
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树