コード例 #1
0
 public static int[] BuildCharFrequencyTable(String phrase)
 {
     int[] table = new int[(int)char.GetNumericValue('z') - (int)char.GetNumericValue('a') + 1];
     foreach (char c in phrase.ToCharArray())
     {
         int x = CharExtension.GetCharNumber(c);
         if (x != -1)
         {
             table[x]++;
         }
     }
     return(table);
 }
コード例 #2
0
            public static bool IsPermutationOfPalindrome2(String phrase)
            {
                int countOdd = 0;

                int[] table = new int[(int)char.GetNumericValue('z') - (int)char.GetNumericValue('a') + 1];
                foreach (char c in phrase.ToCharArray())
                {
                    int x = CharExtension.GetCharNumber(c);
                    if (x != -1)
                    {
                        table[x]++;

                        if (table[x] % 2 == 1)
                        {
                            countOdd++;
                        }
                        else
                        {
                            countOdd--;
                        }
                    }
                }
                return(countOdd <= 1);
            }