My solution which is very easy to understand


  • 0
    D
    bool repeatedSubstringPattern(string s) {
        string subs;
        for (int i=1;i<=s.size()/2;i++){
            if (s.size()%i==0){
                subs=s.substr(0,i);
                string news="";
                for (int j=0;j<s.size()/i;j++) news+=subs;
                if (news==s) return true;
            }
        }
        return false;
    }

Log in to reply
 

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