id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> v;\n vector<vector<int>> v1;\n vector<int> va, vb;\n set<int> sa, sb;\n sort(nums.begin(), nums.end());\n for(int i = 0; i < nums.size(); i++){\n if(nums[... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> resSet;\n unordered_map<int,unordered_set<int>> third;\n int zcount = 0;\n for(int i= 0; i< nums.size(); i++){\n if(nums[i] == 0) zcount++;\n third[-nums[i]]... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <cassert>\n#include <compare>\n#include <ranges>\n#include <span>\n#include <unordered_set>\n#include <utility>\n#include <vector>\n\nstruct addends {\n int n0, n1, n2;\n bool operator==(addends const&) const noexcept = default;\n std::strong_ordering operator<=>(addends const&) const noe... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& a) {\n int n = a.size();\n sort(a.begin(), a.end());\n auto two_pointers = [&](int l, int r, int target) {\n vector<tuple<int,int>> v;\n while (r > l) {\n if (a[l] + a[r] == ta... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n // int cols=3;\n\n // vector<int> column(cols, 0);\n // Create an empty 2D vector\n std::vector<std::vector<int>> matrix;\n std::sort(nums.begin(), nums.end());\n // std::vector<int>... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> trip;\n sort(begin(nums), end(nums));\n if (nums[0] == nums[nums.size() - 1]) {\n if (nums[0] == 0) {\n return {{0,0,0}};\n }\n return {};... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n if (all_of(nums.begin(), nums.end(), [](int i) { return i == 0; }))\n return {{0, 0, 0}};\n sort(nums.begin(), nums.end());\n vector<vector<int>> threeSums;\n int arraySize = nums.size(... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n if (all_of(nums.begin(), nums.end(), [](int i) { return i == 0; }))\n return {{0, 0, 0}};\n sort(nums.begin(), nums.end());\n vector<vector<int>> threeSums;\n int arraySize = nums.size(... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n vector<vector<int>> ans;\n if(nums[0]==0 && nums[nums.size()-1]==0) {\n ans.push_back({0, 0, 0});\n return ans;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> answer;\n std::map<int, int> locations;\n std::map<vector<int>, int> test;\n //std::sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size(); i++) {\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n set<vector<int>> ans;\n int j,k;\n if(nums[0] == 0 && nums[n-1] == 0)\n {\n return {{0,0,0}};\n }\n f... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n \n set<vector<int>> st;\n int n = nums.size();\n vector<int> temp;\n vector<vector<int>> ans;\n sort(nums.begin() , nums.end());\n if(nums[0] == nums[n-1] && nums[0] == 0){\... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cout.tie(NULL);\n cin.tie(NULL);\n\n int n = nums.size();\n set<vector<int>> set_store;\n unordered_map<int, int> count;\n for(auto i:nums)... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cout.tie(NULL);\n cin.tie(NULL);\n\n int n = nums.size();\n set<vector<int>> set_store;\n unordered_map<int, int> count;\n for(auto i:nums)... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n // int find_index(vector<int> v, int index1, int index2)\n // {\n // int elem = -(v[index1] + v[index2]);\n // int start = 0, end = int(v.size()) -1 ;\n // while(start <= end)\n // {\n // int mid = (start + end)/2;\n // if(... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int size = nums.size();\n sort(nums.begin(), nums.end());\n\n if(size<3)\n return {{}};\n \n if(nums[0] == nums[size-1] && nums[0] == 0)\n return {{nums[0], nums[0], n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n \n if(nums.size()<3) return {};\n \n sort(nums.begin(), nums.end());\n int n = nums.size();\n \n if(nums.front() == 0 && nums.back() ==0) return vector<vector<int>>(1, vector<... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n // vector<int> twosum(int i,vector<int>&nums){\n // int sum = -nums[i];\n // for(;i<s;i++){\n\n // }\n // }\n\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> res;\n set<vector<int>>gabbu;\n int n = nums... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\n typedef vector<int> triple;\n\npublic:\n vector<vector<int>> threeSum(vector<int>& nums_in) {\n auto nums = nums_in;\n set<vector<int>> solutionsSet;\n vector<set<int>> sub_solutions;\n auto const nums_count = nums.size();\n vector<vector<int>> so... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> retset={};\n std::sort(std::begin(nums),std::end(nums));\n // auto middle=std::begin(nums)+nums.size()/2;\n auto left=std::begin(nums);\n bool loopcondition=true;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int target = 0;\n sort(nums.begin(), nums.end());\n int n = nums.size();\n set<vector<int>> ansSet;\n vector<vector<int>> ansVector;\n for(int i=0;i<n;i++) {\n int sumNeed... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <bits/stdc++.h>\ntemplate <typename T> using vt = vector<T>;\ntypedef uint32_t u32;\n\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vt<vt<int>> ans;\n \n sort(nums.begin(), nums.end());\n \n u32 n = nums.size();\n\n u32 co... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n std::vector<std::vector<int>> res;\n std::sort(nums.begin(), nums.end());\n for(size_t i = 0; i < nums.size(); ++i){\n int target = -nums[i];\n int l = i + 1;\n int r = n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n\n /* question says order is not important but the API says order is important. thats why this line: */\n \n\n std::vector<std::vector<int>> result;\n std::map<std::string,std::vector<int>> r;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n\n /* question says order is not important but the API says order is important. thats why this line: */\n \n\n std::vector<std::vector<int>> result;\n std::map<std::string,std::vector<int>> r;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int i = 0;\n int j = nums.size() - 1;\n sort(nums.begin(),nums.end());\n vector<vector<int>> res;\n while(i<j-1){\n int tmp = 0 - nums[i];\n int k = i + 1;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n set<vector<int>> triplets;\n int p1, p2, p3, sum;\n for(int i=0; i<nums.size()-2; i++) {\n p1 = i;\n sum = nums[p1];\n p2 = p1+1;... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n \n set<vector<int>> uniqueTriplets;\n for(int i = 0;i<nums.size();i++){\n int m = i+1,n=nums.size()-1;\n \n while(m<n){\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n vector<vector<int>> final;\n set<vector<int>> s;\n for(int i=0 ; i< nums.size(); ++i){\n \n int val = -nums[i];\n cout<<va... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n struct CompareByFirstElement {\n bool operator() (const std::tuple<int, int>& a, const std::tuple<int, int>& b) const {\n return std::get<0>(a) < std::get<0>(b);\n}\n };\n vector<vector<int>> threeSum(vector<int>& nums) {\n std::vector<std::tuple<int, int>>... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n=nums.size();\n vector<vector<int>>ans;\n set<vector<int>>ans1;\n if(nums.empty()||n<3){\n return ans;\n }\n sort(nums.begin(),nums.end());\n for(int i=0;i<n-2... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums)\n {\n vector<vector<int>> out;\n sort(nums.begin(), nums.end());\n\n for (int i = nums.size()-1; i >= 2; i--)\n {\n vector<vector<int>> ret = twoSum(nums, i);\n out.insert(out... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n \n void merge(vector<int> &nums,int s, int mid, int e){\n vector<int> n1(mid-s+1);\n vector<int> n2(e-mid);\n for(int i=0;i<=mid-s;i++)\n {\n n1[i]=nums[s+i];\n }\n \n for(int j=0;j<e-mid;j++){\n n2[j]=... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n \n void merge(vector<int> &nums,int s, int mid, int e){\n vector<int> n1(mid-s+1);\n vector<int> n2(e-mid);\n for(int i=0;i<=mid-s;i++)\n {\n n1[i]=nums[s+i];\n }\n \n for(int j=0;j<e-mid;j++){\n n2[j]=... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> result;\n\n sort(nums.begin(), nums.end());\n\n int sum = 0;\n\n for(int i : nums){\n if(i != 0){\n sum = 1;\n break;\n }\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> result;\n sort(nums.begin(), nums.end());\n \n for (int i = 0; i < nums.size() - 2; i++) {\n auto twoSumList = twoSum(nums, i + 1, -nums[i]);\n for (auto lis... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>>ans;\n vector<int>mp(2000000);\n vector<int>v;\n for(auto i:nums) {\n mp[i + 200000]++;\n if(mp[i + 200000] == 1)\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>>ans;\n vector<int>mp(2000000);\n vector<int>v;\n for(auto i:nums) {\n mp[i + 200000]++;\n if(mp[i + 200000] == 1)\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> res;\n sort(nums.begin(), nums.end());\n\n int n = nums.size();\n unordered_map<int, bool> map;\n for(int i = n-1; i >= 2; i--)\n {\n if (nums[i] < 0) ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> res;\n sort(nums.begin(), nums.end());\n\n int n = nums.size();\n unordered_map<int, bool> map;\n for(int i = n-1; i >= 2; i--)\n {\n if (nums[i] < 0) ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<int> targetSum(vector<int>& nums, int i, int n, int target) {\n vector<int> ans;\n while (i<n){\n int sum = nums[i]+nums[n];\n if(sum==target){\n ans.push_back(nums[i]);\n ans.push_back(nums[n]);\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n set<vector<int>> ans;\n\n sort(nums.begin(), nums.end());\n int zero_idx = lower_bound(nums.begin(), nums.end(), 0) - nums.begin();\n int pos_idx = upper_bound(nums.... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n set<vector<int>> ans;\n\n sort(nums.begin(), nums.end());\n int zero_idx = lower_bound(nums.begin(), nums.end(), 0) - nums.begin();\n int pos_idx = upper_bound(nums.... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, int>> twoSum(vector<int> &nums, int target, int start, map<int, int> &mp)\n {\n vector<pair<int, int>> ans;\n for(int i=start; i<nums.size(); i++)\n {\n if(mp.find(target - nums[i]) != mp.end() && mp[target - nums[i]] > i)\n... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n void twoSum(vector<vector<int>> & ans, vector<int> & v, int r, int tgt) {\n if (tgt < v[0] + v[1] || v[r - 1] + v[r] < tgt) return;\n unordered_map<int, int> mp;\n for (int i = r; i >= 0; --i) {\n mp[v[i]] = i;\n }\n int pre = INT... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n\n void print(vector<int> &nums)\n {\n cout << \"[ \" << nums[0] << \", \";\n for (int i = 1 ; i < nums.size() ; i++)\n {\n cout << nums[i] << \", \";\n }\n\n cout << \" ]\" << endl;\n }\n vector<vector<int>> threeSum(vect... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n\n void print(vector<int> &nums)\n {\n cout << \"[ \" << nums[0] << \", \";\n for (int i = 1 ; i < nums.size() ; i++)\n {\n cout << nums[i] << \", \";\n }\n\n cout << \" ]\" << endl;\n }\n vector<vector<int>> threeSum(vect... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "void f(int &i,const int &n,const vector<int>& nums)\n{\n while(i<n&&nums[i]==nums[i-1])\n i++;\n}\nclass Solution {\npublic:\nvector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>>niz;\n int i=0,j,k=3,n,s,n1;\n n=nums.size();\n pair<int,int>x;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int> get_sorted(vector<int> nums, int start, int end)\n {\n\n vector<int> temp, first, second;\n temp.clear();\n if(start==end)\n {\n temp.push_back(nums[start]);\n return temp;\n \n }\n\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n vector<vector<pair<int, int>>> sum12 (2e5+1);\n vector<int> sum3 (2e5+1, 0);\n int n = nums.size();\n for (int i = 0; i < n; i++) {\n if (i > ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> twosum(vector<int>&nums, int cur) {\n int n = nums.size();\n int st = cur + 1;\n int en = n - 1;\n int target = -nums[cur];\n vector<vector<int>> resAll;\n while(st < en) {\n if(nums[st] + nums[en] < tar... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n map<int, int> mp;\n mp[0 - nums[0]] = 0;\n set<set<int>> se;\n int a, b, c, value;\n set<int> tmp;\n vector<vector<int>> res;\n int le... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> ans;\n sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size() - 2; i++) {\n int l = i;\n int m = l + 1;\n int r = nums.size() - 1;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<vector<int>> ans;\n sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size() - 2; i++) {\n int l = i;\n int m = l + 1;\n int r = nums.size() - 1;\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "// Jai shree ram\n// Hash function for vector<int>\nstruct VectorHash {\n size_t operator()(const vector<int>& v) const {\n size_t hash_value = 0;\n for (int i : v) {\n hash_value ^= hash<int>()(i) + 0x9e3779b9 + (hash_value << 6) + (hash_value >> 2);\n }\n return ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(), nums.end()); //NlogN\n\n int len = nums.size();\n\n set<vector<int>> ans;\n\n unordered_map<int, int> m; \n for(auto &x: nums) m[x]++; \n\n for(int i = 0; i < len ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<vector<int>> ans;\n int mid=0;\n while (mid<nums.size()&&nums[mid]<0)mid++;\n if((mid+2)<nums.size()&&nums[mid]==0&&nums[mid+1]==0&&nums[mid+2]==0)... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>>ans;\n bool flag=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]!=0)\n flag=1;\n }\n if(flag==0)\n {\n vector<int>... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> result;\n int n = nums.size();\n sort(nums.begin(), nums.end());\n\n for(int i=0;i<n;i++){\n int target = -nums[i];\n int left = i+1;\n int rig... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> answer;\n std::map<int, int> locations;\n std::map<vector<int>, int> test;\n std::sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size(); i++) {\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> answer;\n std::map<int, int> locations;\n std::map<vector<int>, int> test;\n std::sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size(); i++) {\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n map<int, int> mp;\n mp[0 - nums[0]] = 0;\n set<set<int>> se;\n int a, b, c, value;\n set<int> tmp;\n vector<vector<int>> res;\n int length = nums.size();\n if(length > ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> twoSum(vector<int>& nums, int left, int target){\n int right=nums.size()-1;\n vector<vector<int>> vpp;\n while(left<right){\n if(nums[left]+nums[right]== target){\n vpp.push_back({nums[left],nums[right]});\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>> threeSum(vector<int>& nums) {\n set<tuple<int, int, int>> res;\n sort(nums.begin(), nums.end());\n int n = nums.size();\n for (int i = 0; i < n; ++i) {\n int j = i + 1;\n int k = n - 1;\n int t... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "struct Node{\n int val;\n int i;\n int j;\n Node(int val,int i,int j): val(val),i(i),j(j) {};\n // Define the operator< to compare Node objects\n bool operator<(const Node& other) const {\n if (val != other.val) return val < other.val;\n if (i != other.i) return i < othe... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "struct Node{\n int val;\n int i;\n int j;\n Node(int val,int i,int j): val(val),i(i),j(j) {};\n // Define the operator< to compare Node objects\n bool operator<(const Node& other) const {\n if (val != other.val) return val < other.val;\n if (i != other.i) return i < othe... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "#include <bits/stdc++.h>\n#define f(i, a, b) for (int i = a; i < b; i++)\n\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n \n int i, j, k, n = nums.size(), diff;\n sort(nums.begin(), nums.end());\n vector <vector <int>> ans;\n vector <i... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n bool bin_search(vector<int>& sorted_arr, int start, int end, int target){\n if (start > end) return false; \n int mid = (start + end) / 2;\n if (sorted_arr[mid] == target){\n return true;\n }\n if (sorted_arr[mid] < target){\n ... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n vector<vector<int>> ans;\n set<vector<int>> temp;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size()-2;i++){\n int target = -(nums[i]); \n vector<int> vec(nums.begin... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& arr) {\n sort(arr.begin(),arr.end());\n int i=0;\n vector<vector<int>>sol;\n while(i<arr.size()-2){\n int j=i+1;int k=arr.size()-1;\n while(j<k){\n vector<int>ans(3);\n i... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int pivot = 0;\n int it = 0;\n int target = 0;\n vector<vector<int>> retVec;\n unordered_map<int,int> numMap;\n\n\n sort(nums.begin(), nums.end());\n for(; pivot < nums.size(); ++p... |
15 | <p>Given an integer array nums, return all the triplets <code>[nums[i], nums[j], nums[k]]</code> such that <code>i != j</code>, <code>i != k</code>, and <code>j != k</code>, and <code>nums[i] + nums[j] + nums[k] == 0</code>.</p>
<p>Notice that the solution set must not contain duplicate triplets.</p>
<p> </p>
<p... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>>ans;\n\n unordered_map<int,int>mp;\n\n sort(nums.begin(),nums.end());\n\n for(int i = 0;i<n;i++)\n {\n if(i>0 and nums[i] == nums[i-1]) continue;... |
16 | <p>Given an integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, find three integers in <code>nums</code> such that the sum is closest to <code>target</code>.</p>
<p>Return <em>the sum of the three integers</em>.</p>
<p>You may assume that each input would have exactly one solu... | 0 | {
"code": "class Solution {\npublic:\n int threeSumClosest(vector<int>& nums, int target) {\n ranges::sort(nums);\n auto best = nums[0] + nums[1] + nums[2];\n\n for (int i = 0; i < nums.size()-1; i++) {\n int left = i+1;\n int right = nums.size() - 1;\n while (... |
16 | <p>Given an integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, find three integers in <code>nums</code> such that the sum is closest to <code>target</code>.</p>
<p>Return <em>the sum of the three integers</em>.</p>
<p>You may assume that each input would have exactly one solu... | 1 | {
"code": "class Solution {\npublic:\n int threeSumClosest(vector<int>& nums, int target) {\n sort(nums.begin(), nums.end());\n int closest_sum = INT_MAX / 2; // A large value but not overflow\n \n for (int i = 0; i < nums.size() - 2; ++i) {\n int left = i + 1, right = nums.... |
16 | <p>Given an integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, find three integers in <code>nums</code> such that the sum is closest to <code>target</code>.</p>
<p>Return <em>the sum of the three integers</em>.</p>
<p>You may assume that each input would have exactly one solu... | 1 | {
"code": "class Solution {\npublic:\n int threeSumClosest(vector<int>& nums, int target) {\n sort(nums.begin(), nums.end());\n int closest_sum = INT_MAX / 2; \n \n for (int i = 0; i < nums.size() - 2; ++i) {\n int left = i + 1, right = nums.size() - 1;\n while (l... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n vector<string> output = {\"\"};\n for(char dig: digits){\n vector<char> toAdd;\n switch(dig){\n case '2':\n toAdd = {'a','b','c'};\n b... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n void recur(string& digits, int idx, string& tmp, vector<string>& ans){\n if(tmp.size() == digits.size()){\n ans.push_back(tmp);\n return;\n }\n //for each digit we can have 3 values, iterate over those\n int digi = digits[idx]... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n if (digits.empty()) {\n return {};\n }\n vector<string> d = {\"abc\", \"def\", \"ghi\", \"jkl\", \"mno\", \"pqrs\", \"tuv\", \"wxyz\"};\n vector<string> ans = {\"\"};\n for (aut... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n if (digits.empty()) {\n return {};\n }\n vector<string> d = {\"abc\", \"def\", \"ghi\", \"jkl\", \"mno\", \"pqrs\", \"tuv\", \"wxyz\"};\n vector<string> ans = {\"\"};\n for (aut... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n if (digits.empty()) {\n return {};\n }\n vector<string> d = {\"abc\", \"def\", \"ghi\", \"jkl\", \"mno\", \"pqrs\", \"tuv\", \"wxyz\"};\n vector<string> ans = {\"\"};\n for (aut... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n if (digits.empty()) {\n return {};\n }\n vector<string> d = {\"abc\", \"def\", \"ghi\", \"jkl\", \"mno\", \"pqrs\", \"tuv\", \"wxyz\"};\n vector<string> ans = {\"\"};\n for (aut... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\n public:\n vector<string> letterCombinations(string digits) {\n if (digits.empty())\n return {};\n\n vector<string> ans;\n\n dfs(digits, 0, \"\", ans);\n return ans;\n }\n\n private:\n const vector<string> digitToLetters{\"\", \"\", \"abc\", \"def\", \"ghi\",\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n void mapping(int i, string& digits, vector<string>& dict, string comb, vector<string>& ans)\n {\n if (i==digits.size())\n {\n if (comb.size()>0)\n ans.push_back(comb);\n return;\n }\n\n for (auto d: dict[digi... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\n private:\n void solve(string digits,vector<string> & ans,string output,string mapping[],int idx){\n if(idx>=digits.length()){\n ans.push_back(output);\n return ;\n }\n int num=digits[idx]-'0';\n string value=mapping[num];\n\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n\nvoid solve(vector<string> &ans,int index,string &output,string &digits,vector<string> &mapping)\n{\n if(index >= digits.length())\n {\n ans.push_back(output);\n return;\n }\n\n int digit = digits[index] - '0';\n string val = mapping[digit];\n for... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n\n vector<string> progressive_ans_builder(vector<string> s1, string s2) {\n vector<string> s3; int n_s2 = s2.length();\n for(int i = 0; i<n_s2; i++) {\n for(int j = 0; j<s1.size(); j++) {\n string t = s1[j]+s2[i];\n s3.pus... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "#include <unordered_map>\n#include <vector>\n#include <string>\n\nclass Solution {\n // Mapping of digits to corresponding characters\n std::unordered_map<char, std::string> m;\n \n // Resulting combinations\n std::vector<std::string> output;\n\n // Depth-first search for generating combi... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n if (digits.empty()) return {};\n vector<string> m = {\n \"abc\", \"def\", \"ghi\", \"jkl\",\n \"mno\", \"pqrs\", \"tuv\", \"wxyz\"\n } ;\n\n vector<string> ans = {\"\"};\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 0 | {
"code": "class Solution {\npublic:\n vector<string> result;\n \n auto solve(int idx, string &digits, string &temp, auto &mp) {\n if(idx >= digits.length()) {\n result.push_back(temp);\n return;\n }\n \n char ch = digits[idx];\n string str = mp[ch];\n... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 1 | {
"code": "class Solution {\nvoid solve(string digit, string output, int index, vector<string>& ans, string mapping[] ) {\n \n //base case\n if(index >= digit.length()) {\n ans.push_back(output);\n return;\n }\n \n int number = digit[index] - '0';\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 1 | {
"code": "class Solution {\nprivate:\n void solve(string digit, string output, int i, vector<string>& ans, string mapping[]){\n if(i>=digit.length()){\n ans.push_back(output);\n return;\n }\n int num = digit[i] - '0';\n string value = mapping[num];\n for(in... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 2 | {
"code": "class Solution {\npublic:\nint n;\nvector<string>result;\nvoid find(int idx,string &temp,string &digits,unordered_map<char,string>&mp){\n if(idx>=n){\n result.push_back(temp);\n return;\n }\n char ch=digits[idx];\n string str=mp[ch];\n for(int i=0;i<str.length();i++){\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 2 | {
"code": "class Solution {\nprivate:\n void solve(string digit, string output, int index, vector<string>& ans, string mapping[] ) {\n \n //base case\n if(index >= digit.length()) {\n ans.push_back(output);\n return;\n }\n \n int number = digit[index]... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 2 | {
"code": "class Solution {\npublic:\n vector<string> tbl={\"\",\"\",\"abc\",\"def\",\"ghi\",\"jkl\",\"mno\",\"pqrs\",\"tuv\",\"wxyz\"};\n vector<string> res;\n void helper(string digi, string tmp, int idx)\n {\n if(tmp.size() == digi.size())\n {\n res.push_back(tmp);\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 2 | {
"code": "class Solution {\npublic:\n vector<string> keys={\"\",\"\",\"abc\",\"def\",\"ghi\",\"jkl\",\"mno\",\"pqrs\",\"tuv\",\"wxyz\"};\n vector<string> ans;\n void helper(string digits,int index,string tempans){\n if(index==digits.size()){\n if(tempans.size()!=0){\n ans.push_... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 3 | {
"code": "class Solution {\n int n, m;\n unordered_map<char, string> M;\n unordered_map<char, string> vis;\npublic:\n void backTrack(int idx, string s, string d, vector<string>& res) {\n if(s.size() == n) {\n res.push_back(s);\n return;\n }\n\n if(idx == n) {\n ... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<char, string> m = {\n {'2', \"abc\"},\n {'3', \"def\"},\n {'4', \"ghi\"},\n {'5', \"jkl\"},\n {'6', \"mno\"},\n {'7', \"pqrs\"},\n {'8', \"tuv\"},\n {'9', \"wxyz\"}\n };\n vector<string> ans;\n voi... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<char, unordered_set<char>> dic = {\n {'2', {'a', 'b', 'c'}},\n {'3', {'d', 'e', 'f'}},\n {'4', {'g', 'h', 'i'}},\n {'5', {'j', 'k', 'l'}},\n {'6', {'m', 'n', 'o'}},\n {'7', {'p', 'q', 'r', 's'}},\n {'8', {'t', 'u'... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 3 | {
"code": "#define pb push_back\nclass Solution {\nprivate:\nmap<char,string>mp={\n {'2',\"abc\"},\n {'3',\"def\"},\n {'4',\"ghi\"},\n {'5',\"jkl\"},\n {'6',\"mno\"},\n {'7',\"pqrs\"},\n {'8',\"tuv\"},\n {'9',\"wxyz\"}\n };... |
17 | <p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p>
<p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette... | 3 | {
"code": "class Solution {\npublic:\n void backtrack(vector<string>& res, vector<vector<char>> element, string str, int i){\n if (str.size() == element.size()){\n res.push_back(str);\n return;\n }\n\n for (int j = 0; j < element[i].size(); j++){\n str+=element... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.