/*
给你一个字符串数组,找出他们所有存在两个或者两个以上相同的字符串
例如数组[@"a",@"b",@"c",@"a"],那么找出的应该是[@"a"]
(提示:给的数组个数可能非常大,请注意算法效率).请编程
NSMutableDictionary *metadic = [NSMutableDictionary dictionary];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
for (NSString *sting in stringAry) {
if (![metadic valueForKey:sting]) {
[metadic setValue:@"1" forKey:sting];
}else{
[dic setValue:@"1" forKey:sting];
}
}
DebugLog(@"dic.allKeys: %@ - metadic.allKeys: %@", dic.allKeys, metadic.allKeys);
给你一个字符串数组,找出他们所有存在两个或者两个以上相同的字符串
例如数组[@"a",@"b",@"c",@"a"],那么找出的应该是[@"a"]
(提示:给的数组个数可能非常大,请注意算法效率).请编程
*/
NSMutableDictionary *metadic = [NSMutableDictionary dictionary];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
for (NSString *sting in stringAry) {
if (![metadic valueForKey:sting]) {
[metadic setValue:@"1" forKey:sting];
}else{
[dic setValue:@"1" forKey:sting];
}
}
DebugLog(@"dic.allKeys: %@ - metadic.allKeys: %@", dic.allKeys, metadic.allKeys);
输出信息: {
dic.allKeys: (
a,
d
) - metadic.allKeys: (
d,
b,
e,
c,
a
)
}