package leetcode;

/**
 * https://leetcode.com/problems/greatest-common-divisor-of-strings/
 */
public class Problem1071 {
    public String gcdOfStrings(String str1, String str2) {
        // TODO
        return "";
    }

    public static void main(String[] args) {
        Problem1071 prob = new Problem1071();
        System.out.println(prob.gcdOfStrings("ABCABC", "ABC")); // ABC
        System.out.println(prob.gcdOfStrings("ABABAB", "ABAB")); // AB
        System.out.println(prob.gcdOfStrings("LEET", "CODE")); // 
    }
}

@@ -187,341 +187,379 @@
     
-// TODO%0A        return %22%22
+String s1 = str1.length() %3E= str2.length() ? str1 : str2
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1071 prob = new Problem1071();%0A        System.out.println(prob.gcdOfStrings(%22ABCABC%22, %22ABC%22)); // ABC%0A        System.out.println(prob.gcdOfStrings(%22ABABAB%22, %22ABAB%22)); // AB%0A        System.out.println(prob.gcdOfStrings(%22LEET%22, %22CODE%22)); // 
+String s2 = str1.length() %3C str2.length() ? str1 : str2;%0A        if (s2.isEmpty()) %7B%0A            return str1;%0A        %7D%0A        int index = s1.indexOf(s2);%0A        if (index %3C 0) %7B%0A            return %22%22;%0A        %7D%0A        String s3 = s1.substring(index + s2.length());%0A        return gcdOfStrings(s2, s3);
 %0A   

Solve problem 1071