What is the cost of ContainsAll in Java?

前端 未结 4 1817
南旧
南旧 2021-01-15 03:15

I discovered containsAll() (a List interface method) during some coding today, and it looks pretty slick. Does anyone know how much this costs in

4条回答
  •  温柔的废话
    2021-01-15 04:01

    consider

    n.ContainsAll(m)

    the best possible case scenario is O(m), and that's if n is a perfect hash set.

    considering unsorted lists, i can come up with an O(n*log(n) + m*log(m)) algorithm

提交回复
热议问题