We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44f3eb1 commit 6c43775Copy full SHA for 6c43775
array-string/1071_greatest_common_divisor_of_strings/solution.py
@@ -0,0 +1,15 @@
1
+class Solution:
2
+ def gcdOfStrings(self, str1: str, str2: str) -> str:
3
+ length1, length2 = len(str1), len(str2)
4
+
5
+ def is_valid_gcd(index):
6
+ if length1 % index or length2 % index:
7
+ return False
8
+ n1, n2 = length1 // index, length2 // index
9
+ base = str1[:index]
10
+ return str1 == n1 * base and str2 == n2 * base
11
12
+ for i in range(min(length1, length2), 0, -1):
13
+ if is_valid_gcd(i):
14
+ return str1[:i]
15
+ return ""
0 commit comments