-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path24.cpp
More file actions
24 lines (23 loc) · 638 Bytes
/
Copy path24.cpp
File metadata and controls
24 lines (23 loc) · 638 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//https://practice.geeksforgeeks.org/problems/triplet-sum-in-array/0
//three sum (two pointer approach)
bool find3Numbers(int A[], int n, int X)
{
//Your Code Here
sort(A,A+n);
for(int i=0;i<n-2;i++){
int z=X-A[i];
if(z>=0){
int j=i+1,k=n-1;
while(j<k){
if(A[j]+A[k]>z){
k--;
}else if(A[j]+A[k]<z){
j++;
}else{
return true;
}
}
}
}
return false;
}