public class Solution {
private IList<IList<int>> result = new List<IList<int>>();
private IList<int> path = new List<int>();
public IList<IList<int>> Combine(int n, int k) {
BackTracking(n,k,1);
return result;
}
public void BackTracking(int n, int k, int startIndex)
{
if(path.Count == k)
{
IList<int> tmp = new List<int>();
for(int i = 0;i <path.Count;i++)//不能直接result.Add(path)
{
tmp.Add(path[i]);
}
result.Add(tmp);
return;
}
for(int i = startIndex;i <=n;i++)
{
path.Add(i);
BackTracking(n,k,i+1);
path.RemoveAt(path.Count - 1);
}
}
}