Fastest way to check if an array contains the same objects of another array

后端 未结 10 1841
夕颜
夕颜 2020-12-29 04:36

The goal is to compare two arrays as and check if they contain the same objects (as fast as possible - there are lots of objects in the arrays). The arrays cannot be checked

10条回答
  •  被撕碎了的回忆
    2020-12-29 05:07

    How about converting both arrays to sets and comparing them.

    NSSet *set1 = [NSSet setWithArray:arr1];
    NSSet *set2 = [NSSet setWithArray:arr2];
    

    Compare the two using

    if([set1 isEqualToSet:set2]) {
    
    }
    

提交回复
热议问题