Skip to content

#1071 - Greatest Common Divisor of Strings

EasyArray / String
Open on LeetCode

Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. A string t divides s if s can be formed by concatenating one or more copies of t.

InputOutput
str1 = "ABCABC", str2 = "ABC""ABC"
str1 = "ABABAB", str2 = "ABAB""AB"
str1 = "LEET", str2 = "CODE"""

Released under the MIT License.