Skip to content

Instantly share code, notes, and snippets.

@Zabaa
Created December 6, 2016 13:29
Show Gist options
  • Save Zabaa/dccac65e36c7a5d178f60a56feaa30e5 to your computer and use it in GitHub Desktop.
Save Zabaa/dccac65e36c7a5d178f60a56feaa30e5 to your computer and use it in GitHub Desktop.
public class Permutation
{
public static IEnumerable<string> GetPermutations(string s)
{
if (s.Length > 1)
return from ch in s
from permutation in GetPermutations(s.Remove(s.IndexOf(ch), 1))
select string.Format("{0}{1}", ch, permutation);
else
return new string[] { s };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment