-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy path046-Permutations.cs
40 lines (36 loc) · 1.1 KB
/
046-Permutations.cs
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
40
//-----------------------------------------------------------------------------
// Runtime: 492ms
// Memory Usage:
// Link:
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _046_Permutations
{
public IList<IList<int>> Permute(int[] nums)
{
var result = new List<IList<int>>();
result.Add(nums);
int length = nums.Length;
int size, temp, i, j, k;
IList<int> tempList;
for (i = 0; i < length; i++)
{
size = result.Count;
for (j = 0; j < size; j++)
{
for (k = i + 1; k < length; k++)
{
tempList = new List<int>(result[j]);
temp = tempList[k];
tempList[k] = tempList[i];
tempList[i] = temp;
result.Add(tempList);
}
}
}
return result;
}
}
}