在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ You are given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'. A string is said to be balanced if each of its characters appears n/4 times where n is the length of the string. Return the minimum length of the substring that can be replaced with any other string of the same length to make the original string s balanced. Return 0 if the string is already balanced. Example 1: Input: s = "QWER" Input: s = "QQWE" Input: s = "QQQW" Input: s = "QQQQ" Constraints: 1 <= s.length <= 10^5 有一个只含有 'Q', 'W', 'E', 'R' 四种字符,且长度为 n 的字符串。 假如在该字符串中,这四个字符都恰好出现 n/4 次,那么它就是一个「平衡字符串」。 给你一个这样的字符串 s,请通过「替换子串」的方式,使原字符串 s 变成一个「平衡字符串」。 你可以用和「待替换子串」长度相同的 任何 其他字符串来完成替换。 请返回待替换子串的最小可能长度。 如果原字符串自身就是一个平衡字符串,则返回 0。 示例 1: 输入:s = "QWER" 输入:s = "QQWE" 输入:s = "QQQW" 输入:s = "QQQQ" 提示: 1 <= s.length <= 10^5 |
请发表评论