459:重复的子字符串

This commit is contained in:
轩辕龙儿 2022-04-18 16:09:17 +08:00
parent fb4a821719
commit bf4a1d280f

View File

@ -49,13 +49,11 @@ public class RepeatedSubstringPattern {
//leetcode submit region begin(Prohibit modification and deletion) //leetcode submit region begin(Prohibit modification and deletion)
class Solution { class Solution {
public boolean repeatedSubstringPattern(String s) { public boolean repeatedSubstringPattern(String s) {
int lens = s.length(), i = 0; int lens = s.length();
while (++i < lens) { for (int i = 1; i < lens; i++) {
if (lens % i != 0) { if (lens % i == 0) {
continue; if (s.substring(0, i).equals(s.substring(lens - i))
} && s.substring(i).equals(s.substring(0, lens - i))) {
if (s.substring(lens - i, lens).equals(s.substring(0, i))) {
if (s.substring(i, lens).equals(s.substring(0, lens - i))) {
return true; return true;
} }
} }