using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型一维数组 * @return int整型二维数组 */ public List<List<int>> permute (List<int> num) { // write code here if (num == null || num.Count == 0) return null; List<List<int>> lslsN = new List<List<int>>(); List<int> lsN = null; DG(num, ref lslsN, ref lsN); return lslsN; } public static void DG(List<int> num, ref List<List<int>> lslsN, ref List<int> lsN) { if (lsN == null) lsN = new List<int>(); if (num.Count == 0) { lslsN.Add(lsN); return; } for (int nIndex = 0; nIndex < num.Count; nIndex++) { List<int> numCpy = new List<int>(); numCpy.AddRange(num); List<int> lsCpy = new List<int>(); lsCpy.AddRange(lsN); lsCpy.Add(numCpy[nIndex]); numCpy.RemoveAt(nIndex); DG(numCpy, ref lslsN, ref lsCpy); } } }