- (NSString *)secondMaxItem:(NSArray *)ary { int max=[ary[0] intValue]; int secondmax=[ary[1] intValue]; max=[ary[0] intValue]>[ary[1] intValue]?[ary[0] intValue]:[ary[1] intValue]; secondmax=[ary[0] intValue]>[ary[1] intValue]?[ary[1] intValue]:[ary[0] intValue]; for (NSUInteger i=2; i<=ary.count-1; i++) { if ([ary[i] intValue]>max) { secondmax=max; max=[ary[i] intValue]; } else if([ary[i] intValue]>secondmax) { secondmax=[ary[i] intValue]; } } return [NSString stringWithFormat:@"%d",secondmax]; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-28 15:05:13