其他分享
首页 > 其他分享> > 字符串全排列

字符串全排列

作者:互联网

    public void perm(char[] chs, int start, List<String > res) {
        if (start == chs.length - 1) {
            res.add(new String(chs));
        } else {
            for (int i = start; i < chs.length; i++) {
                swapChs(chs, start, i);
                perm(chs, start + 1, res);
                swapChs(chs, start, i);
            }
        }
    }

    private void swapChs(char[] chs, int i, int j) {
        char temp = chs[i];
        chs[i] = chs[j];
        chs[j] = temp;
    }

 

标签:排列,int,res,char,start,chs,字符串,swapChs
来源: https://www.cnblogs.com/luckygxf/p/14801234.html