id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n const string letters = \"AEIOUaeiou\";\n unordered_set<char> vowels(letters.begin(), letters.end());\n unordered_map<char, int> vowels_cnt;\n\n for (int i = 0; i < s.size(); i++) {\n if (vowels.count(s[i])... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n string ans = \"\";\n string vowels = \"\";\n string vowelSet = \"AEIOUaeiou\";\n\n for (char c : s) {\n if (vowelSet.find(c) != string::npos) {\n vowels += c;\n ans += '*';\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n // Time/Space: O(n)/O(1)\n string sortVowels(string s) {\n // Use a hash table to check whether a character is a vowel or not\n unordered_set<char> vowels = {\n 'a', 'e', 'i', 'o', 'u',\n 'A', 'E', 'I', 'O', 'U'\n };\n\n //... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_set<char> s1 = {'a', 'e', 'i', 'o', 'u'};\n\n priority_queue<char, vector<char>, greater<char>> pq;\n \n for (char c : s){\n if (s1.count(tolower(c))){\n pq.push(c);\n }... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\nprivate:\n bool isVowel(char ch){\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||\n ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';\n }\npublic:\n string sortVowels(string s) {\n int n = s.size();\n string v = \... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> upper(26,0);\n vector<int> lower(26,0);\n find_upper(upper,s);\n find_lower(lower,s);\n string ans = find_ans(lower,upper);\n placed(ans,s);\n return s;\n }\n void find_upper(ve... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> lower(26, 0), upper(26, 0);\n int n = s.length();\n for (int i = 0; i < n; i++) {\n if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||\n s[i] == 'u')\n lower... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_set<char> s1 = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n\n vector<char> v1;\n \n for (char c : s){\n if (s1.count(c)){\n v1.push_back(c);\n }\n }\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_set<char> s1 = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n\n priority_queue<char, vector<char>, greater<char>> pq;\n \n for (char c : s){\n if (s1.count(c)){\n pq.push(c)... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_set<char> s1 = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n\n vector<char> v1;\n \n for (char c : s){\n if (s1.count(c)){\n v1.push_back(c);\n }\n }\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_set<char> st{'A','E','I','O','U','a','e','i','o','u'};\n vector<char> vowels;\n for(auto a: s){\n if(st.count(a)) vowels.push_back(a);\n }\n if(vowels.size() == 0) return s;\n sort(... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "\nclass Solution {\npublic:\n bool isVowel(char ch) {\n if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||\n ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {\n return true;\n } else {\n return false;\n }\n }\n\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n string vowels = \"AEIOUaeiou\";\n string res = \"\";\n int count = 0;\n unordered_map<char, int> mp;\n for(char &c:vowels)\n mp[c] = 0;\n for(char &c:s)\n mp[c]++;\n\n for(i... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n\n bool isVowel(char i){\n return i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u' || i == 'A' || i == 'E' || i == 'I' || i == 'O' || i == 'U' ;\n }\n\n string sortVowels(string s) {\n vector<int> vowels; \n \n for(char &c: s){\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_set<char> s1 = {'a', 'e', 'i', 'o', 'u'};\n\n priority_queue<char, vector<char>, greater<char>> pq;\n \n for (char c : s){\n if (s1.count(tolower(c))){\n pq.push(c);\n }... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> vovel;\n for(int i = 0; i < s.size() ; i++){\n if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || \n s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] ==... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n int n = s.size();\n string vowel=\"aeiouAEIOU\";\n unordered_map<char ,int>mpp;\n for(auto it :vowel){\n mpp[it]++;\n }\n string ti=\"\";\n for(int i =0 ;i<n;i++){\n if(mpp.... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n unordered_map<char,int> xmap;\n xmap['a'] = 1;\n xmap['e'] = 2;\n xmap['i'] = 3;\n xmap['o'] = 4;\n xmap['u'] = 5;\n xmap['A'] = 6;\n xmap['E'] = 7;\n xmap['I'] = 8;\n xmap['... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char>v;\n map<char,bool>mpp;\n string vow=\"aeiouAEIOU\";\n for(int i=0;i<vow.size();i++){\n mpp[vow[i]]=true;\n }\n int n=s.size();\n for(int i=0;i<n;i++){\n if(mpp[... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\nunordered_set<char> Vowels = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};\nstring sortVowels(string s)\n{\n ios_base::sync_with_stdio(false);\n cin.tie(0); \n cout.tie(0);\n\n vector<char> inWord;\n for(int i = 0; i < s.size(); i++)\n {\n if(Vow... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n string consonant,vowel;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U'){\n vowel+=s[i];\... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n string consonant,vowel;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U'){\n vowel+=s[i];\... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "string removeCons(string s)\n{\n int n = s.size();\n string ans;\n for (char c : s)\n {\n if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')\n {\n ans.push_back(c);\n }\n }\n return ans;\... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "// class Solution {\n// public:\n// string sortVowels(string s) {\n// vector<char> vowels;\n// vector<char> vowels_index;\n// for(int i=0;i<s.size();i++)\n// {\n// if (isVowel(s[i])) \n// {\n// vowels.push_back(s[i]);\n// vowels_index.push_ba... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char> vowels ={'a','e','i','o','u','A','E','I','O','U'};\n vector<char> hashOfVowels;\n vector<int> hashOfIndex;\n\n for(int i=0; i<s.size(); i++){\n for(char v: vowels){\n if(s[i] ==... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>v;\n int n=s.size();\n string ss=\"\";\n for(int i=0;i<n;i++){\n if(s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U' || s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u'){\n... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>v;\n int n=s.size();\n string ss=\"\";\n for(int i=0;i<n;i++){\n if(s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U' || s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u'){\n... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> indices;\n vector<char> vogais;\n\n for (int i=0; i<s.size(); ++i){\n if (ehVogal(s[i])){\n indices.push_back(i);\n vogais.push_back(s[i]);\n }\n }\n\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n //solely did it\n vector<char> vowels ={'a','e','i','o','u','A','E','I','O','U'};\n vector<char> hashOfVowels;\n vector<int> hashOfIndex;\n\n for(int i=0; i<s.size(); i++){\n for(char v: vowels){\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n priority_queue<int, vector<int>, greater<int>> vowels;\n string res = \"\";\n for(char c : s) {\n if(tolower(c) == 'a' || tolower(c) == 'e' || tolower(c) =='i' || tolower(c) =='o' || tolower(c) =='u' ) {\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>index;\n string temp=\"\";\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'){\n index.push_back(i);\n... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "// Time: O(NlogN)\n// Space: O(N)\nclass Solution {\n bool isVowel(char c) {\n c = tolower(c);\n return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';\n }\npublic:\n string sortVowels(string s) {\n vector<int> id;\n for (int i = 0; i < s.size(); ++i) {\n ... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>v;\n string x;\n string ans=s;\n int i,n=s.length();\n for(i=0;i<n;i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'|s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'){... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n \nstring t=s;\nvector<char>ans;\nvector<int>pos;\nint index=0;\nwhile(index!=s.size()){\n if(s[index]=='a' || s[index]=='e' || s[index]=='i' || s[index]=='o' || s[index]=='u' || s[index]=='A' || s[index]=='E' ||s[index]=='I' ||s[index]... |
2,887 | <p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p>
<ul>
<li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 <= i < s.length</code> such that <code>s... | 3 | {
"code": "class Solution {\npublic:\n string sortVowels(string s) {\n \nstring t=s;\nvector<char>ans;\nvector<int>pos;\nint index=0;\nwhile(index!=s.size()){\n if(s[index]=='a' || s[index]=='e' || s[index]=='i' || s[index]=='o' || s[index]=='u' || s[index]=='A' || s[index]=='E' ||s[index]=='I' ||s[index]... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 0 | {
"code": "class Solution {\n public:\n vector<int> findFrequentTreeSum(TreeNode* root) {\n vector<int> ans;\n unordered_map<int, int> count;\n int maxCount = 0;\n\n sumDownFrom(root, count);\n\n for (const auto& [_, freq] : count)\n maxCount = max(maxCount, freq);\n\n for (const auto& [sum, f... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 0 | {
"code": "class Solution {\nprivate:\nint find(TreeNode* root , unordered_map< int , int >&cnt){\n if(root == NULL){\n return 0;\n }\n int left = find(root->left , cnt);\n int right = find(root->right , cnt);\n int sum = root->val + left + right;\n cnt[sum]++;\n return sum; \n}\npublic:\n... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
508 | <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p>
<p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that n... | 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... |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\nint solveUsingRecursion(int n){\n // base case\n if(n == 0){\n return 0;\n }\n if(n == 1){\n return 1;\n }\n int ans = solveUsingRecursion(n-1) + solveUsingRecursion(n-2);\n return ans;\n }\n int fib(int n) {\n int ans = solveUsingR... |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n == 0) return 0;\n if( n == 1) return 1;\n return fib(n-1) + fib(n-2);\n }\n};",
"memory": "7100"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n==0){return 0;}\n if(n==1){return 1;}\n return fib(n-1)+fib(n-2);\n // if(n<=1){\n // return n;\n // }\n // else{\n // int fib[n+1];\n // fib[0]=0;\n // fib[1]=1;\n // for(int i=2;i<=n;i++){\n // fib[... |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n<=1) return n;\n int ans=fib(n-1)+fib(n-2);\n return ans;\n \n }\n};",
"memory": "7200"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n<=1){\n return n;\n }\n return fib(n-1)+fib(n-2);\n }\n};",
"memory": "7200"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n==0||n==1){\n return n;\n }\n return fib(n-1)+fib(n-2);\n }\n};",
"memory": "7300"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n==0 || n==1)\n return n;\n return fib(n-1)+fib(n-2);\n }\n};",
"memory": "7300"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n==0){\n return 0;\n }\n else if(n==1){\n return 1;\n }\n else{\n return fib(n-1)+fib(n-2);\n }\n }\n};",
"memory": "7400"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 0 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n==1)\n return 1;\n if(n==0)\n return 0; \n return fib(n-1) + fib(n-2);\n }\n};",
"memory": "7400"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 2 | {
"code": "class Solution {\npublic:\n int fib(int n) {\n if(n==0 || n==1){\n return n;\n }\n int ans = fib(n-1) + fib(n-2);\n return ans;\n }\n};",
"memory": "7500"
} |
1,013 | <p>The <b>Fibonacci numbers</b>, commonly denoted <code>F(n)</code> form a sequence, called the <b>Fibonacci sequence</b>, such that each number is the sum of the two preceding ones, starting from <code>0</code> and <code>1</code>. That is,</p>
<pre>
F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.
</pre>
... | 2 | {
"code": "class Solution {\npublic:\n\nint solveUsingRec(int n){\n if(n==0 || n==1){\n return n;\n }\n return solveUsingRec(n-1) + solveUsingRec(n-2);\n}\n\n int solveUsingDp(int n,vector<int>&dp){\n if(n==0 || n==1){\n return n;\n }\n dp[n] = solveUsingRec(n-1) + s... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 2 | {
"code": "class Solution {\n public:\n int findBottomLeftValue(TreeNode* root) {\n queue<TreeNode*> q{{root}};\n TreeNode* node = nullptr;\n\n while (!q.empty()) {\n node = q.front();\n q.pop();\n if (node->right)\n q.push(node->right);\n if (node->left)\n q.push(node->lef... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 3 | {
"code": "class Solution {\n public:\n int findBottomLeftValue(TreeNode* root) {\n queue<TreeNode*> q{{root}};\n TreeNode* node = nullptr;\n\n while (!q.empty()) {\n node = q.front();\n q.pop();\n if (node->right)\n q.push(node->right);\n if (node->left)\n q.push(node->lef... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
513 | <p>Given the <code>root</code> of a binary tree, return the leftmost value in the last row of the tree.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/14/tree1.jpg" style="width: 302px; height: 182px;" />
<pre>
<strong>Input:</strong> r... | 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.