Open zhaokuohaha opened 8 years ago
public class Solution
{
public IList<IList<int>> Permute(int[] nums)
{
List<IList<int>> res = new List<IList<int>>();
dfs(nums,res,new List<int>());
return res;
}
private void dfs(int[] nums, List<IList<int>> res, List<int> cur)
{
if(cur.Count == nums.Length)
{
res.Add(cur);
return;
}
for(int i=0; i<nums.Length; i++)
{
if (!cur.Contains(nums[i]))
{
var newList = new List<int>();
foreach(var item in cur)
{
newList.Add(item);
}
newList.Add(nums[i]);
dfs(nums, res, newList);
}
}
}
}
46-全排列: https://leetcode.com/problems/permutations/ 47-高阶全排列: https://leetcode.com/problems/permutations-ii/