id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n int n1 = str1.size();\n int n2 = str2.size();\n string sub;\n if (n1 > n2)\n sub = str2;\n else\n sub = str1;\n while (sub.size() > 0){\n if (isSub(sub...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n int n1 = str1.size();\n int n2 = str2.size();\n string sub;\n if (n1 > n2)\n sub = str2;\n else\n sub = str1;\n while (sub.size() > 0){\n if (isSub(sub...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n std::deque<string> commons = std::deque<string>();\n\n for (int i = 0; i < min(str1.length(), str2.length()); i++) {\n if (str1[i] == str2[i]) {\n commons.push_back(str1.substr(0, i + 1)...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n vector <string> vec1;\n vector <string> vec2;\n string ans = \"\";\n string temp = \"\";\n string str3 = \"\";\n\n int minsize = min(str1.length(), str2.length());\n\n if (minsi...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string s1, string s2) {\n \n if(s1.length()==s2.length())\n {if(s1==s2) return s1;\n else\n return \"\";\n }\n if(s1.length()<s2.length())\n {\n string tmp=s1;\n s1=s2...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n std::string smaller_str;\n if (str1.size() <= str2.size()) {\n smaller_str = str1;\n }\n else {\n smaller_str = str2;\n }\n \n for (int i=smaller_str.size(...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "#include <algorithm>\n\nclass Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n string token = str1.size() > str2.size() ? str2 : str1;\n \n while (token.size()) {\n if (valid(str1, token) && valid(str2, token)) break;\n token.pop_back();\...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string s1, string s2) {\n \n if(s1.length()==s2.length())\n {if(s1==s2) return s1;\n else\n return \"\";\n }\n if(s1.length()<s2.length())\n {\n string tmp=s1;\n s1=s2...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\nprivate:\n bool check_divisable(string input, string divisor)\n {\n int len = input.length();\n int div_len = divisor.length();\n if (len % div_len)\n {\n return false;\n }\n int checked_len = 0;\n for (int i = 0; i < len; ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool divisor(string divisor , string str){\n while(str.length()>=divisor.length()){\n if(str.find(divisor)!= string::npos){\n int x = str.find(divisor);\n if(x!=0){\n return false;\n }\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string another_method(string a, string b)\n {\n while (true)\n {\n if (a[0] != b[0]) return \"\";\n bool flag2 = true;\n int i;\n for (i = 0; i < a.size(); i += b.size())\n {\n if (a.substr...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n string temp;\n string output;\n int w1 = str1.size();\n int w2 = str2.size();\n\n string *larger;\n string *smaller;\n int times = 0;\n int small;\n if (w1>w2) {\n...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "#include <iostream>\n\nclass Solution {\npublic:\n std::string repeat(const std::string& str, int times) {\n std::string result;\n result.reserve(str.size() * times);\n for (int i = 0; i < times; ++i) {\n result += str;\n }\n return result;\n }\n strin...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution\n{\n public:\n string gcdOfStrings(string str1, string str2)\n {\n string lStr = str1.size() > str2.size() ? str1 : str2;\n string sStr = str1.size() > str2.size() ? str2 : str1;\n\n for (size_t i = sStr.size(); i > 0; --i)\n {\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool divisable(string& s, string& t) {\n if (s.size() % t.size() != 0) return false;\n for (int i = 0; i < s.size(); i++) { \n if (s[i] != t[i % t.size()]) return false;\n }\n return true;\n }\n\n string gcdOfStrings(string str1, s...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool checkIfDivides(string s1, string s2){\n if(s2.size()%s1.size()!= 0)\n return false;\n int times = s2.size() / s1.size();\n string newS = \"\";\n for(int i = 0; i < times; i++){\n newS += s1;\n }\n return new...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool check(string x, string s)\n {\n int n1 = x.length();\n int n2 = s.length();\n int i;\n\n for(i=0; i+n1-1<n2; i+=n1)\n {\n for(int j=0; j<n1; j++)\n {\n if(s[j+i] != x[j])\n {\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n\n bool check(string s1, string s2){\n int i=0;\n int j=0;\n\n while(i<s1.size()){\n if(s1[i]!=s2[j]){\n return 0;\n }\n\n i++;\n j++;\n if(j==s2.size()){\n j=0;\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n\n int to_int(string char_string) {\n int sum = 0;\n for (char i : char_string) {\n sum += static_cast<int>(i);\n }\n return sum;\n }\n\n string gcdOfStrings(string str1, string str2) {\n std::string smaller = (str1 < str2) ?...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool doesDivide(string str, string div){\n int dl = div.length(), sl = str.length();\n if(sl%dl != 0) return false;\n for(int i=0; i<sl; i++){\n if(str[i]!=div[(i%dl)]) return false;\n }\n return true;\n }\n string gcdOfStri...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n set<string> solve(string & str){\n string temp=\"\";\n set<string> ans;\n for(int i=0;i<str.length();i++){\n temp.push_back(str[i]);\n int flag=0;\n for(int j=i+1;j<str.length();j+=(i+1)){\n if(str.substr(j,...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\n public:\n string gcdOfStrings(string s1, string s2){\n string ans=\"\";\n string s =\"\";\n for(int i=0 ; i<s1.length() ; i++){\n s+=s1[i];\n int j=0;\n while(j<s2.length()){\n if(s2.substr(j,s.length()) != s){\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool gcd(string str, string div)\n {\n if(str.size()%div.size() != 0)\n return 0;\n int s = div.size();\n for(int i=0; i<str.size(); i+=s)\n {\n if(str.substr(i, s) != div)\n return 0;\n }\n return 1;\n...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool gcd(string str, string div)\n {\n if(str.size()%div.size() != 0)\n return 0;\n int s = div.size();\n for(int i=0; i<str.size(); i+=s)\n {\n if(str.substr(i, s) != div)\n return 0;\n }\n return 1;\n...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isMatch(string s,string x) {\n int i,j,m=s.length(),n=x.length();\n if(m%n!=0)\n return false;\n for(i=0;i<m;i+=n) {\n if(s.substr(i,n)!=x)\n return false;\n }\n return true;\n }\n\n string gcd...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n int n = str1.length();\n int m = str2.length();\n string base = \"\";\n\n if (n < m)\n base = str1; //copy of the string is made automatically\n else\n base = str2;\n\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isdivide(string s,string t){\n \n if(t.size()%s.size()!=0)return false;\n int k=t.size()/s.size();\n string temp=\"\";\n for(int i=0;i<k;i++){\n temp+=s;\n }\n if(temp==t)return true;\n return false;\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n string returnVal = \"\";\n string* shorterString;\n string* longerString; \n if (str1.length() > str2.length()) {\n shorterString = &str2;\n longerString = &str1;\n } el...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool solver(string a,string b, int l)\n {\n if(a.size()%l!=0||b.size()%l!=0)\n return 0;\n for(int i=0;i<a.size();i++)\n {\n if(a[i]!=a[i%l])\n return 0;\n }\n for(int i=0;i<b.size();i++)\n {\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "#include <sstream>\n#include <iostream>\n\nclass Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n if(str1.empty() || str2.empty()){\n return \"\";\n }\n\n string divisor = str1;\n\n if(str2.size() < str1.size()){\n divisor = str2;\...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n bool str1_shorter = str1.size() < str2.size() ? 1 : 0;\n if (str1_shorter) {\n int count = 0;\n for (int i = 0; i < str1.size(); i++) {\n if (str1[i] == str2[i]) {\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n int n = str1.length();\n int m = str2.length();\n if(n<m){\n swap(str1, str2);\n swap(n, m);\n }\n string ans = \"\";\n for(int i = 1;i<=m;i++){\n stri...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool valid(string str1, string str2, int k) {\n int len1 = str1.size(), len2 = str2.size();\n if (len1 % k > 0 || len2 % k > 0) {\n return false;\n } else {\n string base = str1.substr(0, k);\n int n1 = len1 / k, n2 = len2...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string joinWords(int f, string s) {\n string ans = \"\";\n for (int i = 0; i < f; i++) {\n ans += s;\n }\n return ans;\n }\n bool helper(string str1, string str2, int l) {\n int len1 = str1.size();\n int len2 = str2.s...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool valid(string str1, string str2, int k) {\n int len1 = str1.size(), len2 = str2.size();\n if (len1 % k > 0 || len2 % k > 0) {\n return false;\n } else {\n string base = str1.substr(0, k);\n int n1 = len1 / k, n2 = le...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isDivisor(int gcdLen, int str1Len, int str2Len, string str1, string str2){\n if(str1Len % gcdLen || str2Len % gcdLen){\n // Check if gcdLen is a factor of the original strings\n return false;\n }\n\n int factor1 = str1Len / gcdL...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n string base=str1.size() > str2.size()?str2:str1;\n for(int l = base.size(); l>=1; l--) {\n if (isGcd(l, str1, str2)){ \n return base.substr(0,l);\n }\n }\n retur...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string joinStr(string s, int i) {\n string res;\n while(i--) {\n res = res + s;\n }\n return res;\n }\n\n bool validStr(string s1, string s2, int i) {\n int size1 = s1.size(), size2 = s2.size();\n if(size1 % i != 0 or...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool valid(string s1,string s2,int k)\n {\n int l1 = s1.length();\n int l2 = s2.length();\n if(l1%k > 0 || l1%k >0)\n return false;\n else\n {\n string base=s1.substr(0,k);\n int n1 = l1/k ,n2=l2/k;\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool valid(string str1,string str2,int n,int m){\n if((n%m)!=0) return false;\n cout<<n<<' '<<m<<endl;\n for(int i=0;i<n-m+1;i+=m){\n string t = str1.substr(i,m);\n if(t!=str2) return false;\n }\n return true;\n }\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isvalid(string s1, string s2, int k){\n int l1=s1.length(),l2=s2.length();\n if(l1%k!=0 && l2%k!=0){\n return false;\n }\n string base=s1.substr(0, k);\n return (s1==join(base, l1/k) ) && (s2==join(base, l2/k));\n }\n s...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isDiv(int l, string str1, string str2) {\n\n if (((str2.length()) % l) || ((str2.length()) % l))\n return false;\n\n string a1 = \"\";\n string a2 = \"\";\n\n for (int i = 0; i < ((str1.length()) / l); i++) {\n a1 += str1...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool check(string ans, string str1) {\n int n = ans.size();\n int m = str1.size();\n if (m % n != 0)\n return false;\n for (int i = 0; i < m; i += n) {\n if (str1.substr(i, n) != ans)return false ;\n }\n return...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\nprivate:\n bool divides(string str1, string str2) {\n if(str2 == \"\") return true;\n if(str1.size()%(str2.size()) != 0) {\n return false;\n }\n string temp = str2;\n while(str1.size() > temp.size()) {\n temp += str2;\n }\...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n\tstring gcdOfStrings(string str1, string str2) {\n\t\tstring d = str1.size() > str2.size() ? str2 : str1;\n\t\tvector<string> subStrL;\n\t\tfor (size_t i = 1; i <= d.size(); i++) {\n\t\t\tint foundIdx = 0;\n\t\t\tint count = 0;\n\t\t\twhile (foundIdx < d.size()) {\n\t\t\t\tfound...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n string gcd = \"\";\n int gcdLen = 0;\n if (str1.length() == str2.length()) {\n if (str1 == str2) return str1;\n else return \"\";\n }\n\n if (str1.length() < str2.length...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n string gcd = \"\";\n int gcdLen = 0;\n if (str1.length() == str2.length()) {\n if (str1 == str2) return str1;\n else return \"\";\n }\n\n std::set<char> uniques;\n\n\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isDivisor(string str1 ,string str2, int len1, int len2, int l){\n if(len1 % l && len2 % l){\n return false;\n }\n int f1 = len1 / l, f2 = len2 / l;\n int i = f1, j = f2;\n string res = \"\";\n while(i != 0){\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n //int i=0;\n int l1 = str1.size();\n int l2 = str2.size();\n string divisor = \"\";\n //int dL = 1; // divisor length\n\n if (str1[0] != str2[0]) {\n return divisor;\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool checker(string str1, string str2) {\n if (str1.length() % str2.length() != 0) return false;\n int step = str2.length();\n\n int cnt = str1.length() / str2.length();\n\n //cout << \"1: \" << str1 << \", \" << str2 << endl;\n\n for (int i...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isgcd(string &pre, string &tar){\n for(int i = 0 ; i < tar.size() ;i+=pre.size()){\n if(tar.substr(i,pre.size()) != pre)return false;\n }\n return true;\n }\n \n string gcdOfStrings(string str1, string str2) {\n if (str1[0] !...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n bool isPossible(string &s1,string &s2,string s){\n if(s.length()==0)return true;\n int i=0;\n while(i<s1.length()){\n string temp = s1.substr(i,s.length());\n if(temp!=s)return false;\n i=i+s.length();\n }\n\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n\n string ret_str;\n string shortest_str = str1.size() < str2.size() ? str1 : str2;\n auto size = shortest_str.size();\n while (ret_str.empty() && size > 0) {\n string str1_copy = str1;\n ...
1,146
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p> <p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the l...
3
{ "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n int len=min(str1.size(),str2.size());\n string ans=\"\";\n for(int i=1;i<=len;i++)\n {\n string str=str2.substr(0,i);\n bool flag=true;\n for(int j=0;j<str1.size();j...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n if(word.length()==1)\n return true; \n int counter=0;\n bool first = isupper(word[0]); \n for(int i = 0; i<word.length(); i++){\n if(isupper(word[i])){\n counter++;\n ...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n int cap=0;\n int nocap=0;\n int n=word.length();\n\n for(int i=0;i<word.length();i++)\n {\n if(word[i]>='A' and word[i]<='Z')\n cap++;\n else\n nocap+...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string s) {\n bool flag=false;\n int count=0;\n if(s[0]>='A' && s[0]<='Z'){\n flag=true;\n }\n for(int i=0;i<s.size();i++){\n if(s[i]>='A' && s[i]<='Z'){\n count++;\n ...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n int n=word.length(),c=0;\n for (char ch:word)\n {\n if(isupper(ch))\n {\n c++;\n }\n } \n if(c==0 || c==n ||c==1 && isupper(word[0])){\n return true;\n }\n ret...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n int n=word.length();\n int c=0;\n for(char ch:word){\n if(isupper(ch)){\n c++;\n }}\n if(c==0||c==n||(c==1&&isupper(word[0]))){\n return true;\n\n }\n ...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n // 'a' <= ? <= 'z' and 'A' <= ? <= 'Z'\n int failcheck = 0;\n if ('a' <= word[0] && word[0] <= 'z') {\n for (int i = 1; i < word.length(); i++) {\n if ('a' > word[i] || word[i] > 'z') { fail...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
0
{ "code": "class Solution {\npublic:\nint countcaps(string &s){\n int cnt=0;\n for(int i=0;i<s.length();i++){\n if(isupper(s[i])){\n cnt++;\n }\n }\n return cnt;\n}\n bool detectCapitalUse(string word) {\n int cnt=countcaps(word);\n if(cnt==0||cnt==word.length()){...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
1
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n int n = word.size();\n if (n == 0) return true;\n\n bool upper = true;\n bool lower= true;\n bool firstuppredlow = true;\n \n for (int i = 0; i < n; ++i) {\n if (isupper(word[i...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
1
{ "code": "class Solution {\n public:\n bool detectCapitalUse(string word) {\n for (int i = 1; i < word.length(); ++i)\n if (isupper(word[1]) != isupper(word[i]) ||\n islower(word[0]) && isupper(word[i]))\n return false;\n return true;\n }\n};", "memory": "7800" }
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
3
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n \n int cnt=0;\n if(word[0]>='A' && word[0]<='Z'){\n if(word[1] >='a' && word[1]<='z'){\n for(int i=2;i<word.size();i++){\n if(word[...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
3
{ "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n int c=0;\n for(int i=0;i<word.size();i++)\n {\n if(isupper(word[i]))\n {\n c++;\n }\n }\n\n if(c==word.size())\n {\n return true;\n...
520
<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p> <ul> <li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li> <li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li> <li>Only the first letter in this wo...
3
{ "code": "class Solution {\npublic:\n bool isuppercase(string word){\n for(int i = 0; i<word.length(); i++){\n char one = word[i];\n if(one >= 'A' && one <= 'Z'){\n continue;\n }\n\n else\n {\n return false;\n }...
521
<p>Given two strings <code>a</code> and <code>b</code>, return <em>the length of the <strong>longest uncommon subsequence</strong> between </em><code>a</code> <em>and</em> <code>b</code>. <em>If no such uncommon subsequence exists, return</em> <code>-1</code><em>.</em></p> <p>An <strong>uncommon subsequence</strong> b...
0
{ "code": "class Solution {\npublic:\n [[nodiscard]]\n auto findLUSlength(const std::string_view a, const std::string_view b) const\n -> int\n {\n return a == b ? -1 : std::max(a.length(), b.length());\n }\n};", "memory": "7300" }
521
<p>Given two strings <code>a</code> and <code>b</code>, return <em>the length of the <strong>longest uncommon subsequence</strong> between </em><code>a</code> <em>and</em> <code>b</code>. <em>If no such uncommon subsequence exists, return</em> <code>-1</code><em>.</em></p> <p>An <strong>uncommon subsequence</strong> b...
0
{ "code": "class Solution {\npublic:\n int findLUSlength(string a, string b) {\n int len1=a.length();\n int len2=b.length();\n if(a==b)\n {\n return -1;\n }\n if(len1>len2)\n {\n return len1;\n }\n else\n {\n ...
521
<p>Given two strings <code>a</code> and <code>b</code>, return <em>the length of the <strong>longest uncommon subsequence</strong> between </em><code>a</code> <em>and</em> <code>b</code>. <em>If no such uncommon subsequence exists, return</em> <code>-1</code><em>.</em></p> <p>An <strong>uncommon subsequence</strong> b...
0
{ "code": "class Solution {\npublic:\n int findLUSlength(string a, string b) {\n if(a==b)return -1;\n return max(a.size(),b.size());\n }\n};", "memory": "7400" }
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution {\npublic:\n string complexNumberMultiply(string s, string t) {\n int a=0,b=0,x=0,y=0;\n int idx=0;\n bool isneg=false;\n while(s[idx]!='+')\n {\n if(s[idx]=='-')\n {\n isneg=true;\n }\n else if(...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n int mar=0,a1=0,a2=0,b1=0,b2=0,a1s=0,a2s=0,b1s=0,b2s=0;\n if(num1[0]=='-'){\n a1s=1;\n }\n for(int i=0;i<num1.size();i++){\n if(a1s && i==0 ){\n continue...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n int i=0;\n string temp1 = \"\";\n while(num1[i] != '+'){\n temp1 += num1[i];\n i++;\n }\n i++;\n string temp2 = \"\";\n while(num1[i] != 'i'){\n ...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution{\npublic://Buffetts > Restaurants | If you have a bad day, orfer fast food \"for here\" (McDonalds/Burger King) Order anything for $1 order and order a small drink. Drink as much Moutain Dew as possible. Clean up after yourself, and clean up the store while you're drinking.\n string compl...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution {\npublic:\n pair<int,int> getNumber(string n){\n string real=\"\";\n string img=\"\";\n\n int i=(n[0]=='-')?1:0;\n\n char sign1=(n[0]=='-')?'-':'+';\n\n while(n[i]!='+'){\n real+=n[i];\n i++;\n }\n\n while(!isdigit(n[...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n int r1 = 0, i1 = 0, r2 = 0, i2 = 0;\n // first string\n // real\n int i = 0;\n if(num1[0] == '-') i++;\n while(num1[i] != '+') {\n r1 *= 10;\n r1 += num1...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
0
{ "code": "class Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n int idx=0;\n int n=num1.size();\n for(int i=0;i<n;i++)\n {\n if(num1[i]=='+')\n {\n idx=i;\n break;\n }\n }\n in...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
2
{ "code": "class Solution {\n public:\n string complexNumberMultiply(string a, string b) {\n const auto& [A, B] = getRealAndImag(a);\n const auto& [C, D] = getRealAndImag(b);\n return to_string(A * C - B * D) + \"+\" + to_string(A * D + B * C) + \"i\";\n }\n\n private:\n pair<int, int> getRealAndImag(cons...
537
<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p> <ul> <li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</...
2
{ "code": "class Solution {\npublic:\n pair<int,int> getNumber(string n){\n string real=\"\";\n string img=\"\";\n\n int i=(n[0]=='-')?1:0;\n\n char sign1=(n[0]=='-')?'-':'+';\n\n while(n[i]!='+'){\n real+=n[i];\n i++;\n }\n\n while(!isdigit(n[...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
0
{ "code": "class Solution {\n public:\n TreeNode* convertBST(TreeNode* root) {\n int prefix = 0;\n reversedInorder(root, prefix);\n return root;\n }\n\n private:\n void reversedInorder(TreeNode* root, int& prefix) {\n if (root == nullptr)\n return;\n\n reversedInorder(root->right, prefix);\n ...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
3
{ "code": "class Solution {\n\nint getSum(TreeNode* rt) {\n\tif (rt == NULL) {\n\t\treturn 0;\n\t}\n\treturn rt->val + getSum(rt->left) + getSum(rt->right);\n}\n\nint sum;\n\nvector<TreeNode*> inorder;\n\nvoid inorderTraversal(TreeNode* rt) { // returns sum of subtree\n\tif (rt == NULL) {\n\t\treturn;\n\t}\n\tinorder...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...
538
<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p> <p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints...
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...