Algorithm to find if two sets intersect

后端 未结 7 1690
一向
一向 2021-01-01 23:22

Let\'s say I have two arrays:

int ArrayA[] = {5, 17, 150, 230, 285};

int ArrayB[] = {7, 11, 57, 110, 230, 250};

Both arrays a

相关标签:
7条回答
  • 2021-01-02 00:10

    If the range of values is small, you could build a lookup table for one of them (time cost = O(N)) and then check if the bit is set from the other list (time cost = O(N)). If the range is large, you could do something similar with a hash table.

    The mergesort trick from Glomek is an even better idea.

    0 讨论(0)
提交回复
热议问题