小编ami*_*ari的帖子

我想在整数数组的连续子集中找到公共数字的最大频率

数组A的部分数字子序列是整数的子序列,其中每个连续的整数至少有一个共同的数字

我保留一个包含0到9个字符的字典以及每个后续字符的计数.然后我循环遍历整数数组中的所有值并取每个数字并检查我的字典中该数字的计数.

public static void Main(string[] args)
{
    Dictionary<char, int> dct = new Dictionary<char, int>
    {
        { '0', 0 },
        { '1', 0 },
        { '2', 0 },
        { '3', 0 },
        { '4', 0 },
        { '5', 0 },
        { '6', 0 },
        { '7', 0 },
        { '8', 0 },
        { '9', 0 }
    };

    string[] arr = Console.ReadLine().Split(' ');
    for (int i = 0; i < arr.Length; i++)
    {
        string str = string.Join("", arr[i].Distinct());
        for (int j …
Run Code Online (Sandbox Code Playgroud)

c# arrays algorithm dynamic data-structures

3
推荐指数
1
解决办法
426
查看次数

标签 统计

algorithm ×1

arrays ×1

c# ×1

data-structures ×1

dynamic ×1