CCI 9.5 字符串全排列
来源:互联网 发布:java工程师转web安全 编辑:程序博客网 时间:2024/04/28 21:19
编写一个方法,确定某字符串的所有排列组合。
package cci;import java.util.ArrayList;public class CCI_9_5 {public static ArrayList<String> permutation(String str){if(str==null)return null;ArrayList<String> result = new ArrayList<String>();if(str.length()<=1){result.add(str);return result;}char first = str.charAt(0);String sub = str.substring(1);ArrayList<String> perms = permutation(sub);for(String perm : perms){for(int i=0; i<=perm.length(); i++){String temp = insertCharAt(perm, i, first);result.add(temp);}}return result;}private static String insertCharAt(String str, int index, char c){String pre = str.substring(0,index);String post = str.substring(index);return pre+c+post;}public static void main(String[] args) {// TODO Auto-generated method stubString str = "abc";ArrayList<String> result = permutation(str);for(String item : result){System.out.println(item);}}}
0 0
- CCI 9.5 字符串全排列
- CCI 9.5 字符串全排列
- 字符串的全排列
- 字符串的全排列
- 字符串全排列问题
- 字符串全排列
- 字符串全排列问题
- 字符串全排列
- 求字符串全排列
- 求字符串全排列
- 字符串的全排列
- 字符串全排列代码
- 字符串全排列
- 字符串全排列
- 字符串全排列
- 字符串的全排列
- 字符串全排列
- 求字符串全排列
- 获取指定的LocationProvider
- Android网络编程之请求和文件上传
- Cocos2dx内存优化
- openCV 高斯模糊及原理
- Robot Framework selenium2library库获取某个对象的属性
- CCI 9.5 字符串全排列
- 外部IO中断和IPI中断
- 目标跟踪学习笔记_1(opencv中meanshift和camshift例子的应用)
- jsp中图片显示
- K - A/B(逆元)(拓展欧几里德)
- nandflash下通过supervivi命令行实现挂载root_qtopia的NFS挂载
- nandflash
- Esper事件处理引擎_14_EPL 语法_7_Patterns_1_模式匹配
- linux下面串口工具C-kermit