算法复杂度:O(M+N)
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSArray *list = [NSArray arrayWithObjects:@"8",@"3",@"5",@"2",@"5", nil];
NSMutableArray *save = [NSMutableArray arrayWithCapacity:10];
for (NSInteger i = 0; i < 10; i++) {
save[i] = @(0);
}
for (NSInteger i = 0; i < 5; i++) {
NSInteger rl = ((NSString*)list[i]).integerValue;
NSInteger result = ((NSNumber *)save[rl]).integerValue;
result += 1;
save[rl] = @(result);
}
NSLog(@"排序:");
for (NSInteger i = 9; i >= 0; i--) {
NSInteger count = ((NSNumber *)save[i]).integerValue;
while (count > 0) {
NSLog(@"%ld", (long)i);
count --;
}
}
}
return 0;
}