1071. Greatest Common Divisor of Strings Easy

@problem@discussion
#Math#String



1/**
2 * [1071] Greatest Common Divisor of Strings
3 *
4 * For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times).
5 * Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.
6 *  
7 * Example 1:
8 * 
9 * Input: str1 = "ABCABC", str2 = "ABC"
10 * Output: "ABC"
11 * 
12 * Example 2:
13 * 
14 * Input: str1 = "ABABAB", str2 = "ABAB"
15 * Output: "AB"
16 * 
17 * Example 3:
18 * 
19 * Input: str1 = "LEET", str2 = "CODE"
20 * Output: ""
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= str1.length, str2.length <= 1000
26 * 	str1 and str2 consist of English uppercase letters.
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/greatest-common-divisor-of-strings/
32// discuss: https://leetcode.com/problems/greatest-common-divisor-of-strings/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn gcd_of_strings(str1: String, str2: String) -> String {
38        String::new()
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_1071() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.