【发布时间】:2016-12-09 23:55:19
【问题描述】:
下面的评论中描述了我想要做的事情。我该怎么做,高效?
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
}
}
【问题讨论】:
-
数组已经初始化为所有
false。它是语言规范的一部分。详情请见stackoverflow.com/a/15300089/56778。 -
如果你想让所有的值都为假,为什么要设置它们为真?
标签: c# .net arrays algorithm data-structures