Given a collection of distinct numbers, return all possible permutations.
For example,
[1,2,3] have the following permutations:
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
排列组合问题。
思路:递归。通过将第一个数与后面的数依次交换,使每个数充当一次开头。然后进行下一轮从第二个数开始的递归……..
还是因为IList<IList<int>>
不会初始化而改用List<List<int>>
导致无法AC的问题。。但结果是正确的。
public class Solution {
public IList<List<int>> Permute(int[] nums)
{
IList<List<int>> ret = new List<List<int>>();
PermutationHelper(ret, nums, 0);
//IList<IList<int>> res = new ArrayList(ret);
return ret;
}