leetcode1071

 1 class Solution:
 2     def gcdOfStrings(self, str1: str, str2: str) -> str:
 3         len1 = len(str1)
 4         len2 = len(str2)
 5         s = ''
 6         l = ''
 7         if len1 <= len2:
 8             s = str1
 9             l = str2
10         else:
11             s = str2
12             l = str1
13         if l.find(s) == -1:
14             return ''
15         else:
16             temp = s
17             while len(temp) < len(l):
18                 temp += temp
19             if temp == l:
20                 return s
21             if temp.find(l) == -1:
22                 return ''
23             else:
24                 return self.gcdOfStrings(s,temp[len(l):])

猜你喜欢

转载自www.cnblogs.com/asenyang/p/10962242.html
今日推荐