Leetcode Problem 1071. Greatest Common Divisor of Strings

1071. Greatest Common Divisor of Strings

Leetcode Solutions

Greatest Common Divisor of Strings

  1. Check if str1 + str2 equals str2 + str1. If not, return an empty string.
  2. Calculate the GCD of the lengths of str1 and str2 using the Euclidean algorithm.
  3. Return the substring of str1 (or str2) from index 0 to gcdLength (inclusive), where gcdLength is the GCD of the lengths of str1 and str2.
UML Thumbnail

Brute Force Search for Common Divisor String

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...