

























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;
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。