有两个这样的列表:
val listA=List("a","b","c","d")
val listB=List("a","b")
我想要像List一样的答案(" c"," d")
但是如果listB的顺序发生变化,那么输出应该是空列表,如下所示:
val listA=List("a","b","c","d")
val listB=List("a","c")
然后这应该导致空列表。
因此我想要ListA-ListB的结果,但应该处理顺序!
答案 0 :(得分:4)
考虑到您的测试用例有限,这似乎有效。
def remainder[T](a: Seq[T], b: Seq[T]): Seq[T] = {
val diff = a diff b
if (a containsSlice diff) diff else Seq()
}
可能会出现更严格和全面的测试用例。