I need to find duplicated numbers (that appear 2 or more times) in array how can I do it without using NSCountedSet?
This is a solution I did:
NSCountedSet *countedSet = [NSCountedSet setWithArray:array];
__block NSUInteger totalNumberOfDuplicates = 0;
[countedSet enumerateObjectsUsingBlock:^(id obj, BOOL *stop)
{
NSUInteger duplicateCountForObject = [countedSet countForObject:obj];
if (duplicateCountForObject > 1)
totalNumberOfDuplicates += duplicateCountForObject;
NSLog(@"%@ appears %ld times", obj, duplicateCountForObject);
}];
This is a solution that can be achieved using Swift, but you can use any language to achieve this result: