2 of 2
it was not a right-fold
A left-fold is an elegant solution too:
class Node (children:List[Node], value:Int) {
def totalCost : Int = (value /: children) (_ + _.totalCost)
}
user unknown
- 618
- 5
- 16
default