Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mergeMatch(limit: Int)(a: Seq[Int], b: Seq[Int]): Int = {
- def mergeRec(limit: Int, a: Seq[Int], b: Seq[Int], acc: Int): Int = {
- (a,b) match {
- case (_, Nil) | (Nil, _) => acc
- case (x +: xs, y +: ys) => if(Math.abs(x-y) < limit) mergeRec(limit, xs, ys, acc+1) else {
- if(x < y) mergeRec(limit, xs, y +: ys, acc)
- else mergeRec(limit, x +: xs, ys, acc)
- }
- }
- }
- mergeRec(limit, a, b, 0)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement