給一個有序數(shù)組和一個目標值咳短,找到數(shù)組中有多少對它們的總和大于特定目標數(shù)。請返回成對數(shù)纽竣。
Example
numbers=[2, 7, 11, 15], target=24
return 1
- (NSInteger)getArray:(NSArray<NSString *> *)array target:(NSInteger)target {
NSInteger count = 0;
NSInteger left = 0;
NSInteger right = array.count - 1;
while (left < right) {
if ([array[left] integerValue] + [array[right] integerValue] > target) {
count += (right - left);
right--;
} else {
left++;
}
}
return count
}