simple C solution,6 ms


  • 0
    W
    bool repeatedSubstringPattern(char* s) {
        int slen=strlen(s);
        for(int i=1;i<=slen/2;i++){
        	int flag=0;
        	if(slen%i) continue;
        	else{
        		for(int j=0;j<slen/i-1;j++){
        			if(strncmp(s+j*i,s+(j+1)*i,i*sizeof(char))){
        				flag=1;
        				break;
        			}
        		}
        		if(flag==0) return true;
        	}
        }
        return false;
    }
    

Log in to reply
 

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