Greatest Common Divisor of Strings

Given two strings str1 and str2, find the largest string x such that x divides both str1 and str2. A string t divides s if and only if s is t concatenated with itself one or more times.

Constraints

  • 1 <= str1.length, str2.length <= 1000
  • str1 and str2 consist of English uppercase letters.
Saving… · 3 lines
class Solution:
def greatestCommonDivisorOfStrings(self, str1: str, str2: str) -> str:
pass
Console

Click Run to execute sample tests.