34 lines
827 B
C++
34 lines
827 B
C++
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
class Solution{
|
|
public:
|
|
int countPairs(vector<int>& nums, int target){
|
|
const int array_length = 60;
|
|
const int nums_length = nums.size();
|
|
int sums[array_length][array_length];
|
|
int rlt = 0;
|
|
for(int i = 0 ; i < nums_length;i++){
|
|
for(int j = i + 1; j < nums_length; j++){
|
|
if(nums[i]+nums[j] < target){
|
|
rlt++;
|
|
}
|
|
}
|
|
}
|
|
return rlt;
|
|
}
|
|
};
|
|
|
|
int main(){
|
|
Solution example;
|
|
int target = 0;
|
|
vector<int> ex1 = {-1,1,2,3,1};
|
|
target = 2;
|
|
cout<<example.countPairs(ex1,target)<<endl;
|
|
vector<int> ex2 = {-6,2,5,-2,-7,-1,3};
|
|
target = -2;
|
|
cout<<example.countPairs(ex2,target)<<endl;
|
|
|
|
|
|
return 0;
|
|
} |