美文网首页
2019-02-03第九天

2019-02-03第九天

作者: 织雾呀 | 来源:发表于2019-02-03 20:41 被阅读0次

    leetcode:

    重复的子字符串

    暴力算法:

        public boolean repeatedSubstringPattern(String s) {
            if(s.length() < 1)
            return false;
            int len = 1;
            int strLen = s.length();
            int i = 0;
            while(len <= strLen/2){
                if(strLen%len != 0){
                    len++;
                    continue;
                }
                String subStr = s.substring(0,len);
                i = 0;
                for(i = len;i < strLen;i += len){
                    if(!subStr.equals(s.substring(i, i+len))){
                        break;
                    }
                }
                if(i >= strLen)
                    return true;
                len++;
            }           
            return false;
        }
    
    

    看了之后知道是怎么写,但是自己写的时候却又写不出,哎,尴尬

    相关文章

      网友评论

          本文标题:2019-02-03第九天

          本文链接:https://www.haomeiwen.com/subject/cwgysqtx.html