id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void solve(int i, int n, int k, vector<int> &curr, vector<vector<int>>& ans){\n if(n == 0 && k == 0){\n ans.push_back(curr);\n return;\n }\n if(i>9){\n return;\n }\n if(n < 0 || k < 0){\n return;\n...
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\nvoid func(int i,vector<int> arr,vector<int> &ds,vector<vector<int>> &ans,int k,int n,int sum)\n{\n \n if(ds.size()==k)\n {\n if(sum==n)\n ans.push_back(ds);\n return;\n }\n\n if(i>=arr.size() || sum>n)\n {\n return;\n }\n\n\n ds.push_...
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void generate(int ind,int len,int target,vector<int> arr,vector<int>&temp,vector<vector<int>> &ans){\n if(target == 0 && temp.size() == len) { ans.push_back(temp) ;return;}\n if(temp.size() == len) return ;\n if(ind == arr.size()) return ;\n if( ar...
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void print1(int ind,vector<vector<int>> &ans,vector<int> &ds,vector<int> nums,int k,int n){\n if(ds.size() == k){\n if(n==0){\n ans.push_back(ds);\n }\n return;\n }\n if(ind>=nums.size()){\n retur...
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void sumOfNum(int n,int k,vector<int> arr,int ind,int curSum,vector<int>&subset)\n { \n if(curSum==n && subset.size()==k)\n {\n ans.push_back(subset);\n return;\n }\n if(curSum>n || ind>=arr....
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void calculate(int n, int k, int start, int curSum, vector<int> ds, vector<vector<int>>& ans){\n //base condition\n if(curSum == n and k==0){\n ans.push_back(ds);\n return;\n }\n if(start > 9 or start > n - curSum) return; ...
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>> &ans,vector<int> s,int k,int n,int i)\n {\n if(s.size()==k)\n {\n if(n==0)\n ans.push_back(s);\n return;\n }\n if(i<1)\n return;\n if(n>=i)\n { \n s.push_b...
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>> &ans,vector<int> s,int k,int n,int i)\n {\n if(s.size()==k)\n {\n if(n==0)\n ans.push_back(s);\n return;\n }\n if(i>9)\n return;\n if(n<0)\n return;\n s....
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>> &ans,vector<int> s,int k,int n,int i)\n {\n if(s.size()==k)\n {\n if(n==0)\n ans.push_back(s);\n return;\n }\n if(i>9)\n return;\n if(n<0)\n return;\n s....
216
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p> <ul> <li>Only numbers <code>1</code> through <code>9</code> are used.</li> <li>Each number is used <strong>at most once</strong>.</li> </ul> <p>Return <em>a list of all possible va...
3
{ "code": "class Solution {\npublic:\n void gen(vector<int> &arr,int i,int count_num,int k,int mysum,int n,set<vector<int>> &ans,vector<int> temp){\n if(i==arr.size() || count_num>=k){\n if(count_num==k && mysum==n){\n ans.insert(temp);\n }\n return;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "auto init = []()\n{\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\n\n\nclass Solution\n{\npublic:\n bool containsDuplicate(vector<int>& nums) // I'd add \"const\" here if I could\n { // but that's not the interface\n...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n switch (nums.size()) {\n case 0:\n return false;\n case 1:\n return false;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n ranges::sort(nums);\n\n for (size_t i = 1; i < nums.size(); ++i)\n if (nums[i-1] == nums[i])\n return true;\n\n return false;\n }\n};", "memory": "59909" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int pula = nums.size();\n for (int i = 1; i < pula; i++) {\n int pizda = nums[i];\n int coaie = i - 1;\n while (coaie >= 0 && nums[coaie] > pizda) {\n if (nums[coaie] =...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool b = false;\n bool containsDuplicate(vector<int>& nums) {\n if (nums.size() == 0){return false;}\n else if (nums.size() == 1){return false;}\n else if (nums.size() == 2)\n {\n if (nums[0] == nums[1]) {return true;}\n el...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "#include <sys/mman.h>\n\nstruct Solution {\n static bool containsDuplicate(const vector<int>& nums) {\n static_assert(CHAR_BIT == 8);\n static_assert(sizeof(int) == 4);\n static_assert(sizeof(uintptr_t) == 8);\n\n void* const mapped = mmap(\n nullptr,\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "#include <sys/mman.h>\n\nauto init = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nstruct Solution {\n static bool containsDuplicate(const vector<int>& nums) noexcept {\n static_assert(CHAR_BIT == 8);\n static...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "#include <sys/mman.h>\n\nauto init = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nstruct Solution {\n static bool containsDuplicate(const vector<int>& nums) noexcept {\n static_assert(CHAR_BIT == 8);\n static...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n\n int n = nums.size();\n\n for(int i = 0;i<n;i++){\n if(i>0 && nums[i]==nums[i-1]) return true;\n }\n\n return false;\n }\n};", "memory": "60734" ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n for(int i =0;i<nums.size()-1;i++){\n if(nums[i] == nums[i+1]) return true;\n }\n return false;\n }\n \n};", "memory": "60734" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(), nums.end()); \n for (int i = 1; i < nums.size(); ++i) {\n if (nums[i] == nums[i - 1]) { \n return true;\n }\n }\n return false; \n }\n \n};"...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n for(int i = 1; i < n; i++){\n if(nums[i] == nums[i-1]){\n return true;\n break;\n }\n }\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n for (int i = 1; i < nums.size(); i++) {\n if (nums[i] == nums[i - 1]) {\n return true;\n }\n }\n return false;\n }\n};\n", "me...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
0
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums){\n int n=nums.size();\n sort(nums.begin(),nums.end());\n for(int i=0; i<n-1; i++){\n if(nums[i]==nums[i+1]){\n return true;\n break;\n }\n }\n retu...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n\n try {\n sort(nums.begin(), nums.end(), [](int& lhs, int rhs) -> bool {\n if (lhs == rhs) {\n throw \"error\";\n }\n return lhs < rhs;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n\n try {\n sort(nums.begin(), nums.end(), [](int& lhs, int rhs) -> bool {\n if (lhs == rhs) {\n throw string(\"error\");\n }\n return lhs < rhs;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "#include <sys/mman.h>\n\nstruct Solution {\n static bool containsDuplicate(const vector<int>& nums) {\n static_assert(CHAR_BIT == 8);\n static_assert(sizeof(int) == 4);\n static_assert(sizeof(uintptr_t) == 8);\n\n constexpr auto len = size_t{1} << (32 - 3);\n void* con...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int> res;\n res.push_back(nums[0]);\n for(int i=1;i<nums.size();i++)\n {\n if(res[i-1]==nums[i])\n {\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int>arr={nums[0]};\n \n \n for(int i=1;i<nums.size();i++){\n if(arr[i-1]==nums[i]){\n\n return true;\n }\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class IntHashMap {\npublic:\n int m_size;\n int *m_HashMap;\n bool *m_Occupied;\n\n IntHashMap(int size) : m_size(size) {\n m_HashMap = new int[m_size]();\n m_Occupied = new bool[m_size]();\n }\n\n ~IntHashMap() {\n delete[] m_HashMap;\n delete[] m_Occupied;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n long long int n= nums.size();\n stack<long long int>s;\n s.push(nums[0]);\n for(int i=1;i<n;i++){\n if(nums[i]==s.top()){\n return true;...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n vector<int>temp;\n temp.push_back(nums[0]);\n for (int i=1; i<n; i++){\n if (nums[0]!=nums[i] && nums[i]!=nums[i-1]) temp.push_...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int i = 0, j = i + 1, k = 0;\n vector<int> arr(nums.size(), 0);\n sort(nums.begin(), nums.end());\n\n while (i < nums.size()) {\n if (j >= nums.size() || nums[i] != nums[j]) {\n arr[k++] = 0;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n constexpr int FIRST_INDEX = 0;\n std::vector sorted_array = nums;\n\n std::sort(sorted_array.begin(), sorted_array.end());\n\n int previous = sorted_array[FIRST_INDEX];\n for (int index = 1; inde...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans(nums);\n sort(begin(ans),end(ans));\n for(int i=0;i<n-1;i++){\n if(ans[i]==ans[i+1]){\n return 1;\n break;\n }\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n vector<int> x = nums;\n sort(x.begin(), x.end());\n for (int i = 0; i < x.size() - 1; i++) {\n if (x[i] == x[i + 1]) {\n return true;\n }\n }\n return false;\...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n\n int size = nums.size();\n pair<int,int>* pairs_array = new pair<int,int>[size];\n\n for(auto& key : nums){\n int index = key % size ;\n\n if(index < 0)\n index +=size ;\n...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n class MyHashSingle{\n private:\n vector<int> table;\n int hash(int value){\n long newValue = value;\n long index = (newValue * newValue) % table.size();\n return index;\n }\n bool esPrimo(int n){\n if ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n long int min = nums[0];\n long int max = nums[0];\n for (int i = 0; i < nums.size(); i++) {\n if (max < nums[i])\n max = nums[i];\n if (min > nums[i])\n min ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n class MyHashSingle{\n private:\n vector<int> table;\n int hash(int value){\n long newValue = value;\n long index = (newValue * newValue) % table.size();\n return index;\n }\n bool esPrimo(int n){\n if ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "#include <iostream>\n#include <vector>\n#include <cstdlib> // For malloc and free\n\nclass Solution {\npublic:\n // Linked List Node\n struct node {\n int key; // key and value are both integers\n int value;\n struct node* next;\n };\n\n // Function to initialize a node\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int> hmp;\n for( short int i = 0; i < nums.size(); i++){\n if(hmp.find(nums[i]) == hmp.end()){\n hmp[nums[i]] = i;\n }else{\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int> hmp;\n for(short int i = 0; i < nums.size(); i++){\n if(hmp.find(nums[i]) == hmp.end()){\n hmp[nums[i]] = i;\n }else{\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int> hmp;\n for(signed short int i = 0; i < nums.size(); i++){\n if(hmp.find(nums[i]) == hmp.end()){\n hmp[nums[i]] = i;\n }else{\n return true;\...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n struct smOl_hash_map {\n struct node {\n node* next;\n int v;\n };\n \n vector<node*> data{128};\n smOl_hash_map(size_t size) : data(size, {}) {\n \n }\n bool put_contains(int v) {\n node** n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n priority_queue<int>pq;\n for(int i = 0; i < nums.size(); i++) {\n pq.push(nums[i]);\n }\n \n int cur=INT_MIN, prev=INT_MIN;\n while(!pq.empty()) {\n prev = cur;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n vector<int> new1;\n for(int i=0;i<nums.size();i++){\n new1.push_back(nums[i]);\n }\n sort(new1.begin(),new1.end());\n\n for(int i=0;i<(new1.size()-1);i++){\n if(new1[i]==new...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n vector <int> new1;\n for (int a:nums){\n new1.push_back(a);\n }\n sort(new1.begin(),new1.end());\n for(int i=0;i<new1.size()-1;i++){\n if (new1[i]==new1[i+1]){\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n vector<int> new1;\n for(int i=0;i<nums.size();i++){\n new1.push_back(nums[i]);\n }\n sort(new1.begin(),new1.end());\n\n for(int i=0;i<(new1.size()-1);i++){\n if(new1[i]==new...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "#include <iostream>\n#include <vector>\n#include <cstdlib> // For malloc and free\n\nclass Solution {\npublic:\n // Linked List Node\n struct node {\n int key; // key and value are both integers\n int value;\n struct node* next;\n };\n\n // Function to initialize a node\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n struct smOl_hash_map {\n struct node {\n node* next;\n int v;\n };\n \n vector<node*> data{128};\n smOl_hash_map(size_t size) : data(size, {}) {\n \n }\n ~smOl_hash_map() {\n for (auto& i : da...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n int h(int x){\n return x % 45013;\n }\n bool containsDuplicate(vector<int>& nums) {\n vector<int> v[45013];\n for(int &x : nums){\n x+=1000000000;\n int vecId = h(x);\n if(find(v[vecId].begin(), v[vecId].end(), x) !=...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n\n bool containsDuplicate(vector<int>& nums) {\n vector<int> v[45013];\n for(int &x : nums){\n x+=1000000000;\n int vecId = x % 45013;\n if(find(v[vecId].begin(), v[vecId].end(), x) != v[vecId].end()) return true;\n v[v...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n public:\nclass aset {\nprivate:\n struct Node {\n int data;\n Node* left;\n Node* right;\n int height;\n Node(int val) : data(val), left(nullptr), right(nullptr), height(1) {}\n };\n int32_t S = 0;\n Node* rotateRight(Node* y) {\n Node* x = y->...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n public:\nclass aset {\nprivate:\n struct Node {\n int data;\n Node* left;\n Node* right;\n int height;\n Node(int val) : data(val), left(nullptr), right(nullptr), height(1) {}\n };\n int32_t S = 0;\n Node* R_Rot(Node* y) { if (!y || !y->left) return ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "#include <algorithm>\nclass Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n std::unordered_set<int>* gyatt = new unordered_set<int>();\n\n for (const auto& num : nums) \n {\n if (!gyatt->insert(num).second)\n {\n return true;\...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n std::unordered_set<int>* has = new std::unordered_set<int>();\n for (int value:nums){\n if (has->count(value)){\n return true;\n }\n has->insert(value);\n }\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int> &nums) {\n unordered_map<int, int> m;\n for (auto it{nums.begin()}; it < nums.end(); it++) {\n if (m.insert_or_assign(*it, 0).second ==\n false) // if assignment took place\n {\n return true;\n }\n }\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n struct smOl_hash_map {\n struct node {\n node* next;\n int v;\n };\n \n vector<node*> data{128};\n smOl_hash_map(size_t size) : data(size, {}) {\n \n }\n ~smOl_hash_map() {\n for (auto& i : da...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n struct smOl_hash_map {\n struct node {\n ~node() {\n if (next)\n delete next;\n }\n node* next;\n int v;\n };\n \n vector<node*> data;\n smOl_hash_map(size_t size) : data(s...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\n struct exc {};\n struct smOl_hash_map {\n struct node {\n ~node() {\n if (next)\n delete next;\n }\n int v;\n node* next;\n };\n \n vector<node*> data;\n smOl_hash_map(s...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n set<int>n;\n int l{}, r{};\n r = nums.size()-1;\n while(l <= r){\n if(n.count(nums[l]) || n.count(nums[r]) || (nums[l] == nums[r] && l != r)) return true;\n else{\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int> map;\n\n int left = 0, right = nums.size() - 1;\n\n while (left <= right) {\n if (left == right) {\n map[nums[left]]++;\n }\n else {\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n unordered_set<int> hashset;\n int n = nums.size();\n // for (const int& n : nums) {\n // if (hashset.find(n) != hashs...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n unordered_set<int> hashset;\n int n = nums.size();\n // for (const int& n : nums) {\n // if (hashset.find(n) != hashs...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n\n unordered_map<int, int> dup;\n\n for (auto num : nums)\n {\n dup[num]+=1;\n if( dup[num] ==2) return true;\n }\n \n return false;\n }\n};", "memory": "70221" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int,int> seen;\n for(int i:nums){\n if(seen[i]>=1){\n return true;\n }\n seen[i]++;\n }\n return false;\n \n\n }\n};", "memory": "70...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "/*\napproach 1:\n- transform to a set and see if the length match\n- O(N) space, O(N) time\n\n- we can early bail and save some time. \n\n*/ \n\nauto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\n\nclass Solution {\npublic:\n bool containsDuplic...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n set<int> st;\n for (auto it:nums){\n if (st.find(it)!=st.end()) return true;\n st.insert(it);\n }\n return false;\n }\n};", "memory": "70634" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map <int,int> val;\n for (int i : nums)\n {\n if (val[i]==1)\n {\n return true;\n }\n val[i]++;\n }\n return false;\n }\n};...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int> seen; \n for(int num : nums) {\n if(seen.find(num) != seen.end()) {\n return true; \n }\n seen.insert(num); \n }\n return false; \n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
1
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int> umap; \n for(int i=0;i<nums.size();i++)\n {\n if(umap[nums[i]]>0)\n {\n return true;\n }\n umap[nums[i]]++;\n }\n\n \n return false;\...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int> map; \n for(int i = 0; i < nums.size(); i++){\n if(map.find(nums[i]) != map.end()) {\n return true;\n } \n map[nums[i]]++;\n } \n\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(int i: nums){\n if (mp[i]>=1)\n return true;\n mp[i]++;\n }\n return false;\n }\n};", "memory": "71046" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int> seen;\n for (const auto& n: nums) {\n if (!seen.contains(n)) {\n seen.insert(n);\n }\n else {\n return true;\n }\n }...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int>s;\n int l=nums.size();\n for(int i=0;i<l;i++){\n if(s.find(nums[i])!=s.end()){\n return true;\n }\n s.insert(nums[i]);\n }\n ret...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int, int> contains(n);\n\n for(int i = 0; i < nums.size(); ++i){\n int cur = nums[i];\n if(contains.count(cur) > 0){\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\nbool containsDuplicate(vector<int>& nums) {\n // Use unordered set to track seen numbers\n unordered_set<int> seenNumbers;\n \n // Reserve space to avoid rehashing\n seenNumbers.reserve(nums.size());\n \n // Iterate over each element\...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\nbool containsDuplicate(vector<int>& nums) {\n // Use unordered set to track seen numbers\n unordered_set<int> seenNumbers;\n \n // Reserve space to avoid rehashing\n seenNumbers.reserve(nums.size());\n \n // Iterate over each element\...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int> set;\n for(int i=0;i<nums.size();++i){\n set.insert(nums[i]);\n if(set.size()<i){\n return true;\n }\n }\n\n if(set.size()==nums.size()...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\ntemplate<typename T>\nstruct Tr_Nd {\n\tT key; int height, count, size; Tr_Nd* left; Tr_Nd* right; Tr_Nd* par = nullptr;\n\tTr_Nd(T x) : key(x), left(nullptr), right(nullptr), height(1), count(0), size(1) {}\n};\ntemplate<typename T>\nclass AVL {\nprivate:\n\tint Gt_Ht(Tr_Nd<T>* ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n std::set<int>* mySet = new std::set<int>(nums.begin(), nums.end());\n if (mySet->size() == nums.size()) {\n return false;\n }\n return true;\n }\n};", "memory": "72284" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
2
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n std::set<int>* mySet = new std::set<int>(nums.begin(), nums.end());\n if (mySet->size() == nums.size()) {\n return false;\n }\n return true;\n }\n};", "memory": "72284" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n map<int, int> set_map;\n for (auto num: nums) {\n if (set_map.contains(num)) return true;\n set_map.insert(pair<int&, int>(num, 1));\n }\n return false;\n }\n};", "memory": "7...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "\n#include <vector>\n#include <unordered_set>\nusing namespace std;\n\nclass Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int> set{nums.begin(), nums.end(), nums.size()};\n return set.size() != nums.size();\n }\n};", "memory": "73934" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int,int> map(n);\n for(int i=0;i<n;i++){\n map[nums[i]]=0;\n }\n for(int i=0;i<n;i++){\n map[nums[i]]+=1;\n }\n for(int i=...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n std::unordered_set<int> hash;\n hash.reserve(nums.size());\n for (int i : nums) {\n hash.insert(i);\n }\n return hash.size() != nums.size();\n }\n};", "memory": "74346" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int> vals; vals.reserve(nums.size());\n for (int i = nums.size()-1; i >= 0; i--) {\n vals.insert(nums[i]);\n }\n return vals.size() == nums.size() ? false : true;\n }\n};", ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int>mp;\n for(auto i:nums)\n mp[i]++;\n for(auto j:mp)\n if(j.second > 1)\n return true;\n return false;\n }\n};", "memory": "74553" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n int n=nums.size();\n unordered_set<int>st;\n for(int i=0;i<n;i++){\n st.insert(nums[i]);\n }\n if(st.size()< n){\n return true;\n }\n re...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int>st(nums.begin(),nums.end());\n int n=nums.size();\n int s=st.size();\n if(n==s)\n return false;\n return true;\n \n }\n};", "memory": "74759" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int>s(nums.begin(),nums.end());\n if(nums.size()==s.size()){\n return false;\n }\n return true;\n }\n};", "memory": "74965" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int>s(nums.begin(),nums.end());\n if(nums.size()==s.size()){\n return false;\n }\n return true;\n }\n};", "memory": "74965" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i=0;i<nums.size();i++){\n if(mp.find(nums[i])==mp.end()) mp[nums[i]]=0;\n mp[nums[i]]++;\n }\n for(auto it: mp){\n if(it.second>=2) ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(int i:nums){\n mp[i]++;\n }\n for(auto i:mp){\n if(i.second>1) return true;\n }\n return false;\n }\n};", "memory": "75171" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int, int>mp;\n int n= nums.size();\n\n for(int i=0; i<n ;i++){\n mp[nums[i]]++;\n }\n\n for(auto it: mp){\n if(it.second>1){\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(auto it:nums){\n mp[it]++;\n }\n auto it= mp.begin();\n while(it!=mp.end()){\n if(it->second>=2){\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(auto it:nums){\n mp[it]++;\n }\n auto it= mp.begin();\n while(it!=mp.end()){\n if(it->second>=2){\n return true;\n ...
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n unordered_set<int>s;\n for(auto it: nums){\n s.insert(it);\n } \n if (nums.size()==s.size()){\n return 0;\n }\n else {\n return 1;\n }\n }\n};", "memory": "75584" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n return nums.size() > set<int>(nums.begin(),nums.end()).size();\n }\n};", "memory": "75790" }