congr / world

2 stars 1 forks source link

LeetCode : 459. Repeated Substring Pattern #522

Closed congr closed 5 years ago

congr commented 5 years ago

https://leetcode.com/problems/repeated-substring-pattern/ image

congr commented 5 years ago
class Solution {
    public boolean repeatedSubstringPattern(String s) {
        // if (s.length() % 2 == 1) return false; // abaabaaba len :9

        String t = s + s;
        return t.substring(1, t.length()-1).contains(s);
    }
}