using System; class Program { static void Main() { Console.WriteLine(AreAnagrams("CCAA", "CAAC")); Console.WriteLine(AreAnagrams("CARE", "RACE")); } static bool AreAnagrams(string str1, string str2) { if (str1.Length!= str2.Length) return false; int[] charCount1 = new int[26]; int[] charCount2 = new int[26]; for (int i = 0; i < str1.Length; i++) { charCount1[str1[i] - 'A']++; charCount2[str2[i] - 'A']++; } for (int i = 0; i < 26; i++) { if (charCount1[i]!= charCount2[i]) return false; } return true; } }
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!