424. Longest Repeating Character Replacement Medium
1/**
2 * [424] Longest Repeating Character Replacement
3 *
4 * You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.
5 * Return the length of the longest substring containing the same letter you can get after performing the above operations.
6 *
7 * Example 1:
8 *
9 * Input: s = "ABAB", k = 2
10 * Output: 4
11 * Explanation: Replace the two 'A's with two 'B's or vice versa.
12 *
13 * Example 2:
14 *
15 * Input: s = "AABABBA", k = 1
16 * Output: 4
17 * Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".
18 * The substring "BBBB" has the longest repeating letters, which is 4.
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= s.length <= 10^5
24 * s consists of only uppercase English letters.
25 * 0 <= k <= s.length
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/longest-repeating-character-replacement/
31// discuss: https://leetcode.com/problems/longest-repeating-character-replacement/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn character_replacement(s: String, k: i32) -> i32 {
37 0
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_424() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.