Skip to content

Commit 77314ab

Browse files
authored
Create Solution.java
1 parent f079e01 commit 77314ab

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public String gcdOfStrings(String str1, String str2) {
3+
if (!(str1 + str2).equals(str2 + str1)) {
4+
return "";
5+
}
6+
int len = gcd(str1.length(), str2.length());
7+
return str1.substring(0, len);
8+
}
9+
10+
private int gcd(int a, int b) {
11+
return b == 0 ? a : gcd(b, a % b);
12+
}
13+
}

0 commit comments

Comments
 (0)