We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f079e01 commit 77314abCopy full SHA for 77314ab
solution/1071.Greatest Common Divisor of Strings/Solution.java
@@ -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