Problem 06

This commit is contained in:
2026-03-19 15:39:17 +01:00
parent 79f245aaf4
commit 79fa83ef67
2 changed files with 42 additions and 0 deletions
@@ -0,0 +1,27 @@
package ninetyNineScalaProblems
import scala.annotation.tailrec
object Problem06:
def isPalindromeList(list: List[Any]): Boolean =
@tailrec
def loop(cursor: List[Any]): Boolean =
cursor match
case head :: Nil =>
true
case head :: tail =>
tail.reverse match
case e :: t if e == head =>
loop(t)
case e :: t =>
false
case Nil =>
false
case Nil =>
true
loop(list)
object Problem06Stdlib:
def isPalindromeList(list: List[Any]): Boolean =
list == list.reverse