如果N种字符出现次数相同,则返回第一个.

解决方案 »

  1.   

    人工哈希表:
            private char MaxFreqChar(string strNote)
            {
                int[] sol = new int[128];   //asc码0~127
                for (int i = 0; i < strNote.Length; i++)  //生成字符的频度数组
                {
                    sol[(int)strNote[i]]++;
                }
                int temp = 0;
                for (int i = 1; i < 128; i++)  //如果只统计字母可以限定asc的循环范围
                {
                    if (sol[i] > sol[temp])
                        temp = i;
                }
                return (char)temp;
            }
      

  2.   

    1 设置数据结构
    struct 或 class A
    {
    char ch;
    int Count;
    }2 设置链表List<A> AL3 遍历该字符串, 如果该字符在AL中不存在, 为AL添加一个新项A, 如果已存在, Count++;4 最后遍历AL, 看谁的Count最大
      

  3.   

    有汉字的话用unicode码散列。
    空间换时间是很常见的方法。看到标题里有"最佳方案"这几个字,我就以为字符串的长度是百万级的。
    如果很短的话3楼的方法就够了