id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n if(nums.size()==1)\n return {};\n vector <int> answer;\n sort(nums.begin(),nums.end());\n for(int i=1;i<=nums.size()-1;i++){\n if(nums[i]==nums[i-1])\n answer.pu... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>ans(nums.size(),0);\n for(int i=0;i<nums.size();i++){\n int n=nums[i];\n if(ans[n-1]==0)\n ans[n-1]=nums[i];\n else\n ans.push_back(ans[n-1]);\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& a) {\n vector<int> res ;\n int n = a.size();\n sort(a.begin(), a.end()) ;\n int mini = INT_MAX;\n int maxi= INT_MIN;\n for(int i = 0 ; i< n ; i=i+1){\n maxi = max(maxi , a[i]) ;\n min... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>ans(nums.size(),0);\n for(int i=0;i<nums.size();i++){\n int n=nums[i];\n if(ans[n-1]==0)\n ans[n-1]=nums[i];\n else\n ans.push_back(ans[n-1]);\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> arr2;\n vector<int> arr3;\n int flag=0;\n for(int i=0;i<nums.size();i++){\n if (find(arr3.begin(), arr3.end(), nums[i]) != arr3.end()) {\n if (find(arr2.begin()... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector <int> comp1;\n vector <int> comp2;\n for(auto i:nums){\n if(find(comp1.begin(),comp1.end(),i)!=comp1.end()){\n comp2.push_back(i);\n }\n else{\n comp1.... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "// class Solution {\n// public:\n// vector<int> findDuplicates(vector<int>& arr) {\n\n// vector<int> ans;\n// int n = arr.size();\n// if(n==1);\n// return {};\n// vector<bool> visited(n, false);\n\n// for (int i = 0; i < n; i++) {\n// // Check if the element has a... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n\n vector<int> hash(nums.size()+1,0);\n vector<int> ans;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++)\n {\n hash[nums[i]]++;\n }\n for(int i=0;i<ha... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>demo=nums;\n vector<int>list;\n sort(demo.begin(),demo.end()); \n int tempo=-1;\n for(int i:demo){\n if(tempo==i){\n list.push_back(i);\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& arr) {\n vector<int> ans;\n if (arr.size() == 1) {\n return ans;\n }\n sort(arr.begin(), arr.end());\n int count = 0;\n int n = arr.size();\n\n for (int i = 0; i < n - 1; i++) ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> ans;\n vector<int> nums1;\n for(int i=0;i<nums.size();i++){\n nums1.push_back(1);\n }\n \n for(int i=0;i<nums.size();i++){\n int x=nums[i];\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n // unordered_set<int> dups;\n int len = 100000;\n bool *dups = new bool[len];\n for(int i= 0; i < len; i++) {\n dups[i] = false;\n }\n //will cause a memory leak but will a... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int>ans;\n vector<int>arr;\n for(int i=1;i<nums.size();i++){\n if(nums[i]!=nums[i-1]){\n arr.push_back(nums[i-1]);\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n sort( nums.rbegin() , nums.rend());\n\n vector<int> ans;\n\n for(int i=0 ; i<nums.size()-1 ; i++){\n if(nums[i]==nums[i+1]){\n ans.push_back(nums[i]);\n \n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n\n vector<int> ar(nums);\n vector<int> a;\n vector<int> c;\n int b;\n\n for(int i=0;i<ar.size();i++){\n a.push_back(1);\n b=ar[i];\n for(int j=i+1;j<ar.size();... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>k;\n vector<int>h;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n k.push_back(nums[i]);\n }\n for(int i=1;i<k.size();i++){\n if(k... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>k;\n vector<int>h;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n k.push_back(nums[i]);\n }\n for(int i=1;i<k.size();i++){\n if(k... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> BruteForce(vector<int> n){\n int s = n.size();\n vector<int> k(s,-1);\n for(int i=0;i<s;i++){\n for(int j=i+1;j<s;j++){\n if(n[i] == n[j]){\n k[i] = n[i];\n break;\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>ans;\n int n=nums.size();\n int arr[1000000] = {0};\n\n for(int i=0;i<nums.size();i++)\n { \n int ch=abs(nums[i]);\n\n arr[ch]++;\n if(arr[ch]>1)\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> p;\n int h[1000000]={0};\n for(int i=0;i<nums.size();i++)\n {\n h[nums[i]]++;\n if(h[nums[i]]==2)\n {\n p.push_back(nums[i]);\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n\n vector<int> ar(nums);\n sort(ar.begin(),ar.end());\n vector<int> a;\n vector<int> c;\n int b;\n\n for(int i=0;i<ar.size();i++){\n a.push_back(1);\n b=ar[i];\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n set<int> ans;\n int n = nums.size();\n for(int i = 0; i < n; i++) {\n if(nums[i] == i+1) continue;\n if(nums[i] == nums[nums[i]-1]) ans.insert(nums[i]);\n else {\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n const int n = nums.size();\n unordered_set<int> duplicates;\n\n for (int i = 0; i < n;) {\n if (nums[i] != i + 1) {\n while (nums[i] != i + 1 && nums[nums[i] - 1] != nums[i])\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector <int> ans;\n set <int> temp;\n for (int i=0;i<nums.size();i++)\n {\n if (nums[i]==i+1) continue;\n else\n {\n while(1)\n {\n if (nums[i]==nums[nums[i]-1]) \n {\n... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int size = nums.size();\n vector<int>ans;\n unordered_map<int,int> map;\n for(int i = 0;i<size;i++){\n while(nums[i] != nums[nums[i]-1])\n swap(nums[i], nums[nums[i]-1]);\n... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> duplicates;\n unordered_set<int> visited;\n\n for(int i = 0; i < nums.size(); ) {\n if(i + 1 == nums[i]) {\n i++;\n continue;\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_set<int>st;\n int n = nums.size();\n for(int i=0;i<n;i++){\n int id = nums[i] - 1;\n if(id != i){\n while(nums[i]-1 != i && nums[nums[i]-1] != nums[i]){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n // find the value of n\n int n=nums.size();\n\n // traverse the vector nums\n for(int i=0;i<n;i++){\n // find the value of indx\n int indx=abs(nums[i])-1;\n\n // upd... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n \n set<int> s;\n vector<int> res;\n vector<int> freq(nums.size()+1,0);\n for(int i=0;i<nums.size();i++){\n freq[nums[i]]++;\n }\n for(int i=0;i<nums.size();i++){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n set<int>s1;\n vector<int>result;\n sort(nums.begin(),nums.end());\n int n=nums.size();\n for(int i=0;i<n-1;i++){\n if(nums[i]==nums[i+1]){\n s1.insert(nums[i]);\n }\n\n }\n result.a... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n //numbers from 1 to n\n // 0 based indexing\n vector<int> m=nums;\n set<int> s;\n for(int i=0;i<nums.size();i++)\n {\n if(m[nums[i]-1]==-1)\n {\n s... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_set<int> ret;\n const int N = nums.size();\n for (int i = 0; i < N; ++i) {\n while (nums[nums[i] - 1] != nums[i]) {\n swap(nums[nums[i] - 1], nums[i]);\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n = nums.size();\n vector<int> v;\n set<int> s;\n sort(nums.begin(),nums.end());\n for(int i = 0;i < n-1;i++){\n if(nums[i] == nums[i+1]){\n s.insert(nums[i]);\n... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n = nums.size() ;\n\n sort(nums.begin() , nums.end()) ;\n\n vector<int> ans ;\n\n for(int i = 0 ; i < n-1 ; ++i)\n {\n if(nums[i] == nums[i+1])\n ans.push_back(nums[... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>res;\n unordered_set<int>h;\n for(int i=0;i<nums.size();i++){\n if(h.find(nums[i])==h.end()){\n h.insert(nums[i]);\n }\n else{\n re... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int, bool> m;\n vector<int> v;\n for(auto x:nums)\n {\n if(m.contains(x))\n {\n v.push_back(x);\n m.erase(x);\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n = nums.size();\n\n if(n == 1)\n return {};\n\n unordered_set<int> st;\n vector<int> ans;\n for(auto it : nums){\n if(st.count(it) != 0){\n ans.push_... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int>m(n);\n vector<int>ans;\n for(int i=0;i<n;i++){\n m[nums[i]]++;\n }\n for(auto it:m){\n if(it.second>=2){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int>m(n);\n vector<int>ans;\n for(int i=0;i<n;i++){\n m[nums[i]]++;\n }\n for(auto it:m){\n if(it.second>=2){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int,int> map(n);\n for(auto& x: nums) map[x]++;\n vector<int> res;\n for(auto& x: map){\n if(x.second > 1){\n res.push_back(x.f... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int>m(n);\n vector<int>ans;\n for(int i=0;i<n;i++){\n m[nums[i]]++;\n }\n for(auto it:m){\n if(it.second>=2){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int> nums) {\n unordered_map<int, bool> m;\n m.reserve(1000);\n vector<int> v;\n for(auto x:nums)\n {\n if(m.contains(x))\n {\n v.push_back(x);\n m.erase(x... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {unordered_map<int,int>map1;\n for(int i=0;i<nums.size();i++)\n {if(map1.count(nums[i]))\n {map1[nums[i]]++;}\n else\n map1[nums[i]]=1;}\n nums={};\n for(auto x:map1)\n {if(x.second==2)\n {nums.push_back... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int, int>mp;\n for(auto i:nums) mp[i]++;\n nums.clear();\n for(auto i:mp){\n if(i.second==2)nums.push_back(i.first);\n } \n return nums;\n }\n};",
"memory": ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n ios::sync_with_stdio(0);\n vector<int> ans;\n unordered_map<int,int> map1;\n for(auto i:nums){\n map1[i]++;\n }\n for(int i=0;i<nums.size();i++){\n if(map1[nums[i]]==2){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic: // zekeriya atbaş\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int,int> m;\n for(int& num : nums){\n m[num]++;\n }\n vector<int> ans;\n for(auto& p : m){\n if(p.second > 1) ans.push_back(p.first);\... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int, int> freq;\n vector<int> ans;\n for(auto num : nums) ++freq[num];\n for(auto& [num, freq] : freq)\n if(freq % 2 == 0) ans.push_back(num);\n \n return ans;... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> ans;\n unordered_map<int,int> freq;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n freq[nums[i]]++;\n }\n for(int i=0;i<nums.size();i++){\n... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int,int> mp;\n vector<int> result;\n for(int &x:nums){\n mp[x]++;\n }\n for(auto it:mp){\n if(it.second>1){\n result.push_back(it.first);\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int, int> freqCount;\n vector<int> duplicates;\n\n for(int num : nums) {\n freqCount[num]++;\n }\n\n for(auto& entry : freqCount) {\n if(entry.second > 1) ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int,int> ans;\n vector<int> nums1;\n for(int i:nums){\n ans[i]++;\n }\n for(auto i:ans){\n if(i.second>1){\n nums1.push_back(i.first);\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int,int> ans;\n vector<int> nums1;\n for(int i:nums){\n ans[i]++;\n }\n for(auto i:ans){\n if(i.second>1){\n nums1.push_back(i.first);\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>freq(100000,0);\n vector<int>res;\n for(int num:nums){\n freq[num]++;\n if(freq[num]==2) res.push_back(num);\n }\n \nreturn res;\n }\n};",
"memory": "47062"
} |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>ans;\n\n int n=nums.size();\n\n set<int>_set;\n\n for(int i=0; i<n; i++){\n if(_set.count(nums[i])) ans.push_back(nums[i]);\n else _set.insert(nums[i]);\n }\n re... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> duplicates; // To store the duplicate numbers\n set<int> seen; // To track numbers we've already seen\n \n // Iterate over each number in the nums array\n for (int i ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int> duplicates; // To store the duplicate numbers\n set<int> seen; // To track numbers we've already seen\n \n // Iterate over each number in the nums array\n for (int i ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n map<int,int>mp;\n vector<int> duplicates;\n for(auto i: nums){\n if (mp.find(i)!=mp.end()){\n duplicates.push_back(i);\n }\n \n else{\n mp.in... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>ans;\n set<int>s;\n for(auto&num:nums){\n if(s.find(num)!=s.end()){\n \n ans.push_back(num);\n }\n s.insert(num);\n } \n\n return ans;\n }\n... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n set<int> s;\n vector<int> vec;\n for(int i=0;i<nums.size();i++){\n if(s.find(nums[i])!=s.end()){\n vec.push_back(nums[i]);\n }\n else{\n s.ins... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n map<int,int> mpp;\n for(int i=0; i<nums.size();i++){\n mpp[nums[i]]++;\n }\n nums.clear();\n for(auto it:mpp){\n if(it.second==2){\n nums.push_back(it.fir... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n unordered_map<int,int>count;\n for(int i=0;i<nums.size();i++){\n count[nums[i]]++;\n }\n vector<int>ans;\n for(int i=0;i<nums.size();i++){\n if(count[nums[i]]==2){\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n stack<int>s;\n unordered_set<int>seen;\n vector<int> findDuplicates(vector<int>& nums) {\n vector<int>result;\n for(int i=0;i<nums.size();i++){\n if(seen.find(nums[i])!=seen.end()){\n result.push_back(nums[i]);\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n map<int,int> mpp;\n for(auto it: nums){\n mpp[it]++;\n }\n int count=0;\n for(auto it: mpp){\n if(it.second==2){\n count++;\n }\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n map<int,int> m;\n for(int ele : nums){\n m[ele]++;\n }\n \n vector<int> ans;\n\n for(auto it : m){\n if(it.second==2){\n ans.push_back(it.first);\n }\n }\n ... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n map<int,int>mp;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n }\n vector<int> num;\n for(auto c:mp){\n if(c.second==2){\n num.push_back(c.first);\n... |
442 | <p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>
<p>You mu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n int n=nums.size();\n vector<int>vt;\n map<int,int>mpp;\n for(int i=0;i<n;i++){\n mpp[nums[i]]++;\n }\n for(auto x:mpp){\n if(x.second==2){\n vt.pus... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n char prev=chars[0]; \n int count=1, index=0;\n for(int i=1;i<chars.size();i++){\n if(chars[i]==prev){\n count++;\n }\n\n else{\n chars[index++]=prev;\n if(count>1){\... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n int size = chars.size();\n if (size == 0) return 0;\n\n char cur = chars[0];\n int cnt = 1, index = 1, left = 0;\n while (index <= size) {\n if (index < size && chars[index] == cur) {\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& s) {\n\n int index = 0;\n int count = 1;\n char prev = s[0];\n for (int i = 1; i < s.size(); i++) {\n if (s[i] == prev) {\n count++;\n } else {\n s[index++] = prev;\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& s) {\n int index=0;\n int n=s.size();\n int i=0;\n int j=0;\n int cnt=0;\n while(j<n){\n while(j<n && s[i]==s[j]){\n cnt++;\n j++;\n }\n s[index++]=s[i];\n i... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& s) {\n int index = 0, count = 1;\n char prev = s[0];\n\n for (int i = 1; i < s.size(); i++) {\n if (s[i] == prev) {\n count++;\n }\n\n else {\n s[index++] = prev;\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& s) {\n //famoue RUN_LENGTH_ENCODING tecqunicqe\n\n int count = 1,index = 0;\n char prev = s[0];\n\n for(int i=1;i<s.size();i++){ \n\n if(s[i] == prev){\n count++;\n }\n e... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n\n void findDigit(int count, vector<char>& chars, int &index)\n {\n string temp;\n while(count != 0)\n {\n temp.push_back((char)(count % 10 + '0'));\n count /= 10;\n }\n\n for(int i = temp.size() - 1; i >= 0; i--)\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n void convertToArray(vector<int>&arr,int num){\n while(num){\n arr.push_back(num%10);\n num /= 10;\n }\n }\n int compress(vector<char>& chars) {\n int n = chars.size();\n int i = 0,j=0;\n while(j<n){\n c... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n // dynamic for\n for (int i = 0; i < chars.size(); i++) {\n cout << \"> \" << i;\n char curr = chars[i];\n cout << \" curr = \" << curr << endl;\n // simple case, i is last\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n // dynamic for\n for (int i = 0; i < chars.size(); i++) {\n cout << \"> \" << i;\n char curr = chars[i];\n cout << \" curr = \" << curr << endl;\n // simple case, i is last\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n if(chars.size()<=1){\n return chars.size();\n }\n char temp='\\0';\n int count=0,answer=0,index=-1;\n stack<int> nums;\n for(int i=0;i<chars.size();i++){\n if(temp==chars[i])... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n vector<char> vect;\n int idx = 0;\n int cnt = 1;\n for(int i = 1;i<chars.size() ;i++){\n if(chars[idx] == chars[i]) cnt++;\n else{\n vect.push_back(chars[idx]);\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n unordered_map<char, int> um;\n vector<char> chars2;\n um[chars[0]]++;\n\n for(int i=1; i<chars.size(); i++){\n if(chars[i] == chars[i-1]){\n um[chars[i]]++;\n } else {\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n vector<pair<char,int>> vPair;\n char ch = chars[0];\n unordered_map<int, int> mp;\n int i = 0;\n for(; i < chars.size(); i++)\n {\n if(ch != chars[i])\n {\n ch... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n int ans = 0;\n\n // iterate through input vector using i pointer\n for (int i = 0; i < chars.size();) {\n const char letter = chars[i]; // current character being compressed\n int count = 0; // c... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) \n { \n int i = 0;\n int ansIndex = 0;\n int n = chars.size();\n\n while(i < n)\n {\n int j = i + 1;\n\n while(j < n && chars[i] == chars[j])\n {\n j++;\n... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n int n = chars.size();\n\n int write = 0; // Position to write the compressed characters\n int i = 0; // Position to read characters from\n\n while (i < n) {\n char currentChar = chars[i];\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n int i = 0;\n int ansIndex = 0;\n int n = chars.size();\n\n while(i<n){\n int j = i+1;\n while(j<n && chars[i]==chars[j]){\n j++;\n }\n //ya to chars si... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n int n=chars.size();\n int index=0, i=0;\n while(i<n){\n char ch=chars[i];\n int count=0;\n while(i<n && chars[i]==ch){\n count++;\n i++;\n }\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 0 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n string s;\n if(chars.size()==1) return 1;\n int cnt=1;\n for(int i=1;i<chars.size();i++){\n if(chars[i]==chars[i-1]) cnt++;\n else {\n s.push_back(chars[i-1]);\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 1 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n int i = 0;\n int ansIdx = 0;\n int n = chars.size();\n\n while(i < n) {\n int j = i + 1;\n while(j < n && chars[i] == chars[j]) {\n j++;\n }\n\n chars[... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 1 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n \n int ansIndex = 0;\n int count = 1;\n int n = chars.size();\n int i = 0;\n \nwhile(i<n)\n{\n int j = i+1;\n\n while(j<n && chars[i]==chars[j])\n {\n \n j++;\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 2 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n string s;\n //vector<int> mp(127, 0);\n if(chars.size()==1) s+=chars[0];\n else{\n int cnt=1;\n for(int i=1;i<chars.size();i++){\n if(chars[i]==chars[i-1]){\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 2 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n string s;\n if(chars.size()==1) s+=chars[0];\n int cnt=1;\n for(int i=1;i<chars.size();i++){\n if(chars[i]==chars[i-1]) cnt++;\n else {\n s.push_back(chars[i-1]);\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 3 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n vector<char>s;\n map<char,int>st;\n for(char i:chars){\n st[i]++;\n }\n int i=0;\n int n=chars.size();\n while(i<n){\n char cu=chars[i];\n int c=0;\n ... |
443 | <p>Given an array of characters <code>chars</code>, compress it using the following algorithm:</p>
<p>Begin with an empty string <code>s</code>. For each group of <strong>consecutive repeating characters</strong> in <code>chars</code>:</p>
<ul>
<li>If the group's length is <code>1</code>, append the character to... | 3 | {
"code": "class Solution {\npublic:\n int compress(vector<char>& chars) {\n // sort(chars.begin(),chars.end());\n string s=\"\";\n for(int i=0;i<chars.size();i++){\n int count=1;\n while(i+1<chars.size() && chars[i]==chars[i+1]){\n count++; i++;\n }\n ... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "\n// * Definition for singly-linked list.\n// struct ListNode {\n// int val;\n// ListNode *next;\n// ListNode() : val(0), next(nullptr) {}\n// ListNode(int x) : val(x), next(nullptr) {}\n// ListNode(int x, ListNode *next) : val(x), next(next) {}\n// };\n \n\nListNode* rev(L... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "\n// * Definition for singly-linked list.\n// struct ListNode {\n// int val;\n// ListNode *next;\n// ListNode() : val(0), next(nullptr) {}\n// ListNode(int x) : val(x), next(nullptr) {}\n// ListNode(int x, ListNode *next) : val(x), next(next) {}\n// };\n \n\nListNode* rev(L... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "class Solution {\npublic:\n ListNode* reverseList(ListNode* head) {\n if(head == NULL) return head;\n ListNode* newHead = NULL;\n while(head != NULL){\n ListNode* next = head->next;\n head->next = newHead;\n newHead = head;\n head = next;\... |
445 | <p>You are given two <strong>non-empty</strong> linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, ex... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.