2014年1月21日

LeetCode: Subsets & Subsets II

摘要: Given a set of distinct integers,S, return all possible subsets.我想到的算法是这个样子的。我想用的是递归。n个数的subset可以由n-1个数的subset产生。就是把subset(n-1)以及其中每一个组合加上S[n]。比如[1,2,3] = [], [1], [2], [1,2], []+3, [1]+3, [2]+3, [1, 2]+3; 1 public static ArrayList> subsets(int[] S, int aa) { 2 if(aa == 0) { 3 re... 阅读全文

posted @ 2014-01-21 03:45 longhorn 阅读(254) 评论(0) 推荐(0) 编辑

导航