Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,5 @@
|
|||
def lessThan1(a: List[Int], b: List[Int]): Boolean =
|
||||
if (b.isEmpty) false
|
||||
else if (a.isEmpty) true
|
||||
else if (a.head != b.head) a.head < b.head
|
||||
else lessThan1(a.tail, b.tail)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
def lessThan2(a: List[Int], b: List[Int]): Boolean = (a, b) match {
|
||||
case (_, Nil) => false
|
||||
case (Nil, _) => true
|
||||
case (a :: _, b :: _) if a != b => a < b
|
||||
case _ => lessThan2(a.tail, b.tail)
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
def lessThan3(a: List[Int], b: List[Int]): Boolean =
|
||||
a.zipAll(b, Integer.MIN_VALUE, Integer.MIN_VALUE)
|
||||
.find{case (a, b) => a != b}
|
||||
.map{case (a, b) => a < b}
|
||||
.getOrElse(false)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
val tests = List(
|
||||
(List(1, 2, 3), List(1, 2, 3)) -> false,
|
||||
(List(3, 2, 1), List(3, 2, 1)) -> false,
|
||||
(List(1, 2, 3), List(3, 2, 1)) -> true,
|
||||
(List(3, 2, 1), List(1, 2, 3)) -> false,
|
||||
(List(1, 2), List(1, 2, 3)) -> true,
|
||||
(List(1, 2, 3), List(1, 2)) -> false
|
||||
)
|
||||
|
||||
tests.foreach{case test @ ((a, b), c) =>
|
||||
assert(lessThan1(a, b) == c, test)
|
||||
assert(lessThan2(a, b) == c, test)
|
||||
assert(lessThan3(a, b) == c, test)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue