Need extra test case


  • 0
    T

    The following code was listed in the 9ms accepted Java sample codes and didn't past

    "abcabcabcabcabcabcabc"
    
    class Solution {
        public boolean repeatedSubstringPattern(String s) {
            if (s == null || s.length() <= 1) return false;
            int len = s.length(), mid = len >>> 1;//一半
            if (s.substring(0, mid).equals(s.substring(mid))) return true;
            int one_third = len/3;//三分之一
            String sub = s.substring(0, one_third);
            if (sub.equals(s.substring(one_third, one_third * 2))
                    && sub.equals(s.substring(one_third * 2))) return true;
            if (len % 2 == 1) {//奇数个字符
                char c = s.charAt(0);
                for (int i = 1; i < len; i++) {
                    if (s.charAt(i) != c) return false;
                }
                return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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