【发布时间】:2016-02-19 05:29:26
【问题描述】:
警告 - 这是处理 Codility BinaryGap 任务的代码 - 只是为了警告,因为这可能会破坏某些人。
我有一段代码,比如
@tailrec
def count2(max:Int, count:Int, d:Seq[Char]):Int = d match {
case '1' :: s => count2(Math.max(max, count), 0, s)
case '0' :: s => count2(max, count+1, s);
case Nil => max
}
我这样称呼它
println(Solution.count2(0, 0, Seq('1', '0')))
println(Solution.count2(0, 0, "10"))
它可以编译,但是第二个调用不起作用 - 抛出“Match not found 10”我不明白为什么。有一个similar question around that topic 声明,需要显式转换。但是,我觉得我确实有一个方法参数类型的形式。 调试器清楚地指出 d 变量的类型是 WrappedString - 它应该可以完成这项工作。但显然,它没有。
这是怎么回事?
【问题讨论】:
标签: scala