字符串中出现次数最多的字符

    技术2025-11-02  13

    public static SortedList<char, int> fun(string str) { SortedList<char, int> slt = new SortedList<char, int>(); foreach (char item in str) { if (slt.ContainsKey(item)) slt[item]++; else slt.Add(item, 1); } int _max = slt.Max(p => p.Value); int count = slt.Count-1; for (int i = count; i >= 0; i--) { if (slt.Values[i] != _max) slt.RemoveAt(i); } return slt; }

    最新回复(0)