Problem statement

https://binarysearch.com/problems/Repeating-String/

Solution

Equal to Leetcode 0459. Repeated Substring Pattern.

Complexity

Complexity of this solution is O(n * sqrt(n)) for time and O(n) for space.

Code

class Solution:
    def solve(self, s):
        N = len(s)
        for i in range(1, N//2+1):
            if N % i == 0 and s[:i]* (N//i) == s:
                return True
        return False

Remark

There is also linear time solution, but it gives TLE, because it is linear in average and for special cases it can broke complexity. If we want to have true linear, use KMP.