Last active
December 4, 2016 03:49
-
-
Save wkimeria/7e9bc1d7e66f578abe958e457c5d2038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hasSubsequence[A](sup: List[A], sub: List[A]): Boolean = { | |
def loop[A](supRev: List[A], subRev: List[A], isSubSequence: Boolean): Boolean = supRev match { | |
case Nil => { | |
subRev match { | |
case Nil => isSubSequence | |
case _ => false | |
} | |
} | |
case Cons(x,xs) => subRev match { | |
case Nil => isSubSequence | |
case Cons(x2, xs2) => { | |
if(x == x2) loop(xs, xs2, true) | |
else loop(xs, subRev, false) | |
} | |
} | |
} | |
loop(sup, sub, false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment