iOS 快速查找数组中长度最长的字符串

iOS 快速查找数组中长度最长的字符串

- (NSString *)findArrMaxLengthOfStringArr:(NSArray *)arr {
    NSMutableDictionary *lengthDic = [NSMutableDictionary dictionary];
    NSMutableArray *strLengthArr = [NSMutableArray array];
    NSInteger length = 0;
    for (int i = 0; i < arr.count; i++) {
        NSString *iStr = arr[i];
        [lengthDic setObject:iStr forKey:@(iStr.length)];
        [strLengthArr addObject:@(iStr.length)];
    }
    NSInteger max = [[strLengthArr valueForKeyPath:@"@max.floatValue"] integerValue];
    NSString *value = [lengthDic objectForKey:@(max)];
    return value;
}

你可能感兴趣的:(iOS 快速查找数组中长度最长的字符串)