- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// NSMutableArray *integerArray = [NSMutableArray arrayWithArray:@[@0,@2,@3,@4,@5,@6,@7,@9]];
NSMutableArray *integerArray = [NSMutableArray arrayWithArray:@[@2,@7,@11,@5]];
NSInteger target = 9;
NSMutableArray *resultIndexArray = [NSMutableArray arrayWithCapacity:1];
TICK(resultIndexArray)
for (NSInteger i = 0; i < integerArray.count; i ++) {
NSInteger pre = [[integerArray objectAtIndex:i] integerValue];
for (NSInteger j = (i + 1); j < (integerArray.count); j ++) {
NSInteger next = [[integerArray objectAtIndex:j] integerValue];
if ((pre + next) == target) {
[resultIndexArray addObject:[NSArray arrayWithObjects:@(i),@(j), nil]];
}
}
}
TOCK(resultIndexArray)
NSLog(@"resultIndexArray : %@",resultIndexArray);
}
近期评论