Skip to content

Commit 369a0b8

Browse files
committed
Runtime: 1 ms (Top 86.0%) | Memory: 2.00 MB (Top 89.5%)
1 parent 61b08dd commit 369a0b8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Runtime: 1 ms (Top 86.0%) | Memory: 2.00 MB (Top 89.5%)
2+
3+
impl Solution {
4+
pub fn gcd_of_strings(str1: String, str2: String) -> String {
5+
if &(str1.clone() + &str2) != &(str2.clone() + &str1) {
6+
return "".to_string();
7+
}
8+
let length = gcd(str1.len(), str2.len());
9+
str1[0..length].to_owned()
10+
}
11+
}
12+
pub fn gcd(n1: usize, n2: usize) -> usize{
13+
if n2 == 0 {
14+
return n1;
15+
}
16+
gcd(n2, n1 % n2)
17+
}

0 commit comments

Comments
 (0)