Your code iterates through an array of arrays. But then you get the next array, repeat its numbers, but try to compare each of these numbers with the current set.
Assuming you have an NSArray objects, you can do this:
- (NSArray *)getDisjointedSets:(NSArray *)sets { NSMutableArray *resultSet = [NSMutableArray array]; for (NSArray *arrayA in sets) { BOOL noMatch = YES; for (NSArray *arrayB in sets) {
Test code:
NSArray *sets = @[ @[ @0, @4, @9 ], @[ @3, @4, @5 ], @[ @6, @7, @8 ] ]; NSArray *result = [self getDisjointedSets:sets]; NSLog(@"results = %@", result);
source share