-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy path4sum.cpp
40 lines (31 loc) · 820 Bytes
/
4sum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Solution {
public:
vector<vector<int>> fourSum(vector<int>& nums, int target)
{
sort(nums.begin(),nums.end());
int n=nums.size();
int i,j,k;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
int j1=0,j2=n-1;
while(j1<j2)
{
int sum=nums[i]+nums[j]+nums[j1]+nums[j2];
if(j1==i||j1==j)
{
j1++;
}
else if(j2==i||j2==j)
{
j2--;
}
else if(sum>target)
{
}
}
}
}
}
};