Problem 10
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package ninetyNineScalaProblems
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
object Problem10:
|
||||
def runLengthEncode(list: List[Any]): List[Tuple2[Int, Any]] =
|
||||
@tailrec
|
||||
def loop(cursor: List[List[Any]], acc: List[Tuple2[Int, Any]]): List[Tuple2[Int, Any]] =
|
||||
cursor match
|
||||
case d :: tail =>
|
||||
loop(tail, (d.length, d(0)) :: acc)
|
||||
case Nil =>
|
||||
acc
|
||||
|
||||
loop(Problem09.consecutiveDuplicatesIntoSublists(list), List()).reverse
|
||||
Reference in New Issue
Block a user