Algorithm to tell if two arrays have identical members

前端 未结 16 3002
渐次进展
渐次进展 2020-11-29 06:52

What\'s the best algorithm for comparing two arrays to see if they have the same members?

Assume there are no duplicates, the members can be in any order, and that n

16条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 07:12

    I would suggest using a sort first and sort both first. Then you will compare the first element of each array then the second and so on.

    If you find a mismatch you can stop.

提交回复
热议问题