Generating all permutations of a given string

前端 未结 30 1658
我寻月下人不归
我寻月下人不归 2020-11-21 06:35

What is an elegant way to find all the permutations of a string. E.g. permutation for ba, would be ba and ab, but what about longer st

30条回答
  •  醉酒成梦
    2020-11-21 06:43

    Permutation of String:

    public static void main(String args[]) {
        permu(0,"ABCD");
    }
    
    static void permu(int fixed,String s) {
        char[] chr=s.toCharArray();
        if(fixed==s.length())
            System.out.println(s);
        for(int i=fixed;i

提交回复
热议问题