Class Solution
-
- All Implemented Interfaces:
public final class Solution3398 - Smallest Substring With Identical Characters I.
Hard
You are given a binary string
sof lengthnand an integernumOps.You are allowed to perform the following operation on
sat mostnumOpstimes:Select any index
i(where0 <= i < n) and flips[i]. Ifs[i] == '1', changes[i]to'0'and vice versa.
You need to minimize the length of the longest substring of
ssuch that all the characters in the substring are identical.Return the minimum length after the operations.
Example 1:
Input: s = "000001", numOps = 1
Output: 2
Explanation:
By changing
s[2]to'1',sbecomes"001001". The longest substrings with identical characters ares[0..1]ands[3..4].Example 2:
Input: s = "0000", numOps = 2
Output: 1
Explanation:
By changing
s[0]ands[2]to'1',sbecomes"1010".Example 3:
Input: s = "0101", numOps = 0
Output: 1
Constraints:
1 <= n == s.length <= 1000sconsists only of'0'and'1'.0 <= numOps <= n
-
-
Constructor Summary
Constructors Constructor Description Solution()
-