id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\n map<int, int> cache;\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if (amount == 0) return 0;\n if (amount < 0 || coins.size() == 0) return -1;\n auto r = coinChangeR(coins, amount);\n return r == INT_MAX ? -1: r;\n }\n int coinChan...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n map<int,int> memo;\n int coiner(vector<int>& coins, int amount,map<int,int>& memo) {\n if(amount==0){\n return 0;\n }\n if(amount<0){\n return -1;\n }\n if(memo.find(amount)!=memo.end()){\n return memo[amo...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if (amount == 0) {\n return 0;\n }\n\n // Sort coins in reverse order (largest to smallest)\n std::sort(coins.rbegin(), coins.rend());\n\n // Priority queue to store (count of coi...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n\n vector<int> dp ;\n void nbCoins(vector<int> coins ,int amount){\n if(amount == 0){\n return ;\n }\n int nb = amount+1;\n for( int i =0 ; i<coins.size() ; i++){\n int diff = amount - coins[i];\n if(diff<0){\n ...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\n\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if(amount == 0){return 0;}\n sort(coins.begin(), coins.end());\n int ind = coins.size()-1;\n int minn = 1e9;\n queue<pair<pair<int,int>,int>> q;\n q.push({{amount,0},ind});\n ...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) \n {\n if(amount == 0)\n return 0;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; // n coins, amt to make\n pq.push({0,amount});\n\n unordered_set<int>v...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n using node = pair<int, int>;\n\n int coinChange(vector<int>& coins, int amount) {\n // TLE\n // We can do a BFS\n // Regarding amount as the first node, coins are the edges\n // We make a node to track {current coin count, amount left}\n ...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n using node = pair<int, int>;\n\n int coinChange(vector<int>& coins, int amount) {\n // TLE\n // We can do a BFS\n // Regarding amount as the first node, coins are the edges\n // We make a node to track {current coin count, amount left}\n ...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n\n int memo(int i, vector<int>&coins, int amt, vector<vector<int>>&dp){\n if(i==0){\n if(amt%coins[0]==0) return amt/coins[0];\n else return 1e9;\n }\n \n if(dp[i][amt]!=-1) return dp[i][amt];\n\n int notPick =...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\nint noofcoins(vector<int>coins,int a,vector<vector<int>>&dp,int i,int n)\n{ vector<int>prev(a+1,0);\nfor(int i=0;i<=a;i++) {if(i%coins[0]==0) prev[i]=i/coins[0];\nelse prev[i]=1e9;\n}\n\nfor(int i=1;i<n;i++){\n vector<int>curr(a+1,0); \nfor(int j=0;j<=a;j++){\nint pick=INT_MAX...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int f(int i, int target, vector<int>& coins) {\n if(i == 0) {\n if(target % coins[i] == 0) return target / coins[i];\n return 1e9;\n }\n\n if(dp[i][target] != -1) return dp[i][target];\n\n int notp...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n int dp(vector<int>& coins, int amount, set<int> &s, map<int, int> &memo){\n if(memo.find(amount) != memo.end()){\n return memo[amount];\n }\n\n if(s.find(amount) != s.end()){\n memo[amount] = 1;\n return 1;\n }else ...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n #define DPSolver ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); \n map<int,int> memo;\n bool dpSolverFlag = false;\n int coinChange(vector<int>& coins, int amount, bool notFirstStep = false ) {\n if(!dpSolverFlag){\n DPSolver;\n dp...
322
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio...
3
{ "code": "class Solution {\npublic:\n \n unordered_map<int, long long> dp;\n long long recurse(int amount, vector<int>& coins) {\n if(amount < 0) return INT_MAX;\n if(amount == 0) return 0;\n if(dp.find(amount) != dp.end()) return dp[amount];\n long long ans = INT_MAX;\n f...
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
0
{ "code": "class Solution {\npublic:\n int poorPigs(int total, int minutesToDie, int minutesToTest) {\n if(total==1) return 0;\n int n= (minutesToTest / minutesToDie) +1;\n int p=n;\n int cnt=1;\n while( n<total){\n n=n*p; cnt++;\n }\n return cnt;\n }\...
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
0
{ "code": "class Solution {\n public:\n int poorPigs(int buckets, int timeDetect, int timeTest) {\n return ceil(log2(buckets)/log2(int(timeTest/timeDetect)+1));\n }\n };\n\n\n\n ", "memory": "7300" }
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
0
{ "code": "class Solution {\npublic:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n int trials = minutesToTest / minutesToDie + 1;\n int numPigs = 0;\n for (int testedBuckets = 1; testedBuckets < buckets; testedBuckets *= trials) {\n numPigs++;\n }\n ...
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
0
{ "code": "class Solution {\npublic:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n return ceil(log2(buckets)/log2(int(minutesToTest/minutesToDie)+1)); \n }\n};", "memory": "7400" }
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
1
{ "code": "class Solution {\n public:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n const int base = minutesToTest / minutesToDie + 1;\n int ans = 0;\n for (int x = 1; x < buckets; x *= base)\n ++ans;\n return ans;\n }\n};", "memory": "7500" }
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
1
{ "code": "class Solution {\npublic:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n return ceil(log2(buckets)/log2(int(minutesToTest/minutesToDie)+1));\n }\n};", "memory": "7500" }
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
2
{ "code": "\nclass Solution {\npublic:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n // Calculate the number of tests we can conduct within the given time\n int tests = minutesToTest / minutesToDie;\n \n // The number of possible states each pig can be in after th...
458
<p>There are <code>buckets</code> buckets of liquid, where <strong>exactly one</strong> of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have <code>minutesToTest</code> minutes to determine whic...
2
{ "code": "class Solution {\npublic:\n int poorPigs(int buckets, int timeDetect, int timeTest) {\n return ceil(log2(buckets)/log2(int(timeTest/timeDetect)+1));\n }\n};", "memory": "7600" }
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(const std::string& str)\n\t{\n\t\tconst int len = str.length();\n\t\tfor (int i = len / 2; i >= 1; --i)\n\t\t\tif (len % i == 0 && str.substr(0, len - i) == str.substr(i))\n\t\t\t\treturn true;\n\n\t\treturn false;\n\t}\n};", "memory": "32553" ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(const std::string& str)\n\t{\n\t\tconst int len = str.length();\n\t\tfor (int i = len / 2; i >= 1; --i)\n\t\t\tif (len % i == 0 && str.substr(0, len - i) == str.substr(i))\n\t\t\t\treturn true;\n\n\t\treturn false;\n\t}\n};", "memory": "32553" ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int size = s.size();\n string r = \"\";\n for(int i = 0; i < size; i++) {\n if(r.size() > 0 && s[i] == r[0] && size % r.size() == 0) {\n int m = size / r.size();\n string...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n vector<int> sol;\n for(int i=1;i<=s.size()/2;i++){\n if(n%i == 0){\n sol.push_back(i);\n }\n }\n for(int i=0;i<sol.size();i++){\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n=s.size();\n for(int i=1;i<=n/2;i++){\n if(n%i==0){\n string x=s.substr(0,i), temp=s;\n while(temp.find(x)!=string::npos){\n temp.erase(temp.find(x), x.size());\...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n if (s.size() <= 1) {\n return false;\n }\n for (int len = 2; len < s.size();) {\n if (FoundForThisLength(s, len)) {\n return true;\n }\n\n len++;\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n vector<int> index;\n for(int i=1; i<=s.size()/2; i++) {\n if(s[i] == s[0]) index.push_back(i);\n }\n\n int k = 0,j=INT_MIN;\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n \n vector<int> factors;\n int n = s.size();\n for (int i = 1; i <= sqrt(n); i++) {\n if (n % i == 0) {\n if (n / i == i)\n factors.push_back(i);\n else {\n facto...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n for(int i = n/2;i>=1;i--){\n if(n%i == 0){\n int t = n/i;\n string a = \"\";\n while(t--){\n a+= (s.substr(0,i));\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n=s.size();\n for(int l=n/2;l>=1;l--){\n if(n%l==0){\n int times=n/l;\n string ans=\"\";\n while(times--){\n ans+=s.substr(0,l);\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string str) {\n if(!(str.size() & 1))\n {\n string first = str.substr(0, str.size() / 2);\n if(first + first == str) return true;\n }\n\n int halfSize = str.size() / 2;\n int size = str.siz...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string str) {\n if(!(str.size() & 1))\n {\n string first = str.substr(0, str.size() / 2);\n if(first + first == str) return true;\n }\n\n int halfSize = str.size() / 2;\n int size = str.siz...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\nbool repeatedSubstringPattern(std::string s) {\n int s_len = s.size();\n for (int len = 1; len < s_len; len++)\n {\n if ((s_len % len) == 0)\n {\n auto s1 = s.substr(0, s.size() - len);\n auto s2 = s.substr(len);\n if (s1 ==...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(const std::string& str)\n\t{\n\t\tconst int length = str.length();\n\t\tconst int halfLength = length / 2;\n\n\t\tchar first = str[0];\n\t\tint patternLength = 1;\n\t\twhile (patternLength <= halfLength)\n\t\t{\n\t\t\twhile (patternLength <= half...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "// Ali Eren Ciftci\nclass Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n if(s.length() < 2)\n return false;\n string temp(s);\n for(int i = 1; i <= s.length() / 2; i++) // i substring size ini tutsun\n {\n if(s.length() % i) \n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "// Ali Eren Ciftci\nclass Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n if(s.length() < 2)\n return false;\n string temp = s;\n for(int i = 1; i <= s.length() / 2; i++) // i substring size ini tutsun\n {\n if(s.length() % i) // i subs...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n\n int n = s.size();\n string temp;\n temp += s[0];\n char comp = s[0];\n\n for(int i = 1; i < n; i++) {\n if(s[i] != comp) temp += s[i];\n else {\n int n1 = tem...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n\n int n = s.size();\n string temp;\n char comp = s[0];\n\n for(int i = 0; i < n; i++) {\n if(temp.size() == 0) temp += s[i];\n else if(s[i] != comp) temp += s[i];\n else {...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n [[nodiscard]]\n auto repeatedSubstringPattern(const std::string_view s) const\n -> bool\n {\n const int sLen = s.length();\n const int halfsLen = sLen / 2;\n std::string sub;\n\n for (int i { 0 }; i < halfsLen; ++i)\n {\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n for (int i = 1; i <= n / 2; ++i) {\n if (n % i == 0) {\n string substring = s.substr(0, i);\n string repeated = \"\";\n for (int j = 0; j < ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
2
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n \n // Check possible lengths for the repeated substring pattern\n for (int len = 1; len <= n / 2; ++len) {\n if (n % len == 0) { // Check if `len` divides `n`\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n string str = \"\";\n for(int i=0; i<n; i++){\n if(n%(i+1)==0) str = s.substr(0,i+1);\n while(str.length()<n){\n str += s.substr(0,i+1);\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n string str = \"\";\n for(int i=0; i<n; i++){\n if(n%(i+1)==0){\n str = s.substr(0,i+1);\n while(str.length()<n){\n str += s.subst...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n string str = \"\";\n for(int i=0; i<n; i++){\n if(n%(i+1)==0) str = s.substr(0,i+1);\n while(str.length()<n){\n str += s.substr(0,i+1);\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int i=1;i<=s.size()/2;i++){\n int len = i;\n if(s.size()%len == 0){\n unordered_map<string,int> mp;\n for(int j=0;j<s.size();j+=len){\n mp[s.substr(j,...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n if(s.length()==1) return false;\n char first=s.front();\n char last=s.back();\n int pos=s.find(last,0);\n if(pos==s.length()-1){// the pos found is the last one\n if(last==first){\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n int i=1;\n while(i<=n/2){\n if(n%i == 0){\n string repeatedString = s.substr(0, i);\n \n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n if (n == 0) {\n return false;\n }\n\n for (int i = 1; i <= n/2; ++i) {\n if (n % i == 0) {\n stringstream pattern;\n for (int j ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n vector<int> index;\n for(int i=1; i<=s.size()/2; i++) {\n if(s[i] == s[0]) index.push_back(i);\n }\n\n int k = 0;\n for(int i=0; i<index.size(); i++) {\n int pattern_length = ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for (int k = 0; k < s.size() / 2; k++) {\n if (s[0] == s[k + 1]) {\n if (check(s, k + 1)) {\n return true;\n }\n }\n }\n return false;\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n \n vector<string> f(string s, int length){\n vector<string>ans;\n for(int i=0; i<s.length()-length+1; i+=length){\n ans.push_back(s.substr(i, length));\n }\n return ans;\n }\n \n bool check(vector<string> s){\n set<str...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n\n bool check(int size , string s){\n string temp = s.substr(0,size);\n for(int i = size ; i<s.size() ; i+=size){\n string t = s.substr(i,i+size);\n if(t.substr(0,size) != temp){\n return false;\n }\n }\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n \n vector<string> f(string s, int length){\n vector<string>ans;\n for(int i=0; i<s.length()-length+1; i+=length){\n ans.push_back(s.substr(i, length));\n }\n return ans;\n }\n \n bool check(vector<string> s){\n set<str...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n if(n == 1) return false;\n vector<char> tmp;\n char start = s[0], end = s[n - 1];\n //tmp = string(1,start);\n tmp.push_back(s[0]);\n if(start == end)\n {\n int flag...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n vector<int> index;\n for(int i=1; i<s.size(); i++) {\n if(s[i] == s[0]) index.push_back(i);\n }\n\n int k = 0;\n for(int i=0; i<index.size(); i++) {\n int pattern_length = ind...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n char c = s[0];\n for(int i = 1; i <= n / 2; ++i){\n if(s[i] == c){\n string str = s.substr(0, i);\n string repeated = \"\";\n for(int j...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n if (n % 2 == 0){\n if (s.substr(0,n/2) == s.substr(n/2,n)){\n return true;\n }\n }\n for (int i = 1; i <= n / 2; i++) {\n string sub = s...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string ans;\n for(int i=(s.size()/2);i>0;i--){\n ans = s.substr(0,i);\n if(s.size()%i==0){\n int times=s.size()/i;\n string temp=\"\";\n while(times--)...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n \n for(int l = n/2; l>=1;l--)\n {\n string newstr = \"\";\n string p = s.substr(0,l);\n if(n%l == 0){\n int times = n/l;\n while(times--)\n {\n n...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n\n int n=s.size();\n for(int l=n/2;l>=1;l--){\n\n string substring=s.substr(0,l);\n if(n%l==0){\n int times=(n/l);\n string newStr=\"\";\n while(times--...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool solve(string &s,string &curr){\n int n=s.size();\n int m=curr.size();\n if(n%m!=0) return false;\n int times=n/m;\n string temp=\"\";\n while(times--){\n temp+=curr;\n }\n return temp==s;\n }\n bool repeatedSubstringPatt...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int max_substr_len = s.length() / 2;\n if (max_substr_len < 1) return false;\n\n for (int len = max_substr_len; len >= 1; len--) {\n string sub_str = s.substr(0, len);\n int copy_count = (s...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(const std::string& s) {\n auto begin = s.begin(), end = s.end();\n auto it = s.begin();\n char final_char = s[s.size() - 1];\n\n while (it != end)\n {\n it = std::find(it, end, final_char);\n\n if (it == end - 1) brea...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(const std::string& s) {\n auto begin = s.begin(), end = s.end();\n auto it = s.begin();\n char final_char = s[s.size() - 1];\n\n while (it != end)\n {\n it = std::find(it, end, final_char);\n\n if (it == end - 1) brea...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int tot = s.length();\n int i = tot/2;\n int j = 2;\n int previous = 0;\n string x(\"\");\n std::ostringstream os;\n os.str(\"\");\n x = s.substr(0, 1);\n std::fill_n(st...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n \n\n int l = s.length();\n\n string ch = \"\";\n\n for(int i = 0; i < l/2; i++)\n {\n ch += s[i];\n string temp = ch;\n\n int ch_len = ch.length();\n\n if(l % ch_len != 0) cont...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n string st = \"\";\n for(int i = 0;i < s.size()/2; i++){\n string str = s.substr(0,i+1);\n int len = n / (i+1);\n if(n % len == 0)\n for(int k =...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string t = s;\n string str = t.substr(0,1);\n t.erase(0, 1);\n // bool f = true;\n int i = 0;\n while (!t.empty() && str.length() <= s.length()/2 ) {\n if (t.find(str)==0) {\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n int n_2 = n >> 1;\n\n for (int i = 1; i <= n_2; i++) {\n string sub_s = s.substr(0, i);\n int k = i;\n while (s.compare(k, i, sub_s) == 0) {\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": " class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n // if(s.size()&1)return 0;\n int n=s.size()/2;\n for(int i=0;i<s.size()/2;i++){\n string h=s.substr(0,i+1);\n int j=0;\n // cout<<h<<\" \";\n // cout<<h<<\" \";\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\n bool pattern(string &s, string &d){\n int n=s.length(); int m=d.length();\n if (n % m != 0) return false;\n for(int i=0; i<n; i=i+m){\n for(int j=0; j<m; j++){\n if(s[i+j]!=d[j]) return false;\n }\n }\n return tru...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": " class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n // if(s.size()&1)return 0;\n int n=s.size()/2;\n for(int i=0;i<s.size()/2;i++){\n string h=s.substr(0,i+1);\n int j=0;\n // cout<<h<<\" \";\n // cout<<h<<\" \";\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int s_len = s.size();\n \n for ( int t_len = 1; t_len <= s_len/2; t_len++ ) { \n string substr = s.substr(0, t_len);\n if ( s_len % t_len == 0 ) {\n for ( int i = ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string pattern = \"\";\n for (int n = 1; n <= s.size() / 2; n++) {\n pattern = s.substr(0, n);\n if (s.size() % n != 0) {\n continue;\n }\n bool sucses = true;...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n=s.length(); string a; bool var;\n for (int i=1; i<=n/2;++i){\n if (n%i==0){\n a =s.substr(0,i);\n var = true;\n }\n for (int j=i; j<n;j+=i){\n if (j+i<=n&&s.subst...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int lenght = s.size();\n\tint subSize;\n\tstring res;\n\tfor (int i = 1; i <= lenght/2; i++){\n\t\tstring subString = s.substr(0,i);\n\t\tsubSize = subString.size();\n\t\tint repeat = lenght/subSize;\n\t\tres.clear();\n\t\tre...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\nstring a[10001];\n bool repeatedSubstringPattern(string s) {\n int n=s.length(); string a; bool var;\n for (int i=1; i<=n/2;++i){\n if (n%i==0){\n a =s.substr(0,i);\n var = true;\n }\n for (int j=i; j<n;j+=i){\n i...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size();\n for(int l=n/2; l>=1; l--){\n string newString =\"\";\n string pattern = s.substr(0,l);\n int times = n/l;\n while(times--){\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n\n for(int l=n/2;l>=1;l--)\n {\n int times = n/l;\n string pattern = s.substr(0,l);\n string newStr = \"\";\n\n while(times--)\n {\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n\n for(int l=n/2;l>=1;l--)\n {\n int times = n/l;\n string pattern = s.substr(0,l);\n string newStr = \"\";\n\n while(times--)\n {\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int i = 0; i < s.size()/2; i++) {\n string sub = s.substr(0,i+1);\n int subSize = sub.size();\n if(s.size()%subSize > 0) continue;\n int num = s.size()/subSize;\n int...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int i = 0; i < s.size()/2; i++) {\n string sub = s.substr(0,i+1);\n int subSize = sub.size();\n if(s.size()%subSize > 0) continue;\n int num = s.size()/subSize;\n int...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int i = 0; i < s.size()/2; i++) {\n string sub = s.substr(0,i+1);\n int subSize = sub.size();\n if(s.size()%subSize > 0) continue;\n int num = s.size()/subSize;\n int...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.size()/2;\n string subString;\n for(int i = 0; i<n; i++){\n subString = s.substr(0, i+1);\n \n if(s.size() % subString.size() == 0){\n string temp = subS...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n string repeat(string str, int count){\n string result = \"\";\n for (int i = 0; i<count; i++){\n result += str;\n }\n return result;\n }\n bool repeatedSubstringPattern(string s) {\n unordered_map<string, int> store = {};\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n if (s.length() <= 1) return false; \n int n = s.length();\n for (int i = 1; i <= (n+1)/2; i++) {\n string tmp = s.substr(0, i);\n if (n % i != 0) continue;\n string tmp2 = tmp;\n...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string front = \"\",\n back = \"\",\n pattern = \"\";\n int total = 0,\n n = s.size(),\n curr = 0;\n unordered_map<string,int> mp;\n for(int i=0; i<n; i++...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\nint n;\n string makestring(string str,int times){\n string ans=\"\";\n for (int i = 0; i < times; ++i) {\n ans += str;\n }\n return ans;\n }\n bool repeatedSubstringPattern(string s) {\n n=s.size();\n for(int i=0;i<n/2...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string sub = \"\";\n sub += s[0];\n // 0 1 2 3\n // 4 - 1 = 3\n // 4 -2 = 2\n for (int i = 1; i <= s.size() - sub.size(); i++) {\n // cout << \"i: \" << i << endl;\n //...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(int size=1;size<=s.size()/2;size++){\n string temp=s.substr(0, size);\n bool f=true;\n for(int i=size;i<=s.size()-size;i+=size){\n if(temp!=s.substr(i, size)){\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n \tint size = s.length();\n\tif (size == 1)\n\t\treturn false;\n\tif (size == 2)\n\t\treturn(s[0] == s[1]);\n\tif (size == 3)\n\t\treturn(s[0] == s[1] && s[1] == s[2]);\n\tvector<string>container;\n\tfor (int i = 0, j = size - 1; i <...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n bool f=false;\n int len=s.size(),siz;\n unordered_map<string,int> mp;\n string n=\"\";\n for(int i=0;i<s.size()-1;i++){\n n+=s[i];\n //cout<<n<<endl;\n siz=n.size()...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool isDiv(string s, string div){\n int n = s.length(), m = div.length();\n while(s.size()){\n string part = s.substr(0,m);\n if(part != div)\n return false;\n s = s.substr(m);\n }\n return true;\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n std::list<std::string> substrings;\n std::string substring = \"\";\n for (char c : s) {\n substring.push_back(c);\n substrings.push_back(substring);\n if (substring.size() * 2 > ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n string str;\n string str2;\n string dup=s;\n int count=0;\n\n for(int i=0;i<(s.length()/2);i++){\n str+=s[i];\n dup=s;\n count=0;\n int prev=-1;\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n for(auto i = 0; i < s.size()-1; i++){\n if(s.size() % (i+1) == 0){\n string sub = s.substr(0, i+1); \n string compare = sub;\n while(compare.size() < s.size()) compare =...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int n = s.length();\n for(int i=0;i<n/2;i++){\n string str = s.substr(0,i+1);\n int x = n/(i+1);\n string s1 = \"\";\n while(x--){\n s1+=str;\n }\n ...
459
<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> s = &quot;abab&quot; <strong>Output:</strong> true <strong>Explanatio...
3
{ "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n int len=s.size();\n for(int i=0;i<len/2;i++)\n {\n string str=s.substr(0,i+1);\n int kitne_bar_append_karu=len/(i+1);\n string result;\n while(kitne_bar_append_karu--)...