题解 | #集合的所有子集#
集合的所有子集
http://www.nowcoder.com/practice/c333d551eb6243e0b4d92e37a06fbfc9
来个短的
import java.util.*;
public class Solution {
ArrayList<ArrayList<Integer>> res = new ArrayList<>();
ArrayList<Integer> path = new ArrayList<>();
public ArrayList<ArrayList<Integer>> subsets(int[] S) {
Arrays.sort(S);
dfs(S,0);
Collections.sort(res,(o1,o2)->o1.size()-o2.size());
return res;
}
public void dfs(int[] S,int index){
res.add(new ArrayList<>(path));
for(int i = index ; i < S.length;i++){
path.add(S[i]);
dfs(S,i+1);
path.remove(path.size()-1);
}
}
}
顺丰集团工作强度 406人发布