`
cy729215495
  • 浏览: 127241 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

字符串全排列算法

 
阅读更多
  List permu(String s){
        List result=new ArrayList();
        if("".equals(s)){
            result.add("");
            return result;
        }
        String c = s.substring(0, 1);
        List res = permu(s.substring(1));
        for(int i=0; i<res.size(); ++i){
            String t = (String) res.get(i);
            for(int j=0; j<=t.length(); ++j){
                StringBuffer  u = new StringBuffer(t);
                u.insert(j, c);
                result.add(u.toString());
            }
        }
        return result;
    }
    
    @Test
    public void testPermu() throws Exception {
        System.out.println(permu("abc"));
    }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics