686. Repeated String Match Medium
1/**
2 * [686] Repeated String Match
3 *
4 * Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b to be a substring of a after repeating it, return -1.
5 * Notice: string "abc" repeated 0 times is "", repeated 1 time is "abc" and repeated 2 times is "abcabc".
6 *
7 * Example 1:
8 *
9 * Input: a = "abcd", b = "cdabcdab"
10 * Output: 3
11 * Explanation: We return 3 because by repeating a three times "abcdabcdabcd", b is a substring of it.
12 *
13 * Example 2:
14 *
15 * Input: a = "a", b = "aa"
16 * Output: 2
17 *
18 *
19 * Constraints:
20 *
21 * 1 <= a.length, b.length <= 10^4
22 * a and b consist of lowercase English letters.
23 *
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/repeated-string-match/
28// discuss: https://leetcode.com/problems/repeated-string-match/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33 pub fn repeated_string_match(a: String, b: String) -> i32 {
34 0
35 }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_686() {
46 }
47}
48
Back
© 2025 bowen.ge All Rights Reserved.