Algorithm to find if two sets intersect

后端 未结 7 1804
一向
一向 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-01 23:59

    Glomek is on the right track, but kinda glossed over the algorithm.

    Start by comparing ArrayA[0] to ArrayB[0]. if they are equal, you're done. If ArrayA[0] is less than ArrayB[0], then move to ArrayA[1]. If ArrayA[0] is more than ArrayB[0], then move to ArrayB[1].

    Keeping stepping through till you reach the end of one array or find a match.

提交回复
热议问题