Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e3e33c

Browse files
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
Lines changed: 16 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /