-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_03.cpp
More file actions
37 lines (32 loc) · 1.01 KB
/
day_03.cpp
File metadata and controls
37 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*PROBLEM STATEMENT:
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
Example 1:
Input: "abab"
Output: True
Explanation: It's the substring "ab" twice.
Example 2:
Input: "aba"
Output: False
*/
//CODE
class Solution {
public:
bool issafe(string s,string str){
for(int i=0;i<s.length();i+=str.length()){
string cs = s.substr(i,str.length()); //all the substring be of the length of current substring
if(cs!=str) return false;
}
return true;
}
bool repeatedSubstringPattern(string s) {
string str=""; //substring
for(int i=0;i<s.length()/2;i++){
str+=s[i];
if(s.length()%str.length()==0){
bool x=issafe(s.substr(i+1),str);
if(x) return true;
}
}
return false;
}
};