id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
0
{ "code": "class Solution {\npublic:\n int thirdMax(std::vector<int>& nums) {\n // Step 1: Sort the array\n std::sort(nums.begin(), nums.end());\n \n // Step 2: Remove duplicates\n nums.erase(std::unique(nums.begin(), nums.end()), nums.end());\n \n // Step 3: Check ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
0
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n \n int n= nums.size();\n \n pair<int, int>fm= {INT_MIN, -1};\n pair<int, int>sm= {INT_MIN, -1};\n pair<int, int>tm= {INT_MIN, -1};\n \n for(int i=0; i<n; i++)\n {\n i...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
1
{ "code": "class Solution {\npublic:\n int thirdMax(std::vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n nums.erase(std::unique(nums.begin(), nums.end()), nums.end());\n if (nums.size() < 3) {\n return nums.back();\n }\n return nums[nums.size() - 3];\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
1
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n int i = nums.size() - 1;\n int j = 2;\n // if (i < 2) {\n // return nums[i];\n // }\n int res_max = 0;\n for (; i > 0 && j; --i) {\n if (nums[i - 1] !...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
1
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n // Check the trivial cases\n if(nums.size()==1) return nums[0];\n if(nums.size()==2) return nums[0]>nums[1]?nums[0]:nums[1];\n \n //arrange them\n int temp,result;\n for(int i =0 ;i<nums.size...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
1
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n sort(nums.begin(), nums.end(), greater<int>());\n int distinct=nums[0] ;\n int count=1;\n int max=nums[0];\n for(int i=1;i<nums.size();i++){\n if(distinct!=nums[i]){\n distinct=nums[i]...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n list<int> l;// = {INT_MIN, INT_MIN, INT_MIN};\n for (int num : nums) {\n auto iter = l.begin();\n for (; iter != l.end(); ++iter) {\n if (num == *iter) break;\n if (num > *it...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) \n {\n int flag[nums.size()];\n vector<int>arr;\n for(int i=0;i<nums.size();i++)\n {\n int c=1;\n for(int j=i+1;j<nums.size();j++)\n {\n if(nums[i]==nums[j])\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n sort(nums.begin(),nums.end(),greater<int>());\n vector<int>nums1;\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i]!=nums[i+1]){\n nums1.push_back(nums[i]);\n }\n }\n nu...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n int len=nums.size();\n vector<int> unique;\n int max=INT_MIN;\n if(len==1) return nums[0];\n sort(nums.begin(),nums.end());\n int j=0;\n if(len>2)\n {\n for(int i=0;i<len;i+...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "#include <limits>\n\nconst int down_infinity = std::numeric_limits<int>::min();\n\nclass Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n unordered_set<int> used;\n int max = down_infinity, max2 = down_infinity, max3 = down_infinity;\n bool maxSet = false, max2Set = false, ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "#include <limits>\n\nconst int down_infinity = std::numeric_limits<int>::min();\n\nclass Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n unordered_set<int> used;\n int max = down_infinity, max2 = down_infinity, max3 = down_infinity;\n bool maxSet = false, max2Set = false, ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n priority_queue<int , vector<int> , greater<int> > minheap;\n vector<int> values;\n\n minheap.push(nums[0]);\n values.push_back(nums[0]);\n int flag = true;\n for( int i = 1; i < nums.size(); i++){\n...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n vector<int> res{nums[0]};\n for (int num: nums) {\n bool found = false;\n for (int a : res) {\n if (a == num) {\n found = true;\n break;\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n priority_queue<int, vector<int>, greater<int>> minHeap;\n unordered_set<int> visited;\n\n for (int i = 0; i < nums.size(); i++) {\n if (visited.count(nums[i])) {\n continue;\n }\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\nprivate:\n std::vector<int> maxNums;\n int count;\n void appendMax(int num)\n {\n switch(count)\n {\n case 0:\n maxNums[0] = num;\n count++;\n break;\n case 1:\n if (maxNums[0] != n...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int> UniqueNumber(nums.begin(),nums.end());\n auto it = UniqueNumber.rbegin();\n if(UniqueNumber.size()<3)\n return *it;\n else\n {\n advance(it,2);\n return *it;\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int> s;\n for(int i=0;i<nums.size();i++)\n {\n s.insert(nums[i]);\n }\n auto it=s.rbegin();\n if(s.size()<3)\n {\n return *it;\n }\n advance(it, 2);\n...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n priority_queue<int> pq;\n for(int i = 0; i < nums.size(); i++) {\n pq.push(nums[i]);\n }\n \n set<int> numset;\n while(!pq.empty() && numset.size() < 3) {\n numset.insert(pq.to...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int> distinct;\n for (int num : nums) {\n distinct.insert(num);\n if (distinct.size() > 3) {\n distinct.erase(distinct.begin());\n }\n }\n if (distinct.size() =...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int>d;\n for(int num:nums){\n d.insert(num);\n }\n if(d.size()<3){\n return *d.rbegin();\n }\n auto it=d.rbegin();\n advance(it,2);\n return *it;\n }\n};",...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int> s;\n bool f=0;\n for(int i : nums){\n if(i==-2147483648) f=1;\n s.insert(i);\n }\n for(int i : s) cout<<i<<\" \";\n\n if(s.size()==2){\n int a=INT_MIN;\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
2
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int> s; \n for(auto num:nums) s.insert(num);\n auto it = s.rbegin();\n if(s.size() > 2) advance(it,2);\n /*cout<<*it<<endl;\n // Check the trivial cases\n if(nums.size()==1) return nums[0...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n set<int>s;\n for(int i=0;i<nums.size();i++){\n s.insert(nums[i]);\n }\n if(s.size()>=3){\n int thirdmax =s.size()-3;\n auto third_max=next(s.b...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n set<int> map(nums.begin() , nums.end());\n\n vector<int> ans(map.begin() , map.end());\n\n sort(ans.begin() , ans.end());\n\n if(ans.size() < 3){\n return ans[ans.size() - 1];\n }\n retur...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n set<int> s(nums.begin(),nums.end());\n int i=0;\n for(auto x:s)\n {\n nums.push_back(x);\n }\n int n=nums.size();\n if(nums.size()<3)\n {\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n \n int n = nums.size();\n if (n == 1) return nums[0];\n if (n == 2) return max(nums[0], nums[1]);\n\n priority_queue<int, vector<int>, std::greater<int>> min_heap;\n unordered_set<int> unique; // g...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n unordered_map<int,int>m;bool flag=0;\n priority_queue<int,vector<int>,greater<int>>pq;\n int mx=INT_MIN;\n for(int i=0;i<nums.size();i++){\n if(m.find(nums[i])==m.end()){\n pq.push(nums[i...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n \n unordered_set<int> s(nums.begin(), nums.end());\n\n // Initialize three variables to track the top three distinct maximums\n long first = LONG_MIN;\n long second = LONG_MIN;\n long third = LONG_M...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n unordered_set<int> s(nums.begin(), nums.end());\n\n priority_queue<int> pq;\n\n for(int i:s){\n pq.push(i);\n }\n\n if(s.size() < 3)\n return pq.top();\n\n int count = 0;\n\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n int max1=INT_MIN;\n int max2=INT_MIN;\n int max3=INT_MIN;\n int sz=nums.size();\n unordered_set<int> s;\n for(auto nums:nums){\n s.insert(nums);\n }\n for(int i=0;i<sz;i++){...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n unordered_set<int>s1;\n for(auto &it:nums){\n s1.insert(it);\n } \n vector<int>ans(s1.begin(),s1.end());\n sort(ans.begin(),ans.end());\n if (ans.size() >= 3) {\n return ans[ans.size() -...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n unordered_set<int> set(nums.begin(),nums.end());\n vector<int> num1(set.begin(),set.end());\n sort(num1.begin(), num1.end(), greater<int>());\n if(num1.size()>=3){\n return num1[2];\n }\n ...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n priority_queue<int, vector<int>, greater<int>> minHeap;\n set<int> s;\n for(auto i: nums){\n s.insert(i);\n }\n if(s.size()<3){\n return *(s.rbegin());\n }\n for(auto i:...
414
<p>Given an integer array <code>nums</code>, return <em>the <strong>third distinct maximum</strong> number in this array. If the third maximum does not exist, return the <strong>maximum</strong> number</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,2...
3
{ "code": "class Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n int n=nums.size();\n unordered_set<int>s;\n for(int i=0;i<n;i++){\n s.insert(nums[i]);\n }\n vector<int>ans;\n for(auto el:s){\n ans.push_back(el);\n } \n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
0
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int size1=num1.size()-1;\n int size2=num2.size()-1;\n int carry=0;\n string ans;\n while(size1>=0 || size2>=0 || carry){\n int n1=(size1>=0)?num1[size1]-'0':0;\n int n2=(size2>=0)?num2[size2]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
0
{ "code": "class Solution {\npublic:\n void solve(string &num1, string &num2, int p1, int p2, int carry, string &ans){\n\n if(p1<0 && p2<0){\n if(carry != 0){\n ans.push_back(carry + '0');\n }\n return;\n \n }\n \n int n1 = (p1 >= 0 ? n...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
2
{ "code": "#include <iostream>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string addStrings(string num1, string num2) {\n string result = \"\";\n int i = num1.size() - 1, j = num2.size() - 1, carry = 0;\n\n // Loop through both strings from the last character\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
2
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n reverse(num1.begin() , num1.end());\n reverse(num2.begin() , num2.end());\n string ans = \"\";\n int i = 0; \n int j = 0;\n int carry = 0;\n while(i<num1.size() && j< num2.size())...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(string &num1, string &num2, int i, int j, int c, string &op){\n if(i<0 && j<0){\n if(c!=0){\n op+=c+'0';\n }\n return;\n }\n \n int no1 = (i>=0)? (num1[i]-'0'):0;\n int no2 = (j>=0)?...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(string &num1, string &num2, int i, int j, int c, string &op){\n if(i<0 && j<0){\n if(c!=0){\n op+=c+'0';\n }\n return;\n }\n \n int no1 = (i>=0)? (num1[i]-'0'):0;\n int no2 = (j>=0)?...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int len1 = num1.length() , len2 = num2.length();\n if(len2>len1) for(int i = 0 ; i < len2-len1;i++) num1 = '0' + num1;\n else if(len1>len2) for(int i = 0 ; i < len1-len2;i++) num2 = '0' + num2;\n int ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n string ans=\"\";\n while(num1.size()<num2.size())\n {\n num1=\"0\"+num1;\n }\n while(num1.size()>num2.size())\n {\n num2=\"0\"+num2;\n }\n int c=0;\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int carry = 0;\n int n = num1.size();\n int m = num2.size();\n int sum = 0;\n while(n>m){\n num2 = \"0\" + num2;\n m++;\n }\n while(n<m){\n num1 =...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n bool carry = false;\n string sum = \"\";\n int t;\n while (num1.size() < num2.size()) {\n num1 = \"0\" + num1;\n }\n while (num1.size() > num2.size()) {\n num2 = \"...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n if (num1.size() < num2.size()) {\n swap(num1, num2);\n }\n while (num2.size() < num1.size()) {\n num2 = \"0\" + num2;\n }\n num1 = \"0\" + num1;\n num2 = \"0\" + nu...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(int i,int carry,string &num1,string &num2,string &ans){\n if(i<0){\n if(carry==0){\n return;\n }\n ans.push_back(carry+'0');\n return;\n }\n int x=num1[i]-'0';\n int y=num2[i]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(int i,int carry,string &num1,string &num2,string &ans){\n if(i<0){\n if(carry==0){\n return;\n }\n ans.push_back(carry+'0');\n return;\n }\n int x=num1[i]-'0';\n int y=num2[i]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int len1 = num1.size();\n int len2 = num2.size();\n \n string ret;\n int i1 = num1.size() - 1;\n int i2 = num2.size() - 1;\n int carryOn = 0;\n while (i1 >= 0 && i2 >= 0) {...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int len1 = num1.size();\n int len2 = num2.size();\n \n string ret;\n int i1 = num1.size() - 1;\n int i2 = num2.size() - 1;\n int carryOn = 0;\n for (; i1 >= 0 && i2 >= 0; )...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n string ans = \"\";\n int i = num1.size()-1;\n int j = num2.size()-1;\n int carry = 0;\n while(i >=0 && j>=0){\n int a = num1[i] - '0';\n int b = num2[j] - '0';\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int i = num1.size() - 1, j = num2.size() - 1, carry = 0;\n string result = \"\";\n\n while (i >= 0 || j >= 0 || carry > 0) {\n int digit1 = (i >= 0) ? num1[i--] - '0' : 0;\n int digit2 = (j >= 0) ? n...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n string result = \"\";\n int carry = 0;\n int i = num1.size() - 1;\n int j = num2.size() - 1;\n while (i >= 0 || j >= 0 || carry) {\n int sum = carry;\n if (i >= 0) sum += ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n long long n1=num1.size()-1;\n long long n2= num2.size()-1;\n \n string ans=\"\";\n long long carry =0;\n while(n1>=0 || n2>=0 || carry){\n \n long long sum=carry;\...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int m = num1.size(), n = num2.size();\n int i = m-1, j = n-1;\n int carry = 0;\n string res = \"\";\n while (i >= 0 || j >= 0 || carry) {\n int sum = carry;\n if (i >= 0) ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int i = num1.size() - 1, j = num2.size() - 1, carry = 0;\n string result = \"\";\n\n while (i >= 0 || j >= 0 || carry > 0) {\n int digit1 = (i >= 0) ? num1[i--] - '0' : 0;\n int digit2 ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution \n{\n public:\n string add(string num1,string num2)\n { \n string ans;\n int index1=num1.size()-1;\n int index2=num2.size()-1;\n int sum=0;\n // sum ek ek char ka sum krega\n int car...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int index1=num1.size()-1;\n int index2=num2.size()-1;//smaller number\n int sum=0,carry=0;\n string ans=\"\";\n char ch;\n while(index2>=0 && index1>=0){\n sum=(num1[index1]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string solve(string str1,string str2){\n int idx1 = str1.size()-1;\n int idx2 = str2.size()-1;\n string ans;\n int sum = 0;\n int carry = 0;\n while(idx2>=0){\n sum = str1[idx1]-'0' + str2[idx2]-'0'+carry;\n char...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n string ans=\"\";\n int n1=num1.size()-1,n2=num2.size()-1;\n char carry='0';\n while(n1>=0 && n2>=0){\n int sum=(num1[n1]-'0')+(num2[n2]-'0')+(carry-'0');\n if(sum>9){\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string add(string num1 , string num2){\n int zyada=0;\n int n1=num1.size()-1;\n int n2=num2.size()-1;\n string ans;\n int sum;\n while( n2>= 0)\n {\n sum=num1[n1--]-'0'+ num2[n2--]-'0' +zyada;\n char c = '...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string add(string num1, string num2){\n int index1 = num1.size()-1;\n int index2 = num2.size()-1;\n string ans;\n int carry=0,sum;\n while(index2 >= 0){\n sum = ((num1[index1]-'0') + num2[index2]-'0') + carry;\n carry =...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string add(string num1, string num2)\n {\n int index1=num1.size()-1, index2=num2.size()-1;\n string ans;\n int carry=0, sum;\n \n while(index2>=0)\n {\n sum=(num1[index1]-'0')+(num2[index2]-'0')+carry;\n carry...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\n vector<int> stringToVec(const string& num) {\n vector<int> v(num.size());\n for (int i = 0; i < num.size(); ++i) {\n v[i] = num[i] - '0';\n }\n return v;\n }\npublic:\n string addStrings(string num1, string num2) {\n vector<int> v1 =...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string solve(string& num1, string& num2, int p1, int p2, int carry){\n\n //base case\n if(p1 < 0 && p2 < 0){\n if(carry != 0){\n return string(1,carry + '0');\n }\n return \"\";\n }\n \n //ek case ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n\n string addRE(string& num1,int p1,string& num2,int p2,int carry=0){\n //base case\n if(p1 < 0 && p2 < 0){\n if(carry != 0){\n return string(1,carry + '0');\n }\n return \"\";\n }\n //1st case\n int n1=(p1>=0?num1[p1]:'0')-'0';\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n while(num1.size()<num2.size())\n num1='0'+num1;\n while(num2.size()<num1.size())\n num2='0'+num2;\n string ans;\n int hold = 0, sum;\n for (int i = num1.size()-1;i>=0;i--)...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int l1=num1.size();\n int l2=num2.size();\n while(l1<l2) {\n l1++;\n num1='0'+num1;\n }\n while(l2<l1) {\n l2++;\n num2='0'+num2;\n }\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n string ans = \"\";\n int tmp = 0;\n int _max_length = max(num1.size(), num2.size());\n while(num1.size() != _max_length) {\n num1 = \"0\" + num1;\n }\n while(num2.size() != _m...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n int n1 = num1.size();\n int n2 = num2.size();\n int n = max(n1, n2);\n \n for (int i = n1; i < n; i++) {\n num1 = \"0\" + num1;\n }\n \n for (int i = n2; i < n; ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n if(num1.size()<num2.size())return addStrings(num2, num1);\n int d = num1.size()-num2.size();\n string ans=\"\";\n char carry='0';\n for(int i=0; i<d; i++)num2 = \"0\" + num2;\n for(int i...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n if(num1.size()<num2.size())return addStrings(num2, num1);\n int d = num1.size()-num2.size();\n string ans=\"\";\n int carry=0;\n for(int i=0; i<d; i++)num2 = \"0\" + num2;\n for(int i=nu...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string func(string num1, string num2){\n int d = num1.size()-num2.size();\n string ans=\"\";\n char carry='0';\n for(int i=0; i<d; i++)num2 = \"0\" + num2;\n for(int i=num1.size()-1; i>=0; i--){\n char temp = '0' + ((((num1[i]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string func(string num1, string num2){\n int d = num1.size()-num2.size();\n string ans=\"\";\n char carry='0';\n for(int i=0; i<d; i++)num2 = \"0\" + num2;\n for(int i=num1.size()-1; i>=0; i--){\n char temp = '0' + ((((num1[i]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string func(string num1, string num2){\n int d = num1.size()-num2.size();\n string ans=\"\";\n char carry='0';\n for(int i=0; i<d; i++)num2 = \"0\" + num2;\n for(int i=num1.size()-1; i>=0; i--){\n char temp = '0' + ((((num1[i]-'0...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n while(num1.length() != num2.length()){\n if(num1.length() < num2.length()){\n num1 = \"0\" + num1;\n }\n else{\n num2 = \"0\" + num2;\n }\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n string ans=\"\";\n while(num1.size() != num2.size()){\n if(num1.size() > num2.size()){\n num2 = '0' + num2;\n }else{\n num1 = '0' + num1;\n }\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\nstring addRE(string &num1,int p1,string &num2,int p2,int carry=0){\n //base case\n if(p1<0 && p2<0){\n if(carry!=0){\n return string(1,carry+'0');\n }\n else{\n return \"\";\n }\n }\n //ek case solve kr deta hoon\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\nprivate:\n string addRE(string &num1, string &num2, int p1, int p2, int carry=0){\n\n if(p1 < 0 && p2 < 0 && carry == 0){ return \"\"; }\n\n int n1 = (p1 >= 0 ? num1[p1] : '0') - '0';\n int n2 = (p2 >= 0 ? num2[p2] : '0') - '0';\n \n int total = n1 + ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void addRE(string&num1,int p1,string num2, int p2,int carry,string&ans){\n // bc\n if(p1<0 && p2<0){\n if(carry != 0){\n ans.push_back(carry+'0');\n }\n return;\n }\n // processing\n int n1 = ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void addRE(string &num1, int p1, string num2, int p2,int carry, string &ans){\n // base case\n if(p1<0 &&p2 <0){\n if(carry!=0){\n ans.push_back(carry+'0');\n \n }\n return;\n }\n\n //p...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n\n void solve(string &num1,string num2,int i,int j,int carry,string &ans){\n\n //Base case\n if(i>=num1.length() && j>=num2.length() && carry==0){\n return;\n }\n\n //Ek case mai solve karungaa baaki recursion karungaa\n\n int firs...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addRE(string& num1, int p1, string& num2,int p2, int carry, string& ans){\n //base case\n if(p1<0 && p2 <0){\n if(carry!=0){\n ans.push_back(carry + '0');\n }\n return \"\";\n }\n\n //ek case s...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\n //using recursion\npublic:\n\n string addRE(string& num1, int p1, string& num2, int p2, int carry,string& ans){\n //base case\n if(p1<0 && p2<0){\n if(carry!=0){\n // return string(1,carry+'0');\n ans.push_back(carry+'0');\n }\n r...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string result;\n void helper(string num1, string num2, int n1, int n2, int carry){\n if(n1 < 0 && n2 < 0){\n if(carry){\n result += char(carry+'0');\n }\n return;\n }\n\n\n if(n1<0 || n2 < 0){\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(int &e1, int &e2, string &ans, int &carry,string num1, string num2)\n {\n if(e1<0 || e2<0)\n {\n return;\n }\n int a1=num1[e1]-'0';\n int a2=num2[e2]-'0';\n ans.push_back(((a1+a2+carry)%10)+'0');\n carr...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n // string solve(string num1, int p1, string num2, int p2, int carry=0){\n // //base case\n // if(p1<0 && p2<0){\n // if(carry != 0){\n // return string(1,carry+'0');\n // }\n // return \"\";\n // }\n // ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n\n //FUNCTION FOR SOLVING USING RECURSION:\n string solveUsingRecursion(string& num1,int p1,string& num2,int p2,int carry)\n {\n //BASE CASE:\n if(p1<0 && p2<0)\n {\n if(carry!=0)\n {\n return string(1,carry+'0');...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string solve(string &num1, string &num2,string ans,int carry, int i, int j)\n {\n\n // base case\n \n if(j<0 && i <0)\n {\n if(carry)\n ans.push_back(carry +'0');\n reverse(ans.begin(), ans.end());\n return ans;\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string addRE(string& num1,string& num2,int i,int j,int ans = 0,int carry = 0,string str = \"\") {\n if(i < 0 && j < 0) {\n if(carry != 0) {\n str.push_back(carry + '0');\n carry = 0;\n }\n reverse(str.b...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\nprivate:\n string addRE(string &num1, string &num2, int p1, int p2, int carry=0){\n\n if(p1 < 0 && p2 < 0 && carry == 0){ return \"\"; }\n\n int n1 = (p1 >= 0 ? num1[p1] : '0') - '0';\n int n2 = (p2 >= 0 ? num2[p2] : '0') - '0';\n \n int total = n1 + ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\nprivate:\n string addRE(string &num1, string &num2, int p1, int p2, int carry=0){\n\n if(p1 < 0 && p2 < 0 && carry == 0){ return \"\"; }\n\n int n1 = (p1 >= 0 ? num1[p1] : '0') - '0';\n int n2 = (p2 >= 0 ? num2[p2] : '0') - '0';\n \n int total = n1 + ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string summation(string &s1, string &s2, int i, int j, int carry, string sum){\n // base case\n if(i < 0 && j < 0){\n if(carry > 0)\n sum += to_string(carry); \n reverse(sum.begin(), sum.end());\n return sum;\n ...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n string add(string& num1, string& num2, string& s, int i, int j, int c){\n if(i < 0 && j < 0 && c == 0){\n return \"\";\n }\n int n1, n2;\n if(i >= 0)\n n1 = num1[i] - '0';\n else\n n1 = 0;\n if(j >= 0)...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(string num1, string num2, int p1, int p2, int carry, string &ans){\n\n if(p1<0 && p2<0){\n if(carry != 0){\n ans.push_back(carry + '0');\n }\n return;\n \n }\n \n int n1 = (p1 >= 0 ? num...
415
<p>Given two non-negative integers, <code>num1</code> and <code>num2</code> represented as string, return <em>the sum of</em> <code>num1</code> <em>and</em> <code>num2</code> <em>as a string</em>.</p> <p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger...
3
{ "code": "class Solution {\npublic:\n void solve(string a, string b, int carry, string & ans, int i, int j){\n if(i<0 && j<0 && carry==0){\n return;\n }\n int fi=0,se=0;\n if(i>=0){\n fi=a[i]-'0';\n }\n if(j>=0){\n se=b[j]-'0';\n }\...
416
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:<...
0
{ "code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int n = nums.size(), sum = 0;\n for (int i = 0; i < n; i++) {\n sum += nums[i];\n }\n if (sum % 2 == 1) return false;\n sum /= 2;\n bool subsetSum[sum+1];\n memset(subsetSum, ...
416
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:<...
0
{ "code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int sum=accumulate(nums.begin(),nums.end(),0);\n if(sum%2==1) return false;\n bool dp[sum/2+1];\n memset(dp,false,sizeof dp);\n dp[0]=true;\n for(int i=0;i<nums.size();i++){\n for(in...
416
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:<...
0
{ "code": "class Solution {\n // for other solution of this u can refer to sam equestion in gfg.\n private:\n // optimizing space\n bool solveSO(int N, vector<int>& nums, int total){\n \n vector<int> curr(total+1, 0);\n vector<int> next(total+1, 0);\n \n curr[0] = 1;\n ...
416
<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:<...
0
{ "code": "class Solution {\nprivate:\n bool solveSO(int index,vector<int>& nums,int n,int total)\n {\n vector<int> curr(total+1,0);\n vector<int> next(total+1,0);\n curr[0]=1;\n next[0]=1;\n\n\n\n for(int index=n-1;index>=0;index--)\n {\n for(int target...