Beats 97.99 % of java submissions (12/28/2017)


  • 0
    L
    public class Solution {
        public boolean repeatedSubstringPattern(String s) {
            if (s == null || s.length() <= 1) {
                return false;
            }
            int n = s.length();
    
            String repeat;
            for (int len = n / 2; len >= 1; len--) {
                if (n % len == 0) {
                    int i = 0;
                    repeat = s.substring(0, len);
                    while (i <= n - len && s.startsWith(repeat, i)) {
                        i += len;
                    }
                    if (i == n) {
                        return true;
                    }
                }
            }
            return false;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.