Easy and straightforward Java solution


  • 0
    B
    class Solution {
        public boolean repeatedSubstringPattern(String s) {
            for (int i=1 ; i< s.length()/2 +1 ; i++){ 
                if (s.length()%i != 0)
                    continue;
                int start = i;
                while (start < s.length() && s.substring(0, i).equals(s.substring(start, start+i)))
                    start += i;
                if (start == s.length())
                    return true;
            }
            
            return false;
        }
    }
    

Log in to reply
 

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