Objective-C PrefixSet Codility. 100% .
, ? ( c).
:
, , , .
, , , . , , indexOftheLastPrefix .
It uses only one cycle, so it takes only one pass. Objective-C code is very quiet, so I would like to hear any tricks to make it faster. However, he got 100% for the performance.
int solution(NSMutableArray *A)
{
NSUInteger arraySize = [A count];
NSUInteger indexOflastPrefix=0;
NSMutableDictionary *myDict = [[NSMutableDictionary alloc] init];
for (int i=0; i<arraySize; i++)
{
if ([myDict objectForKey:[[A objectAtIndex:i]stringValue]])
{
}
else
{
[myDict setValue:@"YES" forKey:[[A objectAtIndex:i]stringValue]];
indexOflastPrefix = i;
}
}
return indexOflastPrefix;
}
user440096
source
share