Skip to content

Instantly share code, notes, and snippets.

@vinitshahdeo
Created September 14, 2018 21:25
Show Gist options
  • Save vinitshahdeo/1a25e1080a8bc4ab0fee0c0b61771ed5 to your computer and use it in GitHub Desktop.
Save vinitshahdeo/1a25e1080a8bc4ab0fee0c0b61771ed5 to your computer and use it in GitHub Desktop.
LeetCode Problems
class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
set<vector<int> > st;
sort(num.begin(), num.end());
int i, j, k;
int n = num.size();
for (i = 0; i < n - 2; i++) {
j = i+1;
k = n-1;
while (j < k) {
int sum = num[i] + num[j] + num[k];
if (sum == 0) {
vector<int> v;
v[0] = num[i];
v[1] = num[j];
v[2] = num[k];
rs.insert(v);
j++;
k--;
} else if (sum > 0) {
k--;
} else if (sum < 0) {
j++;
}
}
}
vector<vector <int> >result (st.begin(), st.end());
return result;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment