-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThree_sum_problem.cpp
More file actions
48 lines (44 loc) · 1.02 KB
/
Three_sum_problem.cpp
File metadata and controls
48 lines (44 loc) · 1.02 KB
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
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=6;
//cin>>n;
int target=24;
//cin>>target;
bool found=false;
vector<int> a={12,3,6,9,34,25};
/*for(auto &i:a)
{
cin>>i;
}*/
sort(a.begin(),a.end());
for(int i=0;i<n;i++)
{
int low=i+1; int high= (n-1);
while(low<high)
{
int current=a[i]+a[low]+a[high];
if(current==target)
{
found=true;
break;
}
else if(current>target)
{
high--;
}
else if(current<target)
{
low++;
}
}
}
if(found)
{
cout<<"True";
}
else{
cout<<"False";
}
}