forked from Andyy-18/CPP-BASICS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSArrayTripletsum.cpp
More file actions
32 lines (29 loc) · 828 Bytes
/
CSArrayTripletsum.cpp
File metadata and controls
32 lines (29 loc) · 828 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
25
26
27
28
29
30
31
32
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>> findTriplets(vector<int>arr, int n, int K) {
vector<vector<int>> ans;
for(int i = 0; i<arr.size(); i++){
for(int j = i+1; j<arr.size(); j++){
for(int l = j+1; l<arr.size(); l++){
if(arr[i] + arr[j] + arr[l] == K){
ans.push_back({arr[i],arr[j],arr[l]});
// i++;
// j++;
// l++;
}
else if(arr[i] + arr[j] + arr[l] < K){
i++;
j++;
}
else{
// j++;
// l++;
break;
}
}
}
}
return ans;
}
}