type
status
date
slug
summary
tags
category
icon
password
题目:统计美丽子字符串 II
给你一个字符串
s 和一个正整数 k 。用
vowels 和 consonants 分别表示字符串中元音字母和辅音字母的数量。如果某个字符串满足以下条件,则称其为 美丽字符串 :
vowels == consonants,即元音字母和辅音字母的数量相等。
(vowels * consonants) % k == 0,即元音字母和辅音字母的数量的乘积能被k整除。
返回字符串
s 中 非空美丽子字符串 的数量。子字符串是字符串中的一个连续字符序列。
英语中的 元音字母 为
'a'、'e'、'i'、'o' 和 'u' 。英语中的 辅音字母 为除了元音字母之外的所有字母。
示例 1:
示例 2:
示例 3:
提示:
1 <= s.length <= 5 * 104
1 <= k <= 1000
s仅由小写英文字母组成。
题解
思路
前缀和 + 哈希表代码实现
纯暴力遍历:跑 LeetCode 会超时
前缀和 + 哈希表
附录
- Author:Zinphy
- URL:https://zouysay.cn/article/10aac39e-36af-4f85-89d1-ffd1b93531e3
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!