【发布时间】:2018-07-21 16:41:11
【问题描述】:
我有以下 Scala 代码:
object Solution {
def main(args: Array[String]) {
val List(n, m) = readLine().split(" ").map(_.toInt).toList;
val knowledge: List[Set[Int]] = (0 until n).map( _ => {
val knows: List[Char] = readLine().toList;
(0 until m).toSet.flatMap(topic: Int => {
knows(topic) match {
case '1' => Set(topic);
case _ => Set[Int].empty;
}
});
}).toList;
val teams: List[Int] = knowledge.grouped(2).map{ case(x, y) => x ++ y }.map(_.size);
val best: Int = teams.max;
val count = teams.filter(_ == max);
println(best + " " + count);
}
}
在它上面,我收到了这个错误:
Solution.scala:16: error: illegal start of declaration
knows(topic) match {Solution.scala:
在这一行:
knows(topic) match {
我不明白出了什么问题。
我在 flatMap 的正文中使用了 match。
知道这段代码有什么问题吗?
【问题讨论】:
标签: scala