1. 字符串翻转
-(void)test2{
NSString *str = @"hello world";
NSArray *array = [str componentsSeparatedByString:@" "];
NSMutableString *dstStr = [NSMutableString string];
for (NSInteger idx = array.count - 1; idx >= 0 ; idx--) {
[dstStr appendFormat:@"%@ ",array[idx]];
}
NSLog(@"%@",dstStr);
}
2. 数组中第二大的数字
-(void)test3{
NSArray *array = @[@(1),@(51),@(11),@(0)];
array = [array sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [(NSNumber *)obj1 integerValue] <= [(NSNumber *)obj2 integerValue];
}];
NSLog(@"%@",array);
if (array.count >= 2) {
NSLog(@"第二大的数字为:%@",array[1]);
}
}