求大项集的所有子集(字符串的所有子集)

 public List<String> getSubSet(String largeItemSet) {
        List<String> list = new ArrayList<String>();
        char[] lisChar = largeItemSet.toCharArray();
        
        for(int i = 0; i < lisChar.length; i++) {
            list.add(new String(lisChar[i] + ""));
        }

        for(int j = 0; j < list.size(); j++) {
            for(int k = 0; k < lisChar.length; k++) {
                if(list.get(j).indexOf(new String(lisChar[k] + "")) == -1) {
                    String tempStr = list.get(j) + new String(lisChar[k] + "");
                    list.add(tempStr);
                }
            }
        }

        return list;
    }


是否还可以再优化一下呢?

测试了一下:
String str = "abcdefgh";


结果:
init:
deps-jar:
Warning: _asi\Main.java modified in the future.
Compiling 1 source file to E:\JavaProject\02_ASI_1\build\classes
compile:
run:
count:1   subSet.get(i):a
count:2   subSet.get(i):b
count:3   subSet.get(i):c
count:4   subSet.get(i):d
.
.
.
count:109590   subSet.get(i):hgfecadb
count:109591   subSet.get(i):hgfecbad
count:109592   subSet.get(i):hgfecbda
count:109593   subSet.get(i):hgfecdab
count:109594   subSet.get(i):hgfecdba
count:109595   subSet.get(i):hgfedabc
count:109596   subSet.get(i):hgfedacb
count:109597   subSet.get(i):hgfedbac
count:109598   subSet.get(i):hgfedbca
count:109599   subSet.get(i):hgfedcab
count:109600   subSet.get(i):hgfedcba
成功生成(总时间:22 秒)

你可能感兴趣的:(java,C++,c,C#,J#)