id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n const int n = (3e4 * 2) + 6;\n int arr[n] = {0};\n for (auto& num : nums) {\n if (num >= 0)\n arr[num]++;\n else\n arr[abs(num) + int(3e4)]++;\n }\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int a[100000] = {0}, k;\n for(int i = 0; i < nums.size(); i++)\n {\n a[nums[i] + 3 * 10000]++;\n }\n for(int i = 0; i < 100000; i++)\n {\n if(a[i] == 1)\n k = i ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>A) {\n int result = 0;\n int n=A.size();\n for (int i = 0; i<n; i++)\n {\n\t\tresult ^=A[i];\n }\n\treturn result;\n}\n};",
"memory": "20100"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = 6 * 1e4 + 1;\n int offset = 3 * 1e4;\n vector<bool> arr(n,false);\n for (auto num:nums) {\n arr[num+offset] = !arr[num+offset];\n //cout << \"num=\" << num << \", arr[num]=\" << ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int i;\n int max = nums[0], min = nums[0];\n for (i = 1; i < nums.size(); i++) {\n if (nums[i] < min)\n min = nums[i];\n if (nums[i] > max)\n max = nums[i];\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n=nums.size(),flag=0;\n vector<int>freq(n,1);\n\n for(int i=0;i<n;i++){\n flag=1;\n for(int j=i+1;j<n;j++){\n if(nums[i]==nums[j] && freq[i]!=0 ){\n freq[j]... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int x=0;\n for(int i=0;i<n;i++)\n {\n x=x^nums[i];\n }\n return x;\n \n }\n};",
"memory": "20400"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int x=0;\n for(int i=0;i<n;i++)\n {\n x=x^nums[i];\n }\n return x;\n \n }\n};",
"memory": "20400"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) { \n sort(nums.begin(),nums.end());\n for(int i=1;i<nums.size();i+=2)\n {\n if(nums[i]!=nums[i-1])\n return nums[i-1];\n }\n return nums[nums.size()-1];\n }\n};",
"memory": "2... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size()-1;i+=2){\n if(nums[i]!=nums[i+1]){\n if(nums[i+1]==nums[i+2]){\n return nums[i];\n }\n e... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int i=0;\n int j=i+1;\n while(i<nums.size() && j<nums.size()){\n if(nums[i]==nums[j]){\n i=i+2;\n j=j+2;\n }\n e... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n \n int i = 0;\n if(nums.size() == 1)\n return nums[0];\n\n for(int i = 0; i < nums.size(); i = i + 2)\n {\n if(nums[i] != nums[i+1])\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n if(nums.size() == 1) {\n return nums[0];\n }\n sort(nums.begin(), nums.end());\n \n int i;\n for(i=0; i<nums.size(); i+=2) {\n if(nums[i] == nums[i+1]) continue;\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size()-1;i+=2)\n {\n if(nums[i]!=nums[i+1])\n {\n return nums[i];\n }\n }\n return nums.back();\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n int XOR = 0;\n\n\n for(int i=0;i<n;i++){\n XOR ^= nums[i];\n }\n\n return XOR;\n }\n};",
"memory": "20800"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "// M-1) Brute force (map) --> T.C: O(n), S.C: O(m) where m is size of the map and m = (n/2)+1.\n/*\nclass Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = nums.size();\n int single;\n\n unordered_map<int, int> m;\n for (int i = 0; i < n; i++) { // O(n) ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n std::sort(nums.begin(), nums.end());\n\n for(int i = 0; i < nums.size(); i += 2)\n {\n if(std::count(nums.begin(), nums.end(), nums[i]... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n vector<bool> vb(nums.size(),true);\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i]==nums[i+1]){vb[i]=vb[i+1]=false;}\n\n }\n\n for(int i=0;i<nums.size();i++){... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n vector<int> ans(nums.begin(),nums.end());\n sort(ans.begin(),ans.end());\n for(int i=0;i<nums.size()-1;i+=2){\n if(ans[i]!=ans[i+1]){\n return ans[i];\n\n }\n }\n r... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n vector<int> num = nums;\n sort(num.begin(), num.end());\n // cout << num[num.size()-1];\n for(int i=0; i<num.size()-1; i+=2) {\n if (num[i+1] != num[i]) return num[i];\n }\n return nu... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n \n int i = 0;\n vector <int> num = nums;\n sort(num.begin(),num.end());\n if ( nums.size() == 1 ) return num[i];\n while(i < nums.size()-1)\n {\n if ( num[i] != num[i+1] ) return n... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n \n int i = 0;\n vector <int> num = nums;\n sort(num.begin(),num.end());\n if ( nums.size() == 1 ) return num[i];\n while(i < nums.size()-1)\n {\n if ( num[i] != num[i+1] ) return n... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n stack<int> ayush;\n for (int i = 0; i < nums.size(); i++) {\n ayush.push(nums[i]);\n }\n int temp1, temp2;\n while (!ayush.empty()) {\n temp1 = ayush.top();\n ayush... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int len = nums.size();\n int singleNum;\n int lp1, lp2, tInt;\n int lowest, pos;\n int count, curNum;\n\n if (len == 1)\n return nums[0];\n\n // sort the numbers\n for (... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n vector<int> num = nums ;\n sort(num.begin(),num.end()) ;\n if( num.size() % 2 == 1 )\n {\n num.push_back( 1e5 ) ;\n }\n int i = 0 , j = 1 ;\n for( ; i < num.size() ; i += 2 , j... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n vector<int> num = nums ;\n sort(num.begin(),num.end()) ;\n if( num.size() % 2 == 1 )\n {\n num.push_back( 1e5 ) ;\n }\n int i = 0 ;\n for( i = 1 ; i < num.size() ; i++ )\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int max_dim = 3 * 100000;\n int freq_positive[3 * 100000] = { 0 };\n int freq_negative[3 * 100000] = { 0 };\n int nums_dim = nums.size();\n for(int i = 0; i<nums_dim; i++){\n if(nums[i] >= 0... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n //sorting \n sort(nums.begin(),nums.end());\n long long int n=nums.size();\n \n\n if(n==1){\n return nums[0];\n };\n \n if(nums[n-1]!=nums[n-2]){\n return num... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int> &nums) {\n std::pmr::unordered_map<int, int> map;\n\n for (int i = 0; i < nums.size(); i++) {\n map[nums[i]] += 1;\n }\n\n for (int i = 0; i < nums.size(); i++) {\n if (map[nums[i]] == 1) {\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n\n if (nums.size() == 1) {\n return nums[0];\n }\n std::set<int> frequency;\n\n for (int i = 0; i < nums.size(); i++) {\n if (frequency.find(nums[i]) == frequency.end()) {\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution { \npublic: \n int singleNumber(vector<int>& nums) { \n set<int> uni; \n for (int i = 0; i < nums.size(); i++){ \n if (uni.find(nums[i]) == uni.end()) { \n uni.insert(nums[i]); \n } else { \n uni.erase(nums[i]); \n... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n std::set<int> uniq;\n for(auto n : nums){\n if(uniq.contains(n))\n uniq.erase(n);\n else\n uniq.insert(n);\n }\n return *uniq.begin();\n }\n};",
"memor... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "#include <vector>\n#include <set>\nusing namespace std;\n\nclass Solution {\npublic:\n int singleNumber(vector<int>& nums)\n {\n // Use a set to find unique numbers\n std::set<int> s(nums.begin(),nums.end());\n \n for (int i : s) {\n int count = 0;\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n set<int> s(nums.begin(),nums.end());\n int setsum=accumulate(s.begin(),s.end(),0);\n int vectorsum=accumulate(nums.begin(),nums.end(),0);\n return 2*setsum-vectorsum;\n \n }\n};",
"memory": "23400"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n set<int> s(nums.begin(),nums.end());\n int setsum=2*accumulate(s.begin(),s.end(),0)-accumulate(nums.begin(),nums.end(),0);\n return setsum;\n \n }\n};",
"memory": "23500"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n=nums.size();\n set<int> s;\n int sum=0;\n for(int i=0;i<n;i++)\n {\n s.insert(nums[i]);\n sum=sum+nums[i];\n }\n int s_sum=0;\n for(auto it=s.begin();it... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = nums.size();\n \n\n unordered_map<int, int> hash;\n \n\n for(int i =0 ; i<n ; i++){\n hash[nums[i]]++;\n }\n\n for(int i =0; i<n;i++){\n if(hash[nums[i]] == ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int,int> f;\n for(int c:nums){\n f[c]++;\n }\n int b=0;\n for(const auto a:f){\n if(a.second==1){\n b+=a.first;\n }\n }\n ret... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n \n int usingXor(vector<int>& nums){\n int ans=0;\n for(int i=0; i<nums.size(); i++){\n \n ans =ans^nums[i];\n }\n\n return ans;\n }\n\n int usingMap(vector<int>& nums){\n unordered_map<int,int> ans;\n\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n \n int usingXor(vector<int>& nums){\n int ans=0;\n for(int i=0; i<nums.size(); i++){\n \n ans =ans^nums[i];\n }\n\n return ans;\n }\n\n int usingMap(vector<int>& nums){\n unordered_map<int,int> ans;\n\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int, int>m;\n if(nums.size()==1)\n return nums[0];\n for(int i=0;i<nums.size();i++){\n m[nums[i]]++;\n }\n for(const auto& a :m){\n if(a.second==1){\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int, int> s;\n for(int num : nums){\n s[num]++;\n }\n for(auto it : s){\n if(it.second == 1){\n return it.first;\n }\n }\n \n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int,int> um;\n for(auto it:nums){\n um[it]++;\n }\n int ans = 0;\n for(auto it=um.begin();it != um.end();it++){\n if(it->second == 1){\n ans = it->fir... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) { \n unordered_map<int,int> a;\n\t for(auto x: nums)\n\t\t a[x]++;\n\t for(auto z:a)\n\t\t if(z.second==1)\n\t\t\t return z.first;\n\t return-1;\n }\n};",
"memory": "24000"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) { \n unordered_map<int,int> a;\n\t for(auto x: nums)\n\t\t a[x]++;\n\t for(auto z:a)\n\t\t if(z.second==1)\n\t\t\t return z.first;\n\t return -1;\n }\n};\n\n \n \n \n",
"memory": "24000"
} |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n // Fast I/O\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n unordered_map<int, int> s;\n for(int num : nums){\n s[num]++;\n }\n for(auto it : s)... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n // Fast I/O\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n unordered_map<int, int> s;\n for(int num : nums){\n s[num]++;\n }\n for(auto it : s)... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n // Fast I/O\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n unordered_map<int, int> s;\n for(int num : nums){\n s[num]++;\n }\n for(auto it : s)... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& arr) {\n map<int,int>mp;\n for(int i=0;i<arr.size();i++)\n {\n mp[arr[i]]++;\n }\n int ans=0;\n for(auto it:mp)\n {\n if(it.second==1)\n {\n ans=it.first;\n }\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = nums.size();\n map <int, int> mpp;\n for(int i = 0; i< n; i++){\n // if(nums[i] == i)\n mpp[nums[i]]++;\n }\n for(auto i:mpp){\n if(i.second == 1)\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int, bool> temp;\n\n for (const auto & num : nums) \n {\n if (temp.find(num) != temp.end())\n {\n temp.erase(num);\n }\n else\n {\n ... |
136 | <p>Given a <strong>non-empty</strong> array of integers <code>nums</code>, every element appears <em>twice</em> except for one. Find that single one.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p>
<p> </p>
<p><strong class="example... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int> f;\n for(int c:nums){\n f[c]++;\n }\n int b=0;\n for(const auto a:f){\n if(a.second==1){\n b+=a.first;\n }\n }\n return b;\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int ones = 0, twos = 0;\n for(const int num : nums){\n ones ^= (num & ~twos);\n twos ^= (num & ~ones);\n }\n return ones;\n }\n};",
"memory": "11800"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int ones = 0;\n int twos = 0;\n\n for(int num : nums){\n twos |= (ones & num);\n ones ^= num;\n\n int mask = ~(ones & twos);\n ones &= mask;\n twos &= mask;\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& arr) {\n int ans =0;\n for(int k=0; k<=31; k++){\n int temp = (1<<k);\n\n int count0 =0;\n int count1 = 0;\n for(auto &it: arr){\n if((it&temp) == 0){\n c... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n \n int result = 0;\n int temp = 0;\n\n for(int k = 0; k <= 31; k++){\n temp = (1 << k);\n int countOnes = 0;\n for(auto i : nums){\n if((i & temp )!= 0){\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n for(int i=1;i<n;i+=3){\n if(nums[i]!=nums[i-1]){\n return nums[i-1];\n }\n }\n return nums[n-1];\n \n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n long long aux = 1;\n for (int i = 0; i < 20; i++) aux *= 3;\n const long long MOD = aux;\n\n vector<int> ans(21, 0);\n for (long long num : nums) {\n if (num < 0) {\n num = MO... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 0 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int ones = 0, twos = 0;\n \n for (int num : nums) {\n twos |= ones & num;\n ones ^= num;\n int common_bit_mask = ~(ones & twos);\n ones &= common_bit_mask;\n twos &= common_bit_mask;\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 1 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& arr) {\n int one = 0,two = 0;\n for(int i = 0;i < arr.size();i++){\n one = (one^arr[i])&(~two);\n two = (two^arr[i])&(~one);\n }\n return one;\n }\n};",
"memory": "12200"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 1 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int answer = 0;\n for(int bitIndex = 0; bitIndex < 32; bitIndex++) {\n int count = 0;\n\n for(int i = 0; i < nums.size(); i++) {\n if(nums[i] & (1 << bitIndex))\n cou... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums){\n int count;\n long long ans=0;\n for(int i=0;i<32;i++){\n count=0;\n for(int j=0;j<nums.size();j++){\n if((1 & nums[j])>0)count++;\n nums[j]=nums[j]>>1;\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n\n for(int i=1;i<nums.size();i+=3){\n if(nums[i-1]!=nums[i+1]) return nums[i-1];\n }\n return nums[nums.size()-1];\n }\n};",
"memory": "12300"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n\n for(int i=1;i<nums.size();i+=3){\n if(nums[i-1]!=nums[i+1]) return nums[i-1];\n }\n return nums[nums.size()-1];\n }\n};",
"memory": "12400"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n for(int i=1; i<n; i += 3) {\n if(nums[i] != nums[i-1]) {\n return nums[i-1];\n }\n }\n return nums[n-1];\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n int k = 1;\n vector<int> b;\n sort(nums.begin(), nums.end());\n\n for (int i = 0; i < nums.size(); ) {\n if (i + 1 < nums.size() && nums[i] == nums[i + 1]) {\n nums.erase(nums.begin(... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n set<int> unique;\n long int sum=0;\n long int unique_sum=0;\n \n for(auto i=nums.begin();i!=nums.end();i++){\n unique.insert(*i);\n sum+=*i;\n }\n\n for(auto i=uniqu... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n long sum1=0;\n long sum2=0;\n for(auto it:nums) sum1+=it;\n\n set<long>st;\n for(auto it:nums) st.insert(it);\n\n for(auto it:st) sum2+=it*3;\n\n return (sum2-sum1)/2;\n \n }\n... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n set<int> digits;\n for (int x : nums) {\n digits.insert(x);\n }\n\n for (int x : digits) {\n cout << x;\n if (count(nums.begin(), nums.end(), x) == 1) {\n retur... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int, int> mp;\n int number;\n for (int i = 0; i < nums.size(); i++)\n {\n if (mp.find(nums[i]) == mp.end())\n mp.insert({nums[i], 1});\n else\n mp[nums[... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n\n map<int, int> hash;\n\n for (int i : nums) {\n hash[i]++;\n }\n\n for (auto i : hash) {\n if (i.second == 1) {\n return i.first;\n }\n }\n\n ret... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int> mp;\n for(auto it: nums) mp[it]++;\n for(auto it : mp) if(it.second==1) return it.first;\n return 0;\n }\n};",
"memory": "13100"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int, int> count;\n for (int i = 0; i < nums.size(); i++){\n count[nums[i]] += 1;\n }\n int result;\n for (auto i: count){\n if(i.second == 1){\n result = i.firs... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int>mp;\n int ans;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n }\n for(auto it: mp){\n if(it.second==1)\n ans= it.first;\n }\n return ans;... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int>mp;\n for(auto x:nums){\n mp[x]++;\n }\n for(auto x:mp){\n if (x.second==1)return x.first;\n }\n return -1;\n }\n};",
"memory": "13300"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int> mp;\n for(int i=0;i<nums.size();i++)\n {\n mp[nums[i]]++;\n }\n int t;\n for(auto it : mp)\n {\n if(it.second==1)\n t= it.first;\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 2 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int> m;\n for(int i=0;i<nums.size(); i++){\n m[nums[i]]++;\n }\n for(auto i:m){\n if(i.second==1) return i.first;\n }\n return 0;\n \n }\n};",
"memory":... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map<int,int> mp;\n for(int i=0; i<nums.size();i++){\n mp[nums[i]]++;\n }\n for(auto it:mp){\n if(it.second==1){\n return it.first;\n }\n }\n retur... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n std::map<int, int> counts;\n for (int i: nums) ++counts[i];\n for (const auto [i, count]: counts) if (count == 1) return i;\n assert(false);\n }\n};",
"memory": "13500"
} |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map <int,int> freq;\n for(auto it:nums){\n freq[it]++;\n }\n vector<pair<int,int>> val;\n for(auto pair: freq){\n val.push_back(pair);\n }\n for(auto it:val){\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n map <int,int> freq;\n for(auto it:nums){\n freq[it]++;\n }\n vector<pair<int,int>> val;\n for(auto pair: freq){\n val.push_back(pair);\n }\n for(auto it:val){\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int,int>mpp;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]++;\n }\n\n for(auto it:mpp){\n if(it.second==1){\n return it.first;\n }\n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int,int>freq;\n for(int i=0;i<nums.size();i++) {\n int num = nums[i];\n freq[num]++;\n }\n for(auto i:freq) {\n if(i.second==1) {\n return i.first... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int, int> m;\n \n for(auto x: nums){\n m[x]++;\n }\n\n for(auto x: m){\n if(x.second == 1){\n return x.first;\n }\n }\n \n ... |
137 | <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
<p>You must implement a solution with a linear runtime complexity and use only constant&nb... | 3 | {
"code": "class Solution {\npublic:\n int singleNumber(vector<int>& nums) {\n unordered_map<int, int> ans;\n for (int i = 0; i < nums.size(); i++) {\n ans[nums[i]]++;\n }\n for (auto it : ans) {\n if (it.second == 1) {\n return it.first;\n ... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* clone(Node* head){\n\tNode* temp=head;\n\twhile(temp){... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n\n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n if (head == NULL)\n ... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n\n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) { \n if(head== nullptr){... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n\n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n if(!head) return hea... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "class Solution {\npublic:\n Node* copyRandomList(Node* head) {\n Node* temp = head;\n\n //insert nodes in between\n while(temp!=NULL) {\n Node* newNode = new Node(temp->val);\n newNode->next = temp->next;\n temp->next = newNode;\n temp = t... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\n void insertCopyInBetween(Node* head){\n Node* temp = head;\n ... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n if (!head) {\n ... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n void insertBetween(Node* head){\n Node* temp=head;\n \n whi... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n\n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n unordered_map<Node*,... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n if (head == null... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n\n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n unordered_map<Node*,... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n if (head == null... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n if(!head){\n ... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n\n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n unordered_map<Node*,... |
138 | <p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ... | 2 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) \n {\n unordered_... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.