Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-04-26_16-45-13.png
47.9 KB
#N459. Repeated Substring Pattern
problem link
#solution
class Solution {
public boolean repeatedSubstringPattern(String s) {
for(int i=0; i<s.length()/2; i++){
if(s.length()%(i+1)==0 && check(i, s))
return true;
}
return false;
}
public boolean check(int i, String s){
StringBuilder temp = new StringBuilder(s.substring(0, i+1));
int count=s.length()/(i+1);
while(--count >0){
temp.append(s.substring(0, i+1));
}
if(temp.toString().equals(s)) return true;
return false;
}
}