Skip to content

Commit 4e3e33c

Browse files
authored
Create 1071. Greatest Common Divisor of Strings
1 parent ae8b75d commit 4e3e33c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public String gcdOfStrings(String str1, String str2) {
3+
if(str2.length()>str1.length()){
4+
return gcdOfStrings(str2,str1);
5+
}
6+
if(str2.equals(str1)){
7+
return str1;
8+
}
9+
10+
if(str1.startsWith(str2)){
11+
return gcdOfStrings(str1.substring(str2.length()),str2);
12+
}
13+
14+
return "";
15+
}
16+
}

0 commit comments

Comments
 (0)