-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_pointer.cpp
61 lines (53 loc) · 1.48 KB
/
3_pointer.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
// Author : Shankar Balajee Sambasivam
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <iomanip>
#include <fstream>
using namespace std;
/* CODE BEGINS HERE */
class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
sort(nums.begin(),nums.end());
int n=nums.size();
vector<vector<int>> V;
for(int i1=0;i1<n-2;i1++)
{
if(i1>0 and n>1 and nums[i1]==nums[i1-1])
{
continue;
}
else
{
int i2=i1+1;
int i3=n-1;
while(i3>i2)
{
if(nums[i1]+nums[i2]+nums[i3]==0)
{
vector<int> temp;
temp.push_back(nums[i1]);
temp.push_back(nums[i2]);
temp.push_back(nums[i3]);
V.push_back(temp);
i3--;
}
else if(nums[i1]+nums[i2]+nums[i3]<0)
{
i2++;
}
else
{
i3--;
}
}
}
}
return V;
}
};