Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Permute
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here var sln = new solution(); List<List<int>> permutes= sln.Permute(new int [] {1,2,3,4}); foreach( var list in permutes) { foreach(var num in list){ Console.Write(num + ""); } Console.WriteLine(); } } } public class solution { public List<List<int>> Permute(int[] nums) { var pLists = new List<List<int>> (); permuteRecursive(0, nums, ref pLists); return pLists; } private void permuteRecursive(int beg, int[] nums , ref List<List<int>> pLists) { if( beg == nums.Length) { pLists.Add(nums.ToList()); return; } for(int i = beg ; i < nums .Length ; i++) { Swap(ref nums , beg , i); permuteRecursive(beg + 1, nums, ref pLists); Swap(ref nums , beg , i); } } private void Swap( ref int[] nums, int pos1, int pos2){ var temp = nums[pos1]; nums[pos1] = nums[pos2]; nums[pos2] = temp; return ; } } }
run
|
edit
|
history
|
help
0
Rextester
asxsdxasd sd
random number generator using array
D12
Basma-1
Yoo
jjj4
code for part 4 gogoaim
单链表
test