Problem 06
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user