1156. Swap For Longest Repeated Character Substring Medium
1/**
2 * [1156] Swap For Longest Repeated Character Substring
3 *
4 * You are given a string text. You can swap two of the characters in the text.
5 * Return the length of the longest substring with repeated characters.
6 *
7 * Example 1:
8 *
9 * Input: text = "ababa"
10 * Output: 3
11 * Explanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is "aaa" with length 3.
12 *
13 * Example 2:
14 *
15 * Input: text = "aaabaaa"
16 * Output: 6
17 * Explanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring "aaaaaa" with length 6.
18 *
19 * Example 3:
20 *
21 * Input: text = "aaaaa"
22 * Output: 5
23 * Explanation: No need to swap, longest repeated character substring is "aaaaa" with length is 5.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= text.length <= 2 * 10^4
29 * text consist of lowercase English characters only.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/swap-for-longest-repeated-character-substring/
35// discuss: https://leetcode.com/problems/swap-for-longest-repeated-character-substring/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn max_rep_opt1(text: String) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1156() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.