문제
https://leetcode.com/problems/greatest-common-divisor-of-strings/?envType=study-plan-v2&envId=leetcode-75

python3
import math
def solution(str1, str2):
if str1 + str2 != str2 + str1:
return ""
gcdlen = math.gcd(len(str1), len(str2))
return str1[:gcdlen]
java
public class no_1071 {
public int GCD(int n1, int n2){
while (n1 != 0 && n2 != 0)
{
if(n1 > n2) {
n1 %= n2;
}
else {
n2 %= n1;
}
}
return n1 | n2;
}
public String gcdOfStrings(String str1, String str2){
if (!(str1 + str2).equals(str2 + str1)){
return "";
}
int gcdlen = GCD(str1.length(), str2.length());
return str1.substring(0, gcdlen);
}
}