id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
228 | <p>You are given a <strong>sorted unique</strong> integer array <code>nums</code>.</p>
<p>A <strong>range</strong> <code>[a,b]</code> is the set of all integers from <code>a</code> to <code>b</code> (inclusive).</p>
<p>Return <em>the <strong>smallest sorted</strong> list of ranges that <strong>cover all the numbers i... | 0 | {
"code": "class Solution {\npublic:\n vector<string> summaryRanges(vector<int>& nums) {\n\n vector<string> ans;\n string temp = \"\";\n int n = nums.size();\n bool flag = 0;\n for (int i = 0; i < n; i++) {\n\n int x = nums[i];\n temp = to_string(nums[i]);\n... |
228 | <p>You are given a <strong>sorted unique</strong> integer array <code>nums</code>.</p>
<p>A <strong>range</strong> <code>[a,b]</code> is the set of all integers from <code>a</code> to <code>b</code> (inclusive).</p>
<p>Return <em>the <strong>smallest sorted</strong> list of ranges that <strong>cover all the numbers i... | 0 | {
"code": "class Solution {\npublic:\n vector<string> summaryRanges(vector<int>& nums) {\n vector<string> vec_str;\n string s1 = \"\";\n if (nums.size() == 0)\n return vec_str;\n int start = nums[0];\n int end = 0;\n bool flag = true;\n for (int i = 1; i ... |
228 | <p>You are given a <strong>sorted unique</strong> integer array <code>nums</code>.</p>
<p>A <strong>range</strong> <code>[a,b]</code> is the set of all integers from <code>a</code> to <code>b</code> (inclusive).</p>
<p>Return <em>the <strong>smallest sorted</strong> list of ranges that <strong>cover all the numbers i... | 0 | {
"code": "/*class Solution {\npublic:\n vector<string> summaryRanges(vector<int>& nums) {\n vector<char> temp;\n vector<string> ans;\n int start = nums[0];\n int end = 0;\n for(int i = 0; i < nums.size(); ){\n if(nums[i+1] == (nums[i] + 1)){\n i++;\n ... |
228 | <p>You are given a <strong>sorted unique</strong> integer array <code>nums</code>.</p>
<p>A <strong>range</strong> <code>[a,b]</code> is the set of all integers from <code>a</code> to <code>b</code> (inclusive).</p>
<p>Return <em>the <strong>smallest sorted</strong> list of ranges that <strong>cover all the numbers i... | 2 | {
"code": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> summaryRanges(vector<int>& nums) {\n vector<string> result;\n if (nums.empty()) return result;\n \n int start = nums[0]; // Start of a range\n \n for (int i... |
228 | <p>You are given a <strong>sorted unique</strong> integer array <code>nums</code>.</p>
<p>A <strong>range</strong> <code>[a,b]</code> is the set of all integers from <code>a</code> to <code>b</code> (inclusive).</p>
<p>Return <em>the <strong>smallest sorted</strong> list of ranges that <strong>cover all the numbers i... | 2 | {
"code": "class Solution {\npublic:\n vector<string> summaryRanges(vector<int>& nums) {\n \n if(nums.size()==0) return {};\n \n vector<string> ans;\n int n=nums.size();\n \n int start=nums[0];\n int last=nums[0];\n int cnt=nums[0];\n for(int i=1... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n vector<int>ans;\n int cnt1=0,cnt2=0;\n int el1=INT_MIN;\n int el2=INT_MIN;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if(cnt1==0 && el2!=nums[i]){\n cnt1... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int candidate1 = 0, candidate2 = 0, count1 = 0, count2 = 0;\n int n = nums.size();\n\n // First pass: find potential candidates\n for (int num : nums) {\n if (num == candidate1) {\n count1++;\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n = nums.size();\n int c1 = 0, c2 = 0;\n int ele1, ele2;\n\n for(int i=0; i<n; i++) {\n if(c1 == 0 && ele2 != nums[i]) {\n c1 = 1;\n ele1 = nums[i];\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n //1.\n\n // vector<int>vec;\n // int n = nums.size();\n // map<int,int>mp;\n // for(int i = 0; i<n; i++){\n // mp[nums[i]]++;\n // }\n // for(auto it:mp){\n // ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& v) {\n int n = v.size(); //size of the array\n\n int cnt1 = 0, cnt2 = 0; // counts\n int el1 = INT_MIN; // element 1\n int el2 = INT_MIN; // element 2\n\n // applying the Extended Boyer Moore's Voting Algorithm:\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n = nums.size();\n int m1 = INT_MIN;\n int m2 = INT_MIN;\n int f1 = 0, f2 = 0;\n vector<int> ans;\n for(int x : nums)\n {\n if( f1 == 0 && x != m2)\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums)\n {\n vector<int> res;\n int n = nums.size();\n int c1 = 0;\n int c2 = 0;\n int e1 = INT_MIN;\n int e2 = INT_MIN;\n\n for(int i = 0;i < n;i++)\n {\n if(c1 == 0... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n = nums.size();\n int cnt1 = 0;\n int cnt2=0;\n int el1 = INT_MIN;\n int el2 = INT_MIN;\n vector<int> list;\n int mini = n/3 + 1;\n for(int i =0;i<n;i++){\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans;\n int c1=0,c2=0,e1,e2;\n for(int i=0;i<n;i++)\n {\n if(c1==0 && e2!=nums[i])\n {\n c1++;\n e1=nums[i... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 1 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n if(nums.size()==1) return nums;\n int x,y;\n x=INT_MAX; y=INT_MAX;\n int count_x, count_y;\n count_x=0; count_y=0;\n for(int i=0; i<nums.size(); i++){\n if(x!=nums[i] && y!... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 1 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n = nums.size();\n map<int, int> map;\n vector<int> result;\n\n for (int i = 0; i < n; i++) {\n map[nums[i]] += 1;\n }\n\n for (auto it : map) {\n if (it.sec... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) \n {\n int n = nums.size();\n int maj = n/3;\n \n int maj1 = 0, maj2 = 0;\n \n int vote1 = 0,vote2 = 0;\n for(int i = 0 ;i<n;i++)\n {\n if(nums[i] == maj1)\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) \n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int n = nums.size();\n int maj = n/3;\n \n int maj1 = 0, maj2 = 0;\n \n int vote1 = 0... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int size = nums.size();\n if (size == 0) {\n return vector<int>{0};\n } \n map<int, int> m;\n int num = size / 3;\n if(size == 1 && nums[0] > num) {\n return num... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n=nums.size()/3;\n vector<int>ans;\n ans.reserve(2);\n map<int,int>m;\n for(auto i:nums){\n m[i]++;\n }\n for(auto x:m){\n if(x.second>n) ans.push_bac... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int count = 0;\n vector<int> ans;\n int ind = nums[0];\n sort(nums.begin(), nums.end());\n for (int i = 0; i < nums.size(); i++) {\n\n if (nums[i] == ind)\n count++... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int> v) {\n int n = v.size(); \n\n int cnt1 = 0, cnt2 = 0; \n int el1 = INT_MIN; \n int el2 = INT_MIN; \n\n // applying the Extended Boyer Moore's Voting Algorithm:\n for ( int i = 0; i < n; i++ ) {\n if ( cnt1 == 0 ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int lim=nums.size()/3;int mi=0;vector<int>ans;\n unordered_set<int>st;\n nums.push_back(INT_MAX);\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size()-1;i++){\n \n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int> v) { \n\t int cnt1 = 0; int cnt2 = 0; \n\t int ele1 = INT_MIN; int ele2 = INT_MIN; \n\t int n = v.size();\n\t for(int i = 0;i<n;i++){\n\t\t if(cnt1 == 0 && ele2 != v[i]){\n\t\t\t\t cnt1 = 1; ele1 = v[i]; } \n\t\t else if(cnt2 =... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n int i=0;\n vector<int> ans;\n while(i<n){\n int count = 1;\n int j = i+1;\n while(j<n && nums[i]==num... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int> ans;\n int x=nums.size()/3+1;\n map<int,int> count;\n for(int i=0;i<nums.size();i++){\n count[nums[i]]++;\n if(count[nums[i... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) \n {\n vector <int> v;\n for(int i=0;i<nums.size();i++)\n {\n int count=0;\n \n for(int j=0;j<nums.size();j++)\n {\n if(nums[i]==nums[j])\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& a) {\n\n unordered_map<int, int> hash;\n vector<int> res;\n for (int i = 0; i < a.size(); i++) {\n hash[a[i]]++;\n }\n int n=(a.size() / 3);\n // cout<<\"n:\"<<n<<endl;\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n unordered_map<int,int> mp;\n set<int> ans;\n for(auto it:nums)\n {\n mp[it]++;\n }\n for(auto it:nums)\n {\n if(mp[it]>(nums.size()/3))\n ans.i... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n int n=nums.size();\n vector<int> res;\n unordered_map<int, int> freq;\n for(int i=0; i<n; i++){\n freq[nums[i]]++;\n }\n for(auto item: freq){\n if(item.second>n... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n unordered_map<int,int> fr;\n vector<int> ans;\n int n = nums.size();\n for(int num:nums){\n fr[num]++;\n if(fr[num] > n/3){\n ans.push_back(num);\n ... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n vector<int>ans;\n unordered_map<int,int>mpp;\n int min = nums.size()/3+1;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]++;\n if(mpp[nums[i]]==min){\n ans.pus... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n vector<int>ans;\n unordered_map<int,int>mpp;\n int min = nums.size()/3+1;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]++;\n if(mpp[nums[i]]==min){\n ans.pus... |
229 | <p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>⌊ n/3 ⌋</code> times.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>
<p><strong class="example">Example ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> majorityElement(vector<int>& nums) {\n unordered_map<int,int>mpp;\n int n = nums.size();\n vector<int>ans;\n int mini= n/3 +1;\n for(int i = 0; i < n ; i++ ){\n mpp[nums[i]]++;\n if( mpp[ nums[i] ] == mini )... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "class Solution {\npublic:\n int kthSmallest(TreeNode* root, int k) {\n int cnt = 0;\n return solve(root, cnt, k);\n }\n \n int solve(TreeNode* root, int &cnt, int k) {\n if (root == NULL) {\n return -1;\n }\n int left = solve(root->left, cnt, k);\n ... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "class Solution {\npublic:\n void util(TreeNode *root,int ¤tCount, int &ans,int k)\n {\n if(!root)return;\n util(root->left,currentCount,ans,k);\n currentCount++;\n \n if(currentCount == k){\n \n ans = root->val;\n return;\n ... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
230 | <p>Given the <code>root</code> of a binary search tree, and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>smallest value (<strong>1-indexed</strong>) of all the values of the nodes in the tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="h... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "vector<string> mitoa;\nunordered_map<string, int> matoi;\nbool myCmp(int a, int b) { return mitoa[a] > mitoa[b]; }\n\nclass Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n mitoa.clear();\n matoi.clear();\n matoi[\"JFK\"] = 0;\n mitoa.pu... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\r\npublic:\r\n vector<string> findItinerary(vector<vector<string>>& tickets) {\r\n std::unordered_map<std::string, std::map<std::string, int>> adjs;\r\n for (auto& ticket : tickets) {\r\n ++adjs[ticket[0]][ticket[1]];\r\n }\r\n std::vector<std::str... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n int n = tickets.size();\n std::vector<std::string> ans(n + 1);\n std::unordered_map<std::string, std::multiset<std::string, std::greater<>>> adj;\n for (int i = 0; i < n; ++i) adj[ti... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n auto m = std::unordered_map<std::string_view,\n std::multiset<std::string_view>>{};\n for (auto& ticket : tickets) {\n m[ticket[0]].insert(ticket[1]);... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <map>\n#include <deque>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n unordered_map<string, map<string, int>> graph;\n vector<string> result;\... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n auto m = std::unordered_map<std::string_view,\n std::multiset<std::string_view>>{};\n for (auto& ticket : tickets) {\n m[ticket[0]].insert(ticket[1]);... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\nprivate:\n unordered_map<string, map<string, int>> targets;\n\n bool backtracking (int ticketnum, vector<string>& result) {\n if (result.size() == ticketnum + 1) {\n return true;\n }\n\n for (pair<const string, int>& target : targets[result[result.siz... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n int t = tickets.size();\n unordered_map<string, map<string, int>> adj;\n vector<bool> used(t, false);\n\n \n for(int i = 0; i < t; ++i){\n auto& v = tickets[i];\n ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\nprivate:\n unordered_map<string, map<string, int>> m;\n bool backtracking(int sz, vector<string>& res)\n {\n if (sz + 1 == res.size())\n {\n return true;\n }\n\n for (auto && [addr, count] : m[res.back()])\n {\n if (count >... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\n unordered_map<string, vector<string>>graph;\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n int n = tickets.size();\n if(!n)\n return {};\n for(const auto&t:tickets){\n graph[t[0]].push_back(t[1]);\n }\n... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n \n unordered_map<string,multiset<string>> flightMap;\n vector<string> res;\n\n for(const auto& ticket: tickets){\n flightMap[ticket[0]].insert(ticket[1]);\n }\n\n ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\n public:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n vector<string> ans;\n unordered_map<string, multiset<string>> graph;\n\n for (const vector<string>& ticket : tickets)\n graph[ticket[0]].insert(ticket[1]);\n\n dfs(graph, \"JFK\", ans);\n ran... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n void DFS(vector<string> &res, const string &start, unordered_map<string, multiset<string>> &map) {\n while ( map[start].size() ) {\n const auto next = *(map[start].begin());\n map[start].erase(map[start].begin());\n DFS(res, next, map);... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n vector<string> itinerary;\n unordered_map<string, vector<pair<string, bool>>> map;\n for (const vector<string>& ticket : tickets)\n map[ticket[0]].push_back(make_pair(ticket[1], ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n unordered_map<string, multiset<string>> mp;\n for(const auto& t : tickets) {\n mp[t[0]].insert(t[1]);\n }\n stack<string> s;\n s.push(\"JFK\");\n vector<stri... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "\nclass Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n // Build the adjacency list\n map<string, multiset<string>> adj;\n for (const auto& ticket : tickets) {\n adj[ticket[0]].insert(ticket[1]);\n }\n\n vector<string>... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n using Map = unordered_map<string, multiset<string>>;\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n Map m;\n for(auto& ticket : tickets) {\n m[ticket[0]].insert(ticket[1]); // {\"JFK\" : [\"A\", \"B\", \"B\"]}\n }\n\n vector<... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>> tickets) {\n\n // find the unique nodes\n set<string> nodesUnique;\n for (auto &e: tickets){\n nodesUnique.insert(e[0]);\n nodesUnique.insert(e[1]);\n }\n\n // prepare... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>> tickets) {\n\n // find the unique nodes\n set<string> nodesUnique;\n for (auto &e: tickets){\n nodesUnique.insert(e[0]);\n nodesUnique.insert(e[1]);\n }\n\n // prepare... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\n unordered_map<string, vector<string>>graph;\n unordered_set<string>nodes;\n unordered_map<string,int>indegree, outdegree;\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n int n = tickets.size();\n if(!n)\n return {};\n ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\nprivate:\n void eulerianPath(\n unordered_map<string, vector<string>>& graph,\n unordered_map<string, int>& outDegree,\n string& from,\n stack<string>& itinerary\n ) {\n while (outDegree[from] != 0) {\n string to = *graph[from].begin();\... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n void dfs(unordered_map<string, priority_queue<string, vector<string>, greater<>>>& g, vector<string>& res, string pos) {\n while(!g[pos].empty()) {\n string t = g[pos].top();\n g[pos].pop();\n dfs(g, res, t);\n }\n res.pus... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n // Use a min-heap (priority_queue) for lexicographically sorting the destinations\n unordered_map<string, priority_queue<string, vector<string>, greater<string>>> graph;\n \n // Buil... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\npublic:\n unordered_map<string, priority_queue<string, vector<string>, greater<string>>> graph;\n vector<string> result;\n \n void dfs(string node) {\n auto& destinations = graph[node];\n while (!destinations.empty()) {\n string next = destinations.to... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\npublic:\n void dfs(std::string departure)\n {\n std::string arrival;\n while (graph[departure].size())\n {\n arrival = graph[departure][graph[departure].size() - 1];\n graph[departure].pop_back();\n dfs(arrival);\n }\n ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\n void dfs(string curr, unordered_map<string, multiset<string>>& adjL, vector<string>& path){\n while(!adjL[curr].empty()){\n auto itr = adjL[curr].begin();\n\n string next = *itr;\n\n adjL[curr].erase(itr);\n\n dfs(next, adjL, path);\n... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\nprivate:\n unordered_map<string, priority_queue<string, vector<string>, greater<string>>> flightMap;\n vector<string> itinerary;\n\n // Helper function for DFS\n void dfs(string airport) {\n // While there are still flights departing from the airport\n while (!fl... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\nprivate:\n unordered_map<string, priority_queue<string, vector<string>, greater<string>>> flightMap;\n vector<string> itinerary;\n\n void dfs(string airport) {\n // While there are still flights departing from the airport\n while (!flightMap[airport].empty()) {\n ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "#include <unordered_map>\n\nclass Solution {\nprivate:\n std::unordered_map<std::string, std::multiset<std::string>> connections;\n std::vector<std::string> route; \npublic:\n vector<string> findItinerary(vector<vector<string>>& tickets) {\n // create connection mapings\n for(auto v ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\nprivate:\n void travel(unordered_map<string, vector<string>>& graph, string node, stack<string>& itinerary) {\n while (graph[node].size() != 0) {\n string to = graph[node].back();\n graph[node].pop_back();\n travel(graph, to, itinerary);\n ... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 1 | {
"code": "class Solution {\npublic:\n\n vector<string> ans;\n unordered_map<string,multiset<string>> mp;\n void rec(string s) {\n\n while (!mp[s].empty()) {\n string t = *(mp[s].begin());\n mp[s].erase(mp[s].begin());\n rec(t);\n }\n\n ans.push_back(s);\... |
332 | <p>You are given a list of airline <code>tickets</code> where <code>tickets[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.</p>
<p>All of the tickets belong to a man who departs from <code>"JFK"</... | 2 | {
"code": "\nostream& operator<<(ostream& os, const vector<string>& v) {\n cout << \"[\";\n for (int i = 0; i < v.size(); i++) {\n if (i != 0) {\n cout << \", \";\n }\n cout << v[i];\n }\n cout << \"]\";\n return os;\n}\n\nclass Solution {\npublic:\n vector<string> fi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.