-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0046-Permutations.cs
More file actions
39 lines (33 loc) · 936 Bytes
/
Copy path0046-Permutations.cs
File metadata and controls
39 lines (33 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._0046.Permutations
{
public class _0046_Permutations
{
IList<IList<int>> res = new List<IList<int>>();
public IList<IList<int>> Permute(int[] nums)
{
var list = new List<int>();
backtrack(list, nums);
return res;
}
private void backtrack(List<int> list, int[] nums)
{
List<int> temp = null;
if (list.Count != nums.Length)
{
for (int i = 0; i < nums.Length; i++)
{
if (!list.Contains(nums[i]))
{
temp = new List<int>(list);
temp.Add(nums[i]);
backtrack(temp, nums);
}
}
}
else res.Add(list);
}
}
}