Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // e.g. TEST, TeST, TEsT, TESt, tEST, etc.
  2. public static List<string> Permute(string s)
  3. {
  4. List<string> listPermutations = new List<string>();
  5.  
  6. char[] array = s.ToLower().ToCharArray();
  7. int iterations = (1 << array.Length) - 1;
  8.  
  9. for (int i = 0; i <= iterations; i++)
  10. {
  11. for (int j = 0; j < array.Length; j++)
  12. array[j] = (i & (1 << j)) != 0
  13. ? char.ToUpper(array[j])
  14. : char.ToLower(array[j]);
  15. listPermutations.Add(new string(array));
  16. }
  17. return listPermutations;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement