【发布时间】:2018-01-02 18:48:44
【问题描述】:
我编写代码,检查字符串中的括号余额:
def balance(chars: List[Char]): Boolean = {
def scopes(chars: List[Char], s: Int): Boolean = {
if (chars.isEmpty)
if (s == 0) true
else false
else{
if (s < 0) return false
if (chars.head.toString == "(") scopes(chars.tail, s + 1)
if (chars.head.toString == ")") scopes(chars.tail, s - 1)
else scopes(chars.tail, s)
}
}
scopes(chars, 0)
}
balance("if zero? x( max / 1 x".toList)
但它工作错了。我只是找不到错误。需要帮助,请
【问题讨论】: