how to remove sub list

后端 未结 3 2000
别那么骄傲
别那么骄傲 2021-01-21 00:22

How can I remove all occurrences of a sublist from a list, eg

List(1, 2, 3, 4, 5, 6, 7, 4, 8, 9, 10, 5).removeSubList(4, 5)

should remove all o

3条回答
  •  再見小時候
    2021-01-21 00:44

    Using Tzach Zohar idea with different implementation:

    def removeSubList[T](list: List[T], sublist: List[T]): List[T] =
        if (list.containsSlice(sublist)) 
            removeSubList(list.diff(sublist), sublist)
        else list
    

提交回复
热议问题