Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created September 19, 2017 00:14
Show Gist options
  • Save cixuuz/602cd9514fcb2acbe9f0d73619908a40 to your computer and use it in GitHub Desktop.
Save cixuuz/602cd9514fcb2acbe9f0d73619908a40 to your computer and use it in GitHub Desktop.
[459. Repeated Substring Pattern] #leetcode
class Solution {
// O(n^3) O(n)
public boolean repeatedSubstringPattern(String s) {
int n = s.length();
for (int i=1; i<=n/2; i++) {
if (n%i == 0) {
StringBuilder sb = new StringBuilder();
for (int j=0; j<n/i; j++) {
sb.append(s.substring(0, i));
}
if (s.equals(sb.toString())) return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment