fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. String s = "God";
  8. String t = "dog";
  9.  
  10. // your code goes here
  11. Console.WriteLine(permutation(s, t));
  12. }
  13.  
  14. static bool permutation(String s, String t)
  15. {
  16. if (s.Length != t.Length) return false;
  17. for (int i = 0; i < s.Length; i++)
  18. {
  19. if (t.Contains(s[i]))
  20. {
  21. continue;
  22. }
  23. else
  24. {
  25. return false;
  26. }
  27. }
  28. return true;
  29. }
  30.  
  31. // static bool permutation(String s, String t)
  32. // {
  33. // if (s.Length != t.Length) return false;
  34. // return String.Equals(sort(s),sort(t));
  35. // }
  36.  
  37. // static bool permutation(String s, String t)
  38. // {
  39. // if (s.Length != t.Length) return false;
  40.  
  41. // int[] letters = new int[128];
  42.  
  43. // char[] s_array = s.ToCharArray();
  44. // foreach (char c in s_array)
  45. // letters[c]++;
  46.  
  47. // for (int i = 0; i < t.Length; i++)
  48. // {
  49. // int c = (int)t[i];
  50. // letters[c]--;
  51. // if (letters[c] < 0) return false;
  52. // }
  53.  
  54. // return true;
  55. // }
  56.  
  57. static String sort(String s)
  58. {
  59. char[] content = s.ToCharArray();
  60. Array.Sort(content);
  61. return new String(content);
  62. }
  63. }
Success #stdin #stdout 0.02s 16100KB
stdin
Standard input is empty
stdout
False