-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeatedSubstrPattern.py
More file actions
28 lines (25 loc) · 937 Bytes
/
Copy pathrepeatedSubstrPattern.py
File metadata and controls
28 lines (25 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution:
def divideString(self, s: str, num: int, size: int) -> bool:
first_pivot = int(size / num)
substring = s[0 : first_pivot]
# print(substring)
new_pivot = first_pivot
while new_pivot + first_pivot <= size:
new_substring = s[new_pivot : new_pivot + first_pivot]
# print(new_substring)
if new_substring != substring:
return False
new_pivot += first_pivot
return True
def repeatedSubstringPattern(self, s: str) -> bool:
size = len(s)
for i in range(2, size + 1):
if size % i == 0 and self.divideString(s, i, size):
return True
return False
s = input("Input string: ")
solution = Solution()
if (solution.repeatedSubstringPattern(s)):
print(f'{s} has a repeated substring pattern')
else:
print(f'{s} does not have a repeated substring pattern')