标签:
题目描述:public class Solution {
public IList<IList<int>> Permute(int[] nums) {
return Collect(nums.ToList());
}
private IList<IList<int>> Collect(IList<int> nums)
{
if(nums.Count <= 1){
return new List<IList<int>>(){new List<int>(nums)};
}
if(nums.Count == 2){
return new List<IList<int>>(){new List<int>(){nums[0],nums[1]},new List<int>(){nums[1],nums[0]}};
}
var newSet = new List<IList<int>>();
for(var i = 0;i < nums.Count; i++){
// take out nums[i] and put at last for each sub set
var x = nums[i];
nums.RemoveAt(i);
var subSet = Collect(nums);
for(var k = 0;k < subSet.Count; k++){
subSet[k].Add(x);
newSet.Add(subSet[k]);
}
nums.Insert(i, x);
}
return newSet;
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/48731289