Skip to content

Commit d419991

Browse files
committed
Time: 31 ms (5.02%), Space: 46.9 MB (5.99%) - LeetHub
1 parent 77eb005 commit d419991

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ class Solution {
44
public String gcdOfStrings(String str1, String str2) {
55
String answer = "";
66

7-
for (int i = 0; i < str1.length(); i++) {
7+
for (int i = str1.length()-1; i >= 0; i--) {
88
String cur = str1.substring(0, i + 1);
99

1010
String check1 = str1.replace(cur, "");
1111
String check2 = str2.replace(cur, "");
1212

1313
if(check1.equals("") && check2.equals("")) {
1414
answer = cur;
15+
break;
1516
}
1617

1718
}

0 commit comments

Comments
 (0)