Given a string s
, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.
class Solution {
public boolean repeatedSubstringPattern(String s) {
String substring = "";
for (int i = 1; i < s.length(); i++) {
substring = s.substring(0, i);
int repeated = s.length() / substring.length();
String altogether = "";
for (int r = 0; r < repeated; r++) {
altogether += substring;
}
if (altogether.equals(s)) {
return true;
}
}
return false;
}
}