代码
public static IList<IList<int>>
Subsets(int[] nums)
{
List<IList<int>>
result = new List<IList<int>>();
result.Add(new List<int>());
Array.Sort(nums);
for(int i = 0; i < nums.Length; i++)
{
List<IList<int>>
newResult = new List<IList<int>>();
foreach (var r in result)
{
List<int> nr = new List<int>(r);
nr.Add(nums[i]);
newResult.Add(nr);
}
result.AddRange(newResult);
}
return result;
}