LeetCode高频面试60天打卡日记Day12
程序员文章站
2024-03-22 12:42:40
...
Day12: 字符串的最大公因子
class Solution {
public int gcd(int len1,int len2){
int big = len1>len2 ? len1:len2;
int small = len1<len2 ? len1:len2;
if(big%small==0){
return small;
}
return gcd(big%small,small);
}
public String gcdOfStrings(String str1, String str2) {
if(!(str1+str2).equals(str2+str1)){
return "";
}
int gcdStr = gcd(str1.length(),str2.length());
return str1.substring(0,gcdStr);
}
}
上一篇: kettle-mysql的使用