Solution for 459 Repeated Substring Pattern in javascript

  • 0
    var repeatedSubstringPattern = function(s) {
        if(s == null || s.length <2)return false;
        return helper(s,2);
    var helper = function(s, t){
         while(t<=s.length && s.length%t!=0){
        if(t>s.length)return false;
        var size=s.length;
          var pa=s.substring(0, size/t);
        var pattern= new RegExp(pa, 'g');
         if(!s.replace(pattern,'').trim())return true;
        return helper(s,t+1);

Log in to reply

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