id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "#include <iostream>\n#include <sstream>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string reversestring(string &s, int start, int end) {\n while (start < end) {\n swap(s[start++], s[end--]);\n }\n return s;\n }\n\n string reverseWords(st... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "\nclass Solution {\npublic:\n // Function to remove extra spaces\n string removeExtraSpaces(const string& s) {\n string result;\n bool inSpace = false;\n\n for (char ch : s) {\n if (ch != ' ') {\n // If it's a non-space character, add it to the result\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string revs(string s, int x, int y){\n string res = s.substr(x, y-x);\n reverse(res.begin(), res.end());\n return res;\n }\n string removespace(string s){\n int slow = 0;\n bool flag = false;\n string res;\n for(int fast ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n string ans = \"\";\n\n int x = s.size() - 1;\n while (s[x] == ' ') {\n x--;\n }\n\n int y = 0;\n while (s[y] == ' ') {\n y++;\n }\n\n string temp = \"\";\n f... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n string o=\"\";\n int i=s.size()-1;\n while(i>=0){\n string istr=\"\";\n if(i>=0 && s[i]==' ') i--;\n else{\n if(o.size()!=0) o=o+\" \";\n while(i>=0 && s[i]!=... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n string str = \"\",ans = \"\";\n for(int i=0;i<s.size();i++)\n {\n if(s[i] == ' ' && str != \"\")\n {\n ans = str+ans;\n ans =\" \"+ans;\n str = \"\";\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "// class Solution {\n// public:\n// string reverseWords(string s) {\n// int p1 = s.length()-1;\n// int p2 = s.length()-1;\n// string str;\n\n// while (p1>=0){\n// if (p1 >= 0 && s[p1] == ' ') {\n// p1--;\n// p2--;\n// ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "#include<cstring>\nclass Solution {\npublic:\n string reverseWords(string s) {\n string ans=\"\";\n char ch[s.size()+1];\n strcpy(ch,s.c_str());\n char *p=strtok(ch,\" \");\n stack<string> st;\n while(p!=NULL)\n {\n st.push(p);\n p=s... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n int n=s.length();\n string ans;\n int cnt=0;\n vector <string> v;\n for(int i=0;i<n;i++)\n {\n if(s[i]!=' ')\n {\n ans=ans+s[i];\n }\n else\n... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "#include <iostream>\nusing namespace std;\nclass Solution {\npublic:\n string reverseWords(string s) {\n string word=\"\";\n string output=\"\";\n char c;\n vector<string> words;\n //making vector of all words\n for(int i = 0 ; i<s.size() ; ++i){\n c=... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n stack<string>st;\n int start = 0;\n int end = s.length();\n while(s[start]==' '){\n start++;\n }\n while(s[end]==' '){\n end--;\n }\n for(int i = start ; i<end ; i... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n vector<string> result;\n string r = \"\";\n istringstream stream(s);\n string word;\n\n while(stream >> word){\n result.insert(result.begin(), word);\n result.insert(result.begin(), \" \");\n }\n result.eras... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n vector<string> result;\n string r = \"\";\n istringstream stream(s);\n string word;\n\n while(stream >> word){\n result.insert(result.begin(), word);\n result.insert(result.begin(), \" \");\n }\n result.eras... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n vector<string> v;\n string x=\"\";\n for(int i=0;i<s.size();i++){\n \n if(isspace(s[i])){\n if(x.empty()){\n x=x+\" \";\n v.push_back(x);\n }\n else ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n string ans;\n\n string b;\n\n string a;\n\n vector<string> arr;\n\n int i;\n for (i=0;i<=(s.size () -1);i++) {\n if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >=... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n /*\n s.substr(st2, ed2-st2+1) + s.substr(ed1+1, st2-ed1-1) + s.substr(st1, ed1-st1+1)\n */\n while(s[0]==' '){\n s = s.erase(0, 1);\n }\n reverse(s.begin(),s.end());\n while(s[0]==' ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n \n string temp,fin;\n vector<string> str;\n\n for(auto i:s){\n if(i==' '){\n if(temp==\"\")\n continue;\n else{\n str.push_back(temp);\... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverse(string &s,int i,int j){\n while(i<=j){\n swap(s[i],s[j]);\n i++;\n j--;\n }\n return s;\n }\n\n string reverseWords(string s) {\n int i=0,j=0;\n s.push_back(' ');\n while(i<s.lengt... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n int i = 0, j = 0, n = s.size();\n string tmp = \"\";\n s += '!';\n while(1){\n while(s[i]!='!' && s[i] != ' '){\n tmp += s[i];\n // cout << tmp << \" \";\n s.... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n int i = 0, j = 0, n = s.size();\n string tmp = \"\";\n s += '!';\n while(1){\n while(s[i]!='!' && s[i] != ' '){\n tmp += s[i];\n // cout << tmp << \" \";\n s.... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n int i = 0, j = 0, n = s.size();\n string tmp = \"\";\n s += '!';\n while(1){\n while(s[i]!='!' && s[i] != ' '){\n tmp += s[i];\n // cout << tmp << \" \";\n s.... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n void swap(char& a, char& b){\n char temp;\n temp = a;\n a= b;\n b = temp;\n }\n string reverse(string& s, int low, int high){\n while(low < high){\n swap(s[low],s[high]);\n low++;\n high--;\n }\n... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n void swap(char& a, char& b){\n char temp;\n temp = a;\n a= b;\n b = temp;\n }\n string reverse(string& s, int low, int high){\n while(low < high){\n swap(s[low],s[high]);\n low++;\n high--;\n }\n... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n\n void putword(string &ans, string s, int i, int j) {\n j++; // Move j to the next character after the space\n for (int k = j; k <= i; k++) {\n ans += s[k];\n }\n}\n\nstring reverseWords(string s) {\n int n = s.length();\n string ans = \"\";\n int i = n... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "#include <algorithm>\n#include <string>\n\nclass Solution {\n string reverseSubstring(int i, int j, string &s) {\n while (i < j) {\n swap(s[i], s[j]);\n i++;\n j--;\n }\n return s;\n }\n\npublic:\n string reverseWords(string s) {\n rever... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n\n string reverseUtil(int i, int j, string s){\n // cout<<i<<\" \"<<j<<\" \"<<s<<\"\\n\";\n while(i < j){\n char c = s[i];\n s[i] = s[j];\n s[j] = c;\n i++;\n j--;\n }\n // cout<<s<<\"\\n\";\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n s = \" \" + s + \" \";\n reverseString(s, 0, s.length() - 1);\n \n int spaceCount = 1, j = 1;\n for (int i = 1; i < s.length(); i++) {\n if (s[i] != ' ') {\n spaceCount = 0;\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverse(string s,int st,int end){\n string res=\"\";\n for(int i=st;i<=end;i++)\n res+=s[i];\n return res;\n }\n string reverseWords(string s) {\n string ans=\"\";\n int n= s.length();\n int st=0,end=n-1;\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverse(string s,int start,int end){\n string ans;\n for(int i=end;i>=start;i--){\n ans+=s[i];\n }\n return ans;\n }\n string reverseWords(string s) {\n int start=0,end=-1;\n string ans;\n bool flag=fals... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverse(string s,int i,int j){\n string temp=\"\";\n while(j>=i){\n temp+=s[i];\n i++;\n }\n return temp;\n }\n int start = -1;\n int end = -1;\n string reverseWords(string s) {\n string ans=\"\";\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string customReverse(string s, int i, int j){\n string ans = \"\";\n for(int ind = j;ind>=i;ind--){\n ans+=s[ind];\n }\n return ans;\n }\n\n string reverseWords(string s) {\n int n = s.length();\n int i=0;\n wh... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverse(string s, int start, int end){\n string temp = \"\";\n for(int i=end;i>=start;i--){\n temp+=s[i];\n }\n return temp;\n }\n string reverseWords(string s) {\n int n = s.length();\n s = reverse(s, 0, n-1);... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverse(string s, int start, int end){\n string temp = \"\";\n for(int i=end;i>=start;i--){\n temp+=s[i];\n }\n return temp;\n }\n string reverseWords(string s) {\n int n = s.length();\n s = reverse(s, 0, n-1);... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string revs(int i, int j, string s){\n string res;\n if(i == j) return res+s[i];\n while(i <= j){\n res += s[j];\n j--;\n }\n return res;\n\n }\n string reverseWords(string s) {\n int m = 0;\n for(m ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n vector<string*> temp; // A string of tokens\n int start = -1;\n // In the following loop, start is valid only\n // in a very short while. A new token is added to temp, and\n // start is immediately reset.\n... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n vector<string> tokens;\n string reversed;\n\n cout << s << endl;\n for (int i = 0; i < s.length(); i++) {\n if (isspace(s[i]))\n continue;\n\n int j = next_pos(s, i);\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n int i=0;\n while(s[i]==' ')i++;\n return result(s,i);\n }\n string result(string s,int i){\n string ans;\n int n=s.size();\n while(i<n&&s[i]!=' '){\n ans+=s[i];\n i++;\n ... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n std::string NextWord(std::string s, int &next) {\n while (next != s.length() && s[next] == ' ') ++next;\n std::stringstream ss;\n while (next != s.length() && s[next] != ' ') ss << s[next++];\n return ss.str();\n }\n string reverseWords(stri... |
151 | <p>Given an input string <code>s</code>, reverse the order of the <strong>words</strong>.</p>
<p>A <strong>word</strong> is defined as a sequence of non-space characters. The <strong>words</strong> in <code>s</code> will be separated by at least one space.</p>
<p>Return <em>a string of the words in reverse order conc... | 3 | {
"code": "class Solution {\npublic:\n string reverseWords(string s) {\n string ans=\"\";\n string temp=\"\";\n for(int i =s.length()-1;i>=0;i--){\n char c =s[i];\n if(c!=' '){\n temp+=s[i];\n }\n else if (!temp.empty()){\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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... | 0 | {
"code": "class Solution {\npublic:\n string gcdOfStrings(const string& s1, const string& s2)\n {\n int ans = 0;\n int len = 1, n = s1.size(), m = s2.size();\n \n while(len <= n && len <= m){\n int i=0, j=0, k = 0;\n bool possible = true;\n\n if(n%le... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // find the smallest\n string small;\n string big;\n\n if (str1.length() > str2.length()) {\n small = str2;\n big = str1;\n } else {\n small = str1;\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 if (str1 == str2) return str1;\n int i = 0;\n for (; i < min(str1.length(), str2.length()); i++) {\n if (str1[i] != str2[i]) break;\n }\n if (i == 0) return \"\";\n if (str1... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 if(str1.empty()){\n return str2;\n }\n if(str2.empty()){\n return str1;\n }\n if(str1.length()>str2.length()){\n if(str1.find(str2)==0){\n return gcdOfStrings(str1.... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 divideStrings(string str1, string str2) {\n if (str2.length() > str1.length()) {\n string tmp = str2;\n str2 = str1;\n str1 = tmp;\n }\n while (str1.length() >= str2.length()) {\n if (str1 == str2) return... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 ans=\"\";\n int n=str2.size();\n int m=str1.size();\n string st=\"\";\n\n for(int i=0;i<n;i++) {\n bool flag=1;\n st+=str2[i];\n int k=st.size();\n i... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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.size();\n int m=str2.size();\n int minn=min(n,m);\n string minstr=\"\";\n string nonmin=str1;\n if(minn==n) {minstr=str1;\n nonmin=str2;}\n else minstr=str2;\n... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 len1 = str1.length();\n int len2 = str2.length();\n\n // The length of the GCD is a CD of the lengths\n\n string candidate = \"\";\n \n for(int i=1; i<=min(len1, len2); i++) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 GCD = \"\";\n\n\n string tempGCD = \"\";\n\n for (int i = 0; i < (str1.length()); i++){\n\n\n \n tempGCD += str1[i];\n\n bool gcdStrBool = true;\n if (s... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 bool divide(string str1, string str2, string prefix)\n {\n while(str1.length() > 0)\n {\n if(str1.substr(0, prefix.length()) == prefix)\n {\n str1.erase(0, prefix.length());\n }\n else\n {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // go through both str, find common substring from index 0 until a mismatch happend\n int i = 0;\n string gcd = \"\";\n string greatestGcd = \"\";\n while(i < str1.length() && i < str2.length... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 bool isDivider(const string& devider, const string& str)\n {\n int sizeDev = devider.length();\n int sizeStr = str.length();\n \n if(sizeStr%sizeDev!=0)\n return false;\n\n int numberOfIterations = sizeStr/sizeDev;\n string temp;... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 vector<string> divide(string test){\n vector<int>factors;\n for(int i=1;i<=test.length();i++){\n if(test.length()%i==0)factors.push_back(i);\n }\n vector<string>strcut;\n for(int i=0;i<factors.size();i++){\n string pre ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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(const std::string& str, const std::string& divisor) {\n if (str == divisor) {\n return true;\n }\n\n if (str.size() % divisor.size() != 0) {\n return false;\n }\n\n int64_t parts_count = str.size() / divi... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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(const std::string& str, const std::string& divisor) {\n if (str == divisor) {\n return true;\n }\n\n if (str.size() % divisor.size() != 0) {\n return false;\n }\n\n int64_t parts_count = str.size() / divi... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 int gcd(int a, int b)\n {\n int e = min(a, b);\n for(int i = e; i > 0; i--)\n {\n if(a % i == 0 && b % i == 0) return i;\n }\n return 1;\n }\n string gcdOfStrings(string str1, string str2)\n {\n string out = \"\... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 checkDivisible(string s, string t) {\n int m = s.length();\n int n = t.length();\n int q = m/n;\n string temp = \"\";\n for(int i = 0; i < q; i++) {\n temp += t;\n }\n return (s == temp);\n }\n\n string ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 ok(string a, string b){\n int m = a.size();\n int n = b.size();\n m/=n;\n string temp = \"\";\n while(m--){\n temp += b;\n }\n return a==temp;\n }\n string gcdOfStrings(string str1, string str2) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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(int i, string& str1, string& str2) {\n string f1 = \"\";\n string f2 = \"\";\n string modStr1 = str1.substr(0, i);\n string modStr2 = str2.substr(0, i);\n int times1 = str1.length() / i;\n int times2 = str2.length() / i;\n... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 isValidDiv(string& str1, string& str2) {\n const int s1 = str1.size(), s2 = str2.size(); // 6, 3\n if (s1 % s2 != 0) {\n return false;\n }\n\n for (int i = 0; i < s1; i += s2) {\n for (int j = i; j < i+s2; j++) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 isValidDiv(string& str1, string& str2) {\n const int s1 = str1.size(), s2 = str2.size(); // 6, 3\n if (s1 % s2 != 0) {\n return false;\n }\n\n for (int i = 0; i < s1; i += s2) {\n for (int j = i; j < i+s2; j++) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // base case\n if(str1 + str2 != str2 + str1)\n {\n return \"\";\n }\n // we know there is an answer after base case, get length and find gcd\n int len1 = str1.length... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 str, string target) {\n int j = 0;\n for (int i = 0; i < str.size(); i++) {\n if (str[i] != target[j]) return false;\n j = (j + 1) % target.size();\n }\n return true;\n }\n string gcdOfStrings(string... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 if (str1.size() < str2.size()) {\n return gcdOfStrings(str2, str1);\n }\n\n if (str1 == str2) {\n return str2;\n }\n\n for (int i = str2.size(); i > 0; --i) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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, str, base_bkp;\n int str1_len = str1.length();\n int str2_len = str2.length();\n int base_len, b_len;\n bool match_found = false;\n if (str1.length() > str2.length()) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 xx = 0, y = 0;\n int n = str1.size(), m = str2.size();\n if (n > m) {\n for (int i = m - 1; i >= 0; i--) {\n xx=0;\n string pref = str2.substr(0, i + 1);\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // Helper function to repeat a string `n` times\nstring repeatString(const string& str, int n) {\n string result;\n for (int i = 0; i < n; ++i) {\n result += str;\n }\n return result;\n}\n\n// Function to check if a given substring `ss` divides both str1 and... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // Helper function to check if 't' divides 's'\n bool divides(const string &s, const string &t) {\n int len_s = s.length();\n int len_t = t.length();\n \n if (len_s % len_t != 0) {\n return false; // If t cannot fit evenly into s\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // Step 1: Find the smaller of the two strings\n string minStr = (str1.length() < str2.length()) ? str1 : str2;\n\n // Step 2: Try each substring of the smaller string, starting from the longest\n f... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // cheapest does divide check\n // does substring*len(string)/len(substring) = string\n\n // need a find longest repetitive string check\n // string and all of string[i:j] for j-i e {0:length}\n // once we find one, use it\n\n // find longest string for both\... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // cheapest does divide check\n // does substring*len(string)/len(substring) = string\n\n // need a find longest repetitive string check\n // string and all of string[i:j] for j-i e {0:length}\n // once we find one, use it\n\n // find longest string for both\... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 if(str1 == str2) return str1;\n // If str1 and str2 have a common divisor then one of them will be a substr of the other gcd*m vs gcd*n\n string common;\n int m = str1.length();\n int n = str... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 auto valid = [&](string s){\n int len = s.size();\n if (str1.size()%len!=0 && str2.size()%len!=0){\n return false;\n }\n int n1 = str1.size()/len , n2 = str2.si... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 checkDivisibility(string s1, string s2) {\n if (s1.size() % s2.size() != 0)\n return false;\n\n int idx = 0, len = s2.size(), loop = s1.size() / s2.size();\n while (loop--) {\n if (s1.substr(idx, len) != s2) {\n r... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 key = str1 + \",\" + str2;\n cout << str1 << \" | \" << str2 << endl;\n if (str1.size() < str2.size()) {\n cout << \"wrong order\\n\";\n return gcdOfStrings(str2, str1);\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 s {\"\"}, lastValid{\"\"};\n if(str1 == str2)\n return str1;\n for(int i = 0; i<std::min(str1.size(), str2.size()); ++i) {\n if(i > std::max(str1.size(), str2.size())/2)\n... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 repeat(const string& str,const string& mode)\n {\n auto size = mode.size();\n auto str_size = str.size();\n int i=size;\n int j=i+size;\n\n while(j<=str_size)\n {\n auto sub = str.substr(i,j-i);\n if(sub ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 auto isDivisor = [&](string& div) {\n int n = div.size();\n int i = 0;\n while (i < str1.size()) {\n if (i + n <= str1.size()) {\n if (str1.substr(i, n)... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 list<string> factorOfString(string str){\n int strSize = str.size();\n list<string> factors;\n for(int i=1;i<=(strSize)/2;i++){\n string substring = str.substr(0,i);\n int flag = 1;\n if(strSize%i!=0)\n cont... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 private:\n inline string getCommonPrefix(const string &str1,\n const string &str2) const {\n size_t i = 0;\n for (; i < str1.size() and i < str2.size(); ++i) {\n if (str1[i] != str2[i])\n break;\n }\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 for(int i = 0; i < str2.length(); i++){\n string currentStr = str2.substr(0, str2.length()-i);\n if(str1.length() % currentStr.length() != 0 || str2.length() % currentStr.length() != 0) continue;\n... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 for(int i = 0; i < str2.length(); i++){\n string currentStr = str2.substr(0, str2.length()-i);\n if(str1.length() % currentStr.length() != 0 || str2.length() % currentStr.length() != 0) continue;\n... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 for(int sz = str2.size(); sz >= 1; sz--) {\n string b = str2.substr(0, sz);\n if (str2.size() % sz) continue;\n bool w = true;\n for(int q = 0; q < str1.size(); q += sz) {\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // Ensure str1 is always the larger string, swap if necessary\n if (str1.length() < str2.length()) {\n swap(str1, str2);\n }\n \n // Initialize the answer as an empty string\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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": "#pragma GCC optimize(\"O2,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n string gcdOfStrings... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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(const std::string& ref, const std::string& to_find) {\n if (ref.size() % to_find.size() != 0) return false;\n for (int i = 0; i < ref.size(); i += to_find.size()) {\n if (ref.substr(i, to_find.size()) != to_find) return false;\n }\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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\n // Find common prefix of both strings.\n int len = 0;\n while (len < n1 && len < n2) {\n if (str1[len] == str2[len]) len++;\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 // you can try out all the different lengths\n // then check whether the same length is repeated\n // You know that the length of GCD must be a factor of the length of str1\n // and str2, so that's a way you can speed up the process\n // O(min(s1,s2) * (s1+s2))\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 = str2.size();\n int n1 =str1.size();\n int max_no = 0;\n \n string result;\n \n \n for(int l=1 ;l<=n && l<=n1 ;l++ ){\n string pattern = str1.substr(0 ,l);\... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 string temp = \"\";\n int n = min(str1.size(), str2.size());\n int i = 0;\n\n while(i<n){\n if(str1[i]!=str2[i])\n return \"\";\n tem... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 if(str1.size() < str2.size()){\n string temp = str1;\n str1 = str2;\n str2 = temp;\n }\n int m = str1.size();\n int n = str2.size();\n for(int i=n;i>0;i--){\n... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 if(str1+str2 != str2+str1){\n return \"\";\n }\n string main = str1+str2;\n int i=0;\n string result = \"\";\n while(i<str1.size() && i<str2.size()){\n string tem... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 res=\"\",ans=\"\";\n if(str1 == str2) return str1;\n for(int i=0;i<str1.size();i++){\n string s = res+=str1[i];\n int f=0;\n if(s.size()<=str1.size() && str1.size()%... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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#include <string> \n\nusing namespace std;\n\nclass Solution {\npublic:\n\n bool isDivisor(const string& substr, const string& str){\n\n string combinedStr = \"\"; \n int lengthDiv = str.length() % substr.length();\n\n if (lengthDiv != 0 ){\n return f... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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": "#pragma GCC optimize(\"O2,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n string gcdOfStrings... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 longer = str1.length() > str2.length() ? str1.length() : str2.length();\n bool failed = false;\n int len = longer;\n string divisor = str1.substr(0, len);\n\n for(int i = 0; i < longer+1;... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 longer = str1.length() > str2.length() ? str1.length() : str2.length();\n bool failed = false;\n int len = longer;\n string divisor = str1.substr(0, len);\n\n for(int i = 0; i < longer+1;... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 m = str1.size(), n = str2.size();\n\n string res = \"\";\n\n for (int len = 1; len <= m; len++) {\n string divisor = str1.substr(0, len);\n\n if (m % len) continue;\n i... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 curr_perfix = \"\", g_perfix = \"\";\n int i = 1;\n while (i <= str2.length()) {\n curr_perfix = str2.substr(0, i);\n int prefix_len = curr_perfix.length(), j = 0;\n ... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 pre = \"\";\n std::string pre2 = \"\";\n int max = -1;\n bool flag = false;\n for(int i = 1; i <= str2.length(); ++i){\n pre = str2.substr(0,i);\n flag = fal... |
1,146 | <p>For two strings <code>s</code> and <code>t</code>, we say "<code>t</code> divides <code>s</code>" 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 curr_perfix = \"\", g_perfix = \"\";\n int i = 1;\n while (i <= str2.length()) {\n curr_perfix = str2.substr(0, i);\n int prefix_len = curr_perfix.length(), j = 0;\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.