我想做的是在下面的评论中描述。我该怎么办,高效?

using System;
using System.Collections.Generic;
using System.IO;
class Solution {
    static void Main(String[] args) {
        int n = Int32.Parse(Console.ReadLine());
        bool[][] flags = new bool[26][n]; // I want this to be a 26 x n array of false values
        for(int k = 0; k < n; ++k)
        {
            string line = Console.WriteLine();
            for(int i = 0; i < line.Length; ++i)
                flags[(int)line[i] - (int)'a'] = true;
        }
        int gems = flags.Count(arr => arr.Count(j => j == true) == arr.Length);
        Console.WriteLine
    }
}

最佳答案

看起来您混淆了Multidimensional数组和Jagged Array(数组数组)。
如果你正在寻找二维阵列,你可以简单地这样做。

bool[,] flags = new bool[26,n];
//or
bool[,] flags = new bool[,];
bool[,] flags = new bool[26,];

如果是锯齿形阵列,你可以这样做。
bool[][] flags1 = new bool[26][];
flags1[0] = new bool[n];  // since you want n elements
flags1[1] = new bool[n];
...

// initialization
flags1[0] = new bool[] {true, false};
flags1[1] = new bool[] {false};

10-04 22:00
查看更多