Java time 28ms beats 76%


  • 0

    Sorry, I'm new here, I don't know how to format the code.

    public boolean repeatedSubstringPattern(String s) {
    if (s.length() < 2) return false;
    StringBuffer buffer = new StringBuffer(s.substring(0, (s.length() - 1) / 2 + 1));
    for (int i = (s.length() - 1) / 2; i > -1; i--) {
    if (s.length() % (i + 1) == 0) {
    boolean isTrue = true;
    for (int j = (i + 1); j < s.length(); j += (i + 1)) {
    if (!buffer.toString().equals(s.substring(j, j + (i + 1)))) {
    isTrue = false;
    break;
    }
    }
    if (isTrue) return true;
    }
    buffer.deleteCharAt(i);
    }
    return false;
    }


Log in to reply
 

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