For two strings s and t, we say that t divides s if and only if s can be formed by concatenating one or more copies of t together (i.e., s = t + t + ... + t).
Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. If no such string exists, return an empty string.
Constraints:
str1.length, str2.length
str1 and str2 consist of English uppercase letters.
The key idea behind this solution comes from a mathematical property of repeating strings. If a string x divides both str1 and str2, it means both strings are formed by repeating the same base pattern x.
Because both strings share the same repeating pattern, concatenating them in different orders should produce the same result. In other ...
For two strings s and t, we say that t divides s if and only if s can be formed by concatenating one or more copies of t together (i.e., s = t + t + ... + t).
Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. If no such string exists, return an empty string.
Constraints:
str1.length, str2.length
str1 and str2 consist of English uppercase letters.
The key idea behind this solution comes from a mathematical property of repeating strings. If a string x divides both str1 and str2, it means both strings are formed by repeating the same base pattern x.
Because both strings share the same repeating pattern, concatenating them in different orders should produce the same result. In other ...