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 9d52c93 commit 4c5a12eCopy full SHA for 4c5a12e
my-submissions/e1071.py
@@ -0,0 +1,29 @@
1
+class Solution:
2
+ def gcdOfStrings(self, str1: str, str2: str) -> str:
3
+ tryLen = 0
4
+
5
+ # set str1 as shorter
6
+ if len(str1) > len(str2) :
7
+ str1, str2 = str2, str1
8
9
+ while tryLen < len(str1) and str1[tryLen] == str2[tryLen] :
10
+ tryLen += 1
11
12
+ # len of x
13
+ for i in range(tryLen, -1, -1) :
14
+ if not i :
15
+ break
16
17
+ if len(str1) % i or len(str2) % i :
18
+ continue
19
20
+ if any(str1[j] != str1[j % i] or
21
+ str2[j] != str1[j % i] for j in range(i, len(str1))) :
22
23
24
+ if any(str2[j] != str2[j % i] for j in range(len(str1), len(str2))) :
25
26
27
+ return str1[:i]
28
29
+ return ''
0 commit comments