id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n set<int> s(nums.begin(), nums.end());\n int ans=1;\n for(int i:s){\n if(i>0){\n if(i==ans){\n ... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n set<int> s;\n for(int i:nums){\n if(i>0){\n s.insert(i);\n }\n }\n int ans=1;\n for(in... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n set<int> ns (nums.begin(), nums.end());\n int i = 1;\n while (ns.contains(i++));\n return --i;\n }\n};",
"memory": "71380"
} |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n set<int> ns (nums.begin(), nums.end());\n int i = 1;\n while (ns.contains(i++));\n return --i;\n }\n};",
"memory": "72266"
} |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n \n set<int> s;\n \n for(int i=0;i<nums.size();i++)\n {\n s.insert(nums[i]);\n }\n \n int a = *s.rbegin();\n \n for(int i=1;i<=a;i++)\n {\n ... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n set<int> s(nums.begin(), nums.end());\n int ans=1;\n for(int i:s){\n if(i>0){\n if(i==ans){\n ans++;\n }else{\n break;\n ... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "auto init = []() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n map<int,int> map;\n for(int num:nums){\n map[num]++;\n }\n int i=1;\n whil... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n map<int,int> mpp;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n mpp[nums[i]]++;\n }\n }\n int a=1;\n for(auto it:mpp){\n if(it.first!=a){\... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n map<int, int> list;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>0)\n list[nums[i]]++;\n }\n for(int i=1;i<=list.size();i++)\n {\n if(list[i] ==... |
41 | <p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p>
<p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n map<int,int>ai;\n for(auto i:nums){\n if(i>0){\n ai[i]=1;\n }\n }\n int c;\n for(c=1;c<=ai.size();c++){\n if(ai[c]==0) return c;\n }\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "int init = [] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n for (string s; getline(cin, s);) {\n vector<int> height;\n for (int _i = 0, _n = s.length(); _i < _n;) {\n int num = 0;\n while (_i < _n && (s[_i] & 15) < 10)... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "int init = [] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n for (string s; getline(cin, s);) {\n vector<int> height;\n for (int _i = 0, _n = s.length(); _i < _n;) {\n int num = 0;\n while (_i < _n && (s[_i] & 15) < 10)... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "int init = [] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n for (string s; getline(cin, s);) {\n vector<int> height;\n for (int _i = 0, _n = s.length(); _i < _n;) {\n int num = 0;\n while (_i < _n && (s[_i] & 15) < 10)... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int left=0,right=height.size()-1;\n int left_max=0,right_max=0;\n int water=0;\n while(left<right)\n {\n if(height[left]<height[right])\n {\n if(height[left]>=left_max)\n... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int left = 0;\n int right = height.size() - 1;\n int leftMax = height[left];\n int rightMax = height[right];\n int water = 0;\n\n while (left < right) {\n if (leftMax < rightMax) {\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int left = 0;\n int right = height.size() - 1;\n int total = 0;\n int maxLeft = 0;\n int maxRight = 0;\n\n while(left < right){\n if(height[left]<=height[right]){\n if(maxLef... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int lMax = 0,rMax = 0, total = 0;\n int l = 0,r = height.size()-1;\n while(l < r)\n {\n if(height[l] <= height[r])\n {\n if(lMax > height[l])\n {\n total +... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": " class Solution {\npublic:\n int trap(vector<int>& height) {\n int left = 0;\n int right = height.size() - 1;\n int leftMax = height[left];\n int rightMax = height[right];\n int water = 0;\n\n while (left < right) {\n if (leftMax < rightMax) {\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n=height.size();\n int left=0;\n int leftMax=0;\n int right=n-1;\n int rightMax=height[n-1];\n int ans=0;\n while(left<=right)\n {\n if(height[left]<=height[right])\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n // int trap(vector<int>& height) {\n // int n =height.size();\n // vector<int> prefix(n, 0);\n // vector<int> suffix(n, 0);\n // prefix[0] = height[0];\n // for(int i = 1; i < n; i++) {\n // prefix[i] = max(height[i], prefix[i-1])... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n // int n=height.size();\n\n // vector<int> pmax(n);\n // pmax[0]=height[0];\n // vector<int> nmax(n);\n // nmax[n-1]=height[n-1];\n\n // for(int i=1;i<height.size();i++){\n // pmax[i]=max(p... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n=height.size()-1;\n int leftmax=0,rightmax=0,maxheight=height[0],ans=0,index=0;\n for(int i=1;i<=n;i++){\n if(height[i]>maxheight){\n maxheight=height[i];\n index=i;\n }\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n= height.size();\n int pref[n],suff[n];\n pref[0]=height[0];\n for(int i=1; i<n; i++){\n pref[i]= max(pref[i-1], height[i]);\n }\n suff[n-1]=height[n-1];\n for(int i=n-2; ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n int left[n];\n int right[n];\n left[0] = height[0];\n\n for(int i=1; i<n; i++){\n left[i] = max(left[i-1], height[i]);\n }\n right[n-1] = height[n-1];\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& a) {\n int ans = 0;\n stack<pair<int,int>> st;\n for (int i = 0; i < a.size(); i++) {\n while(!st.empty() && st.top().first <= a[i]) {\n int height = st.top().first;\n st.pop();\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n vector<int> leftMax(height.size());\n vector<int> rightMax(height.size());\n int maxy=0;\n for (int i =0; i<height.size(); i++)\n {\n maxy = max(maxy, height[i]);\n leftMax[i] = maxy;\n... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n int sum = 0;\n stack<int> st;\n for(int i = 0 ; i < n ; i++) {\n while(!st.empty() && height[st.top()] < height[i]) {\n int curr = st.top();\n st.po... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n int *leftmax = new int[n];\n int *rightmax = new int[n];\n leftmax[0]=height[0];\n rightmax[n-1]=height[n-1];\n for(int i=1; i<n; i++)\n {\n leftmax[i] = max... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n\n int n = height.size();\n vector<int> left(n);\n vector<int> right(n);\n\n left[0] = height[0];\n for(int i = 1; i < n; i++){\n left[i] = max(left[i-1], height[i]);\n }\n\n right[n-... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 0 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n vector<int> leftMax(n,0), rightMax(n,0);\n for (int i = 1; i < n; ++i) \n leftMax[i] = max(height[i-1], leftMax[i-1]);\n for (int i = n-2; i >= 0; --i) \n rightMax[i] ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& arr) {\n int n = arr.size();\n // left max\n vector<int> pm(n),nm(n);\n int mx = -1;\n for(int i=0;i<n;i++){\n pm[i] = mx;\n mx=max(mx,arr[i]);\n }\n mx = -1;\n for(int i=n-1;i... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n stack<pair<int, int>> st;\n int ans = 0;\n\n for(int i = 0; i<height.size(); i++){\n int a = 0;\n // cout<<\"val of i: \"<<i<<\"\\n\";\n while(!st.empty() && st.top().second <= height[... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n vector<int> left(n);\n vector<int> right(n);\n vector<int> ans(n);\n int lmax=0;\n int rmax=0;\n \n left[0] = height[0];\n for(int i=1;i<n;i++){\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n vector<int> left(n);\n vector<int> right(n);\n vector<int> ans(n);\n int lmax=0;\n int rmax=0;\n \n left[0] = height[0];\n for(int i=1;i<n;i++){\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n vector<int> maxl(height.size()), maxr(height.size());\n int v = height[0];\n\n maxl.push_back(0);\n for(int i = 1; i < height.size(); i++) {\n maxl[i] = v;\n //cout << maxl[i] << \" \";\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int hgt = 0;\n struct HeightPos {\n int p;\n int h;\n };\n auto heightPosCmp = [](const HeightPos& hp1, const HeightPos& hp2) -> bool { return hp1.h > hp2.h; };\n\n priority_queue<Heigh... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int hgt = 0;\n struct HeightPos {\n int p;\n int h;\n };\n auto heightPosCmp = [](const HeightPos& hp1, const HeightPos& hp2) -> bool { return hp1.h > hp2.h; };\n\n priority_queue<Heigh... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n vector<int> left(height.size(), 0);\n vector<int> right(height.size(), 0);\n\n stack<int> ls;\n stack<int> rs;\n\n int ans=0;\n for(int i = height.size()-1; i>=0; i--){\n if(rs.empty()){\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n vector<int> left(height.size(), 0);\n vector<int> right(height.size(), 0);\n\n stack<int> ls;\n stack<int> rs;\n\n int ans=0;\n for(int i = height.size()-1; i>=0; i--){\n if(rs.empty()){\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n auto result = 0;\n \n if(height.size() < 1) {\n return result;\n }\n\n size_t left = 0, right = height.size() -1, current = 0;\n int max_left_value = height.at(left), max_right_value = heig... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n if (n < 3) return 0; // Early return if there's no space for trapping water\n \n int left = 0, right = n - 1;\n int left_max = height[left]... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n /*\n int trapped = 0; \n vector <int> maxLeft; \n vector<int> maxRight (height.size()); \n\n int l= 0; \n\n for (int i {}; i < height.size(); i++){\n maxLeft.push_back(l);\n l = ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n if (height.size()<2)\n {\n return 0;\n }\n int startIndex = 0;\n while (height[startIndex]==0)\n {\n startIndex++;\n }\n int max = height[startIndex];\n int ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int waterTrapped = 0;\n int n = height.size();\n int left=0;\n int right = n-1;\n int leftMax=0;\n int rightMax=0;\n\n while(left<=right){\n if(height[left]<=height[right]){\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n=height.size();\n int leftmax=0, rightmax=0;\n int maxheight, index, water=0;\n \n for (int i=0; i<n; i++)\n {\n if (height[i]>maxheight)\n {\n maxheight= hei... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int height_size = height.size();\n int left_max = height[0];\n int right_max = height[height_size-1];\n int left = 0;\n int right = height_size-1;\n int result = 0;\n while(left < right)\n {\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int left = 0;\n int right = height.size() - 1;\n int leftMax = height[left];\n int rightMax = height[right];\n int water = 0;\n\n while (left < right) {\n if (leftMax < rightMax) {\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 1 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n\n // O(N) time and O(N) space\n // two arrays method\n // int n = height.size();\n // if (n == 0) return 0;\n \n // vector<int> left(n);\n // vector<int> right(n);\n \n // // Fill... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int left= 0;\n int right = height.size() - 1;\n int maxR = height[right];\n int maxL = height[left];\n int water = 0;\n\n while(left < right) {\n if(maxL < maxR) {\n left++;\n m... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int total = 0;\n int lmax = 0;\n int n = height.size();\n int rmax = 0;\n int l = 0;\n int r = n-1;\n while(l<r){\n if(height[l] <= height[r]){\n if(lmax > height[l]){... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n=height.size();\n int prefix[n];\n int suffix[n];\n int total=0;\n prefix[0]=height[0];\n suffix[n-1]=height[n-1];\n for(int i=1;i<n;i++){\n prefix[i]=max(prefix[i-1],height[i])... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n=height.size();\n int leftMax[n];\n int rightMax[n];\n leftMax[0]=height[0];\n rightMax[n-1]=height[n-1];\n for(int i=1 ,j=n-2;i<n,j>=0;i++,j--){\n leftMax[i]=max(leftMax[i-1],height[i... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& h) {\n \n int leftmax[h.size()];\n leftmax[0]=0;\n for(int i=1;i<h.size();i++){\n leftmax[i]=max(leftmax[i-1],h[i-1]);\n }\n int rightmax[h.size()];\n rightmax[h.size()-1]=0;\n for(int ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\nint trap(vector < int > & arr) {\n int n = arr.size();\n int prefix[n], suffix[n];\n prefix[0] = arr[0];\n for (int i = 1; i < n; i++) {\n prefix[i] = max(prefix[i - 1], arr[i]);\n }\n suffix[n - 1] = arr[n - 1];\n for (int i = n - 2; i >= 0; i--) {\n suffix[i] = max... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n // int trap(vector<int>& arr){\n // int i=0;\n // int j =arr.size()-1;\n // int lm=0;\n // int rm=0;\n // int total=0;\n // while(i<j){\n // if(arr[i]<=arr[j]){\n // if(lm>arr[i]){\n // total+=lm-arr[i]... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "\nclass Solution {\npublic:\n int trap(vector<int>& height) {\n int lastindex=height.size()-1;\n int L=1;\n int R=lastindex-1;\n int Lmax=height[0];\n int Rmax=height[lastindex];\n vector<int> w(height.size(),0);\n \n while(L<=R)\n {\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n \nint trap(vector<int> height){\n int max_l=height.front(),max_r=height.back(),r=height.size()-1,l=0,ans=0;\n while(l<=r){\n if(height[l]<=height[r]){\n int evaluated=max_l-height[l];\n ans+=(evaluated)>0?evaluated:0;\n max_l=max(... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n const int n = height.size();\n vector<int> l(n);\n l[0] = height[0];\n for(int i=1;i<n;++i) l[i] = max(l[i-1], height[i]);\n int ans=0,mx = height[n-1];\n for(int i=n-1;i>=0;--i){\n mx = ma... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int brute_force(vector<int> height) {\n int n = height.size();\n int count = 0;\n\n for(int i = 1; i <= n-2; i++) {\n int left = 0;\n int right = 0;\n\n // left tallest building\n for(int l = i-1; l >= 0; l--)\n... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n \nint trap(vector<int> height){\n int max_l=height.front(),max_r=height.back(),r=height.size()-1,l=0,ans=0;\n while(l<=r){\n if(height[l]<=height[r]){\n int evaluated=max_l-height[l];\n ans+=(evaluated)>0?evaluated:0;\n max_l=max(... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n vector<int> suffixmax(height.size(),0);\n for(int i=height.size()-1;i>=0;i--){\n if(i+1<height.size()){\n suffixmax[i]=max(suffixmax[i+1],height[i]);\n }else{\n suffixmax[i]=height[i];\n }\n }\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n // int trap(vector<int>& h) {\n // int n=h.size();\n // vector<int> t(n);\n // t[n-1]=h[n-1];\n // for(int i = n-2; i>=0;i--){\n // t[i]=min(t[i+1],h[i]);\n // }\n // int sum=0;\n // int maxi=h[0];\n // for(in... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n stack<int> bd;\n int i = 0;\n int running_count = 0;\n\n while(i < height.size()){\n while(!bd.empty() && height[i] > height[bd.top()]){\n int top = bd.top();\n bd.pop();\n\... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\nvector<int>getLeftMaxArray(vector<int>& height , int &n){\n vector<int>leftMax(n);\n leftMax[0] = height[0];\n for(int i = 1 ; i< n;i++){\n leftMax[i] = max(leftMax[i-1] , height[i]);\n }\n return leftMax;\n}\nvector<int>getRightMaxArray(vector<int>& height ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n if (n == 0) return 0;\n \n stack<int> st;\n int trapped_water = 0;\n \n for (int i = 0; i < n; ++i) {\n // While the stack is not empty and the current height is greater than\n /... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n \nint trap(vector<int>& height) {\n int n=height.size();\n vector<int> maxleft(n,-1);\n vector<int> maxright(n,-1);\n int curr_max_l=0,curr_max_r=0;\n int ans=0;\n for(int i=0;i<n;i++){\n maxleft[i]=curr_max_l;\n curr_max_l=max(curr_max_l,heigh... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n \nint trap(vector<int>& height) {\n int n=height.size();\n vector<int> maxleft(n,-1);\n vector<int> maxright(n,-1);\n int found=n;\n int curr_max_l=0,curr_max_r=0;\n int ans=0;\n for(int i=0;i<n;i++){\n maxleft[i]=curr_max_l;\n curr_max_l=ma... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 2 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n vector<int> left(n,0);\n vector<int> right(n,0);\n\n left[0] = height[0];\n for(int i = 1; i<n; i++)\n {\n left[i] = max(height[i], left[i-1]);\n cout<<l... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 3 | {
"code": "class Solution {\npublic:\n int trap(vector<int>& height) {\n int n = height.size();\n vector<int> leftMax(n),rightMax(n);\n // to calculate leftMax array\n leftMax[0]=height[0];\n for(int i=1;i<n;i++){\n leftMax[i] = max(leftMax[i-1],height[i]);\n }\n ... |
42 | <p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" s... | 3 | {
"code": "class Solution {\n public:\n int trap(vector<int>& height) {\n const int n = height.size();\n int ans = 0;\n vector<int> l(n); // l[i] := max(height[0..i])\n vector<int> r(n); // r[i] := max(height[i..n))\n\n for (int i = 0; i < n; ++i)\n l[i] = i == 0 ? height[i] : max(height[i], l[... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 0 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1[0] == '0' || num2[0] == '0') {\n return \"0\";\n }\n \n int n = num1.length() - 1;\n int m = num2.length() - 1;\n string answer;\n\n for (int a = n; a >= 0; --a)... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 0 | {
"code": "class Solution {\npublic:\n string multiply(string& A, string& B) {\n if(A == \"0\" || B == \"0\") return \"0\";\n string ans(size(A)+size(B), '0');\n for(int i = size(A)-1; i >= 0; i--) {\n for(int j = size(B)-1; j >= 0; j--) {\n int res = (ans[i+j+1]-'0')... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 0 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1 == \"0\" || num2 == \"0\") {\n return \"0\";\n }\n int m = num1.size(), n = num2.size();\n vector<int> arr(m + n);\n for (int i = m - 1; i >= 0; --i) {\n int a = nu... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 0 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n\n // handle edge-case where the product is 0\n if (num1 == \"0\" || num2 == \"0\") return \"0\";\n \n // num1.size() + num2.size() == max no. of digits \n vector<int> num(num1.size() + num2.size... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 1 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1 == \"0\" || num2 == \"0\") return \"0\";\n \n int m = num1.size(), n = num2.size();\n vector<int> result(m + n, 0);\n \n for (int i = m - 1; i >= 0; --i) {\n for (int j... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 1 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n int n1 = num1.size();\n int n2 = num2.size();\n \n // Edge case: If either number is \"0\", the result is \"0\"\n if (num1 == \"0\" || num2 == \"0\") return \"0\";\n \n // Result ar... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if(num1.length()<num2.length()) multiply(num2,num1);\n vector <int> ans(num1.length()+num2.length(),0);int pro,carr=0;\n string ret;\n for(int i=num2.length()-1;i>=0;i--)\n {\n int w=a... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n string ret;\n\n int row = num1.size();\n int column = num2.size();\n\n int array[row][column];\n\n for (int i = 0; i < row; i++) {\n \n int a = num1[i] - '0';\n f... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Integer{\n private:\n string s;\n public:\n Integer(string s){\n this->s = s; \n }\n\n void removetrailingzeros(){\n int index = 0;\n while(s[index] == '0') index++;\n\n if(index == s.length()) s = \"0\";\n else ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) \n {\n string& st1 = num1.size() > num2.size() ? num1 : num2;\n string& st2 = st1 == num1 ? num2 : num1;\n\n uint8_t** buffers = new uint8_t*[st2.size()];\n int nc = st1.size() + st2.size() + 1;\n ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n const int base = 1e9;\n vector<int> convert(string& num){\n int len = num.size();\n int sz = (len - 1) / 9 + 1; // Calculate the size of the ans vector\n vector<int> ans(sz, 0);\n int idx = 0, tenPow = 1;\n for (int i = len-1; i>= 0; i--)... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n const int base = 1e9;\n vector<int> convert(string& num){\n int len = num.size();\n int sz = (len - 1) / 9 + 1; // Calculate the size of the ans vector\n vector<int> ans(sz, 0);\n int idx = 0, tenPow = 1;\n for (int i = len-1; i>= 0; i--)... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n \n void addFromOffset(string& acc, int offset, const string& num)\n {\n int c=0;\n acc.resize(offset+num.size(), '0');\n \n for(int i=0; i<num.size(); i++)\n {\n int res = (num[i] - '0' + acc[offset+i] - '0') + c;\n ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1 == \"0\" || num2 == \"0\") return \"0\";\n \n int m = num1.size();\n int n = num2.size();\n vector<int> result(m + n, 0); // Initialize result vector\n \n // Multiply each... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "//\n// \"19\"\n// \"49\"\n//\n// 81\n// 90\n// 360\n// 400\n//\n//\n//\nclass Solution {\npublic:\n string multiply(string num1, string num2) {\n vector<int> val ((num1.size() + 1) * (num2.size() + 1), 0);\n\n int currNum1Zeros = 0;\n\n for (int i = num1.length() - 1; i >= 0; i--) {\n int ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1==\"0\" || num2==\"0\") return \"0\";\n int len1 = num1.length();\n int len2 = num2.length();\n //The maximum number of digits will be len1 + len2\n vector<int> digits;\n for (int ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1 == \"0\" || num2 == \"0\") return \"0\";\n \n vector<int> res(num1.size()+num2.size(), 0);\n \n for (int i = num1.size()-1; i >= 0; i--) {\n for (int j = num2.size()-1; j >= 0... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 2 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n int s1 = num1.size();\n int s2 = num2.size();\n vector<int> values(s1 + s2 + 1);\n for (int i = 0; i < s1; ++i) {\n for (int j = 0 ; j < s2; ++j) {\n int cur = (num1.at(s1 - 1 ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if(num1==\"0\" || num2==\"0\")\n return \"0\";\n \n if(num2.length()>num1.length())\n return multiply(num2, num1);\n \n reverse(num1.begin(), num1.end());\n reverse(n... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "/*\nwrong 1 (10/311 passed, 12 mins):\nLine 34: Char 23: runtime error: signed integer overflow: 123456789 * 987654321 cannot be represented in type 'int' (solution.cpp)\n\nthink: 10^200: The maximum value that can be stored in an unsigned long long in C++ is 18,446,744,073,709,551,615. This is a 64-bit in... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\nprivate:\n void update(string& res, const string& num1, int digit, int d)\n {\n if(!digit)\n {\n return;\n }\n int i = num1.size() - 1;\n string added = \"\";\n int cur = 0;\n while(i >= 0 || cur)\n {\n if... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if(num1==\"0\" || num2==\"0\")\n return \"0\";\n \n reverse(num1.begin(), num1.end());\n reverse(num2.begin(), num2.end());\n \n string result;\n \n for(int i = 0;... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\n string multiply(const string& num, char ch, string& units) {\n unsigned int digit = ch - '0';\n if (digit == 0) {\n return \"0\";\n }\n \n string result = units;\n unsigned int carry = 0;\n for (int i = num.size() - 1; i >= 0... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\n string multiply(const string& num, char ch, string& units) {\n unsigned int digit = ch - '0';\n if (digit == 0) {\n return \"0\";\n }\n \n string result = units;\n unsigned int carry = 0;\n for (int i = num.size() - 1; i >= 0... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n if (num1 == \"0\" || num2 == \"0\") return \"0\";\n int carry = 0, temp = 0, length1 = num1.length() - 1, length2 = num2.length() - 1;\n string output;\n vector<string> outputlist;\n for (int i =... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "#define pb push_back\nclass Solution {\npublic:\n void add(string s1, string &s2) {\n int i=0,n1=s1.length(),n2=s2.length(),carry=0;\n while(i<n1 && i<n2) {\n int val = (s1[i]-'0') + (s2[i]-'0') + carry;\n s2[i] = (val%10)+'0';\n carry = val/10;\n ... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n vector<int> n1;\n vector<int> n2;\n \n\n for(int i=num1.length()-1;i>=0;i--){\n n1.push_back(num1[i]-'0');\n }\n for(int i=num2.length()-1;i>=0;i--){\n n2.push_back(n... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "#define CTOI(x) int(x - '0')\n#define ITOC(x) int(x + '0')\n\nclass Solution {\n std::string addStrings(std::string num1, std::string num2)\n {\n int carry = 0;\n int i1 = num1.length() - 1;\n int i2 = num2.length() - 1;\n std::string res;\n\n while (i1 >= 0 || i2 >= 0 || carry) {\n i... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "#include <algorithm>\n#include <iostream>\n#include <string>\n#include <vector>\n\nusing namespace std;\n\nclass Solution {\nprivate:\n string addStrings(const string& num1, const string& num2) {\n int len1 = num1.size();\n int len2 = num2.size();\n string result;\n int carry... |
43 | <p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>
<p><strong>Note:</strong> You must not use any built-in BigInteger library or convert the inputs to integer directly.<... | 3 | {
"code": "class Solution {\nprivate:\n string addStrings(const string& str1, const string& str2) {\n auto num1it = str1.rbegin();\n auto num2it = str2.rbegin();\n\n string res = \"\";\n int digit1, digit2, sum;\n bool carry = false;\n while (num1it != str1.rend() && num2i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.