Skip to content

Commit 4eeb84a

Browse files
authored
update: 添加问题“3306.元音辅音字符串计数II”的代码和题解(#806)
* feat: #804 脚本自动发起的issue/pr带上 ewSolution.py版本 Signed-off-by: LetMeFly666 <[email protected]> * clean: remove temp files Signed-off-by: LetMeFly666 <[email protected]> * update: leetcode.3306(C++.AC + Py.WA) 有和我一样第一时间想起mysql的吗 Signed-off-by: LetMeFly666 <[email protected]> * fix: py.AC 滑出窗口的应该是cnt11[word[left1]]而不是cht11[c] Signed-off-by: LetMeFly666 <[email protected]> * update: leetcode.3306(Java.AC + Go.AC) Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“3306.元音辅音字符串计数II”的代码和题解(#806) feat #804 脚本自动发起的issue/pr带上`newSolution.py`版本 clean: remove temp files update: leetcode.3306(C++.AC + Py.WA) 有和我一样第一时间想起mysql的吗 fix: py.AC 滑出窗口的应该是cnt11[word[left1]]而不是cht11[c] update: leetcode.3306(Java.AC + Go.AC) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent f58f423 commit 4eeb84a

12 files changed

+661
-48
lines changed

.commitmsg

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
feat: (#797)
1+
feat #804
2+
脚本自动发起的issue/pr带上`newSolution.py`版本
23

3-
close #795
4-
如果这个commit成功close掉(#795)了,就说明(#795)完成了。
5-
因为close(#795)的信息是来自.commitmsg文件的。
4+
clean: remove temp files
65

7-
fix: python`os.system(f'git commit -s -m "{commitMsg}"')`无法处理多行
6+
update: leetcode.3306(C++.AC + Py.WA)
7+
有和我一样第一时间想起mysql的吗
8+
9+
fix: py.AC
10+
滑出窗口的应该是cnt11[word[left1]]而不是cht11[c]
11+
12+
update: leetcode.3306(Java.AC + Go.AC)

COMMITmultiline.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-13 10:24:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-13 10:34:46
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
typedef long long ll;
12+
13+
class Solution {
14+
private:
15+
static constexpr char aeiou[] = "aeiou";
16+
17+
inline int aeiouIndex(char c) {
18+
for (int i = 0; i < 5; i++) {
19+
if (aeiou[i] == c) {
20+
return i;
21+
}
22+
}
23+
return -1;
24+
}
25+
public:
26+
ll countOfSubstrings(string word, int k) {
27+
int cnt1_k = 0, cnt2_k = 0, left_k = 0;
28+
int bin_k[5] = {0};
29+
int cnt1_k1 = 0, cnt2_k1 = 0, left_k1 = 0;
30+
int bin_k1[5] = {0};
31+
ll ans = 0;
32+
for (char c : word) {
33+
int index = aeiouIndex(c);
34+
if (index == -1) {
35+
cnt2_k++;
36+
cnt2_k1++;
37+
} else {
38+
bin_k[index]++;
39+
if (bin_k[index] == 1) {
40+
cnt1_k++;
41+
}
42+
bin_k1[index]++;
43+
if (bin_k1[index] == 1) {
44+
cnt1_k1++;
45+
}
46+
}
47+
48+
while (cnt1_k == 5 && cnt2_k >= k) {
49+
index = aeiouIndex(word[left_k++]);
50+
if (index == -1) {
51+
cnt2_k--;
52+
} else {
53+
bin_k[index]--;
54+
if (!bin_k[index]) {
55+
cnt1_k--;
56+
}
57+
}
58+
}
59+
while (cnt1_k1 == 5 && cnt2_k1 > k) {
60+
index = aeiouIndex(word[left_k1++]);
61+
if (index == -1) {
62+
cnt2_k1--;
63+
} else {
64+
bin_k1[index]--;
65+
if (!bin_k1[index]) {
66+
cnt1_k1--;
67+
}
68+
}
69+
}
70+
ans += left_k - left_k1;
71+
}
72+
return ans;
73+
}
74+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-13 12:59:35
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-13 13:04:36
6+
*/
7+
package main
8+
9+
var aeiou3306 []byte = []byte{'a', 'e', 'i', 'o', 'u'}
10+
11+
func aeiouIndex3306(c byte) int {
12+
for i := 0; i < 5; i++ {
13+
if (aeiou3306[i] == c) {
14+
return i
15+
}
16+
}
17+
return -1
18+
}
19+
20+
func countOfSubstrings(word string, k int) (ans int64) {
21+
bin1 := make([]int, 5)
22+
cntc1, cntk1, left1 := 0, 0, 0
23+
bin2 := make([]int, 5)
24+
cntc2, cntk2, left2 := 0, 0, 0
25+
for i := range word {
26+
index := aeiouIndex3306(word[i])
27+
if index == -1 {
28+
cntk1++
29+
cntk2++
30+
} else {
31+
bin1[index]++
32+
if bin1[index] == 1 {
33+
cntc1++
34+
}
35+
bin2[index]++
36+
if bin2[index] == 1 {
37+
cntc2++
38+
}
39+
}
40+
41+
for cntc1 == 5 && cntk1 >= k {
42+
index = aeiouIndex3306(word[left1])
43+
left1++
44+
if index == -1 {
45+
cntk1--
46+
} else {
47+
bin1[index]--
48+
if bin1[index] == 0 {
49+
cntc1--
50+
}
51+
}
52+
}
53+
for cntc2 == 5 && cntk2 > k {
54+
index = aeiouIndex3306(word[left2])
55+
left2++
56+
if index == -1 {
57+
cntk2--
58+
} else {
59+
bin2[index]--
60+
if bin2[index] == 0 {
61+
cntc2--
62+
}
63+
}
64+
}
65+
ans += int64(left1 - left2)
66+
}
67+
return
68+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-13 12:52:32
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-13 12:59:04
6+
*/
7+
class Solution {
8+
private final char[] aeiou = {'a', 'e', 'i', 'o', 'u'};
9+
10+
private int aeiouIndex(char c) {
11+
for (int i = 0; i < 5; i++) {
12+
if (aeiou[i] == c) {
13+
return i;
14+
}
15+
}
16+
return -1;
17+
}
18+
19+
public long countOfSubstrings(String word, int k) {
20+
int[] bin1 = new int[5];
21+
int cntc1 = 0, cntk1 = 0, left1 = 0;
22+
int[] bin2 = new int[5];
23+
int cntc2 = 0, cntk2 = 0, left2 = 0;
24+
long ans = 0;
25+
for (char c : word.toCharArray()) {
26+
int index = aeiouIndex(c);
27+
if (index == -1) {
28+
cntk1++;
29+
cntk2++;
30+
} else {
31+
bin1[index]++;
32+
if (bin1[index] == 1) {
33+
cntc1++;
34+
}
35+
bin2[index]++;
36+
if (bin2[index] == 1) {
37+
cntc2++;
38+
}
39+
}
40+
41+
while (cntc1 == 5 && cntk1 >= k) {
42+
index = aeiouIndex(word.charAt(left1++));
43+
if (index == -1) {
44+
cntk1--;
45+
} else {
46+
bin1[index]--;
47+
if (bin1[index] == 0) {
48+
cntc1--;
49+
}
50+
}
51+
}
52+
while (cntc2 == 5 && cntk2 > k) {
53+
index = aeiouIndex(word.charAt(left2++));
54+
if (index == -1) {
55+
cntk2--;
56+
} else {
57+
bin2[index]--;
58+
if (bin2[index] == 0) {
59+
cntc2--;
60+
}
61+
}
62+
}
63+
ans += left1 - left2;
64+
}
65+
return ans;
66+
}
67+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-03-13 11:16:41
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-03-13 12:50:10
6+
'''
7+
from collections import defaultdict
8+
9+
class Solution:
10+
def countOfSubstrings(self, word: str, k: int) -> int:
11+
cnt11 = defaultdict(int)
12+
cnt21 = left1 = 0
13+
cnt12 = defaultdict(int)
14+
cnt22 = left2 = 0
15+
ans = 0
16+
for c in word:
17+
if c in 'aeiou':
18+
cnt11[c] += 1
19+
cnt12[c] += 1
20+
else:
21+
cnt21 += 1
22+
cnt22 += 1
23+
24+
while len(cnt11) == 5 and cnt21 >= k:
25+
if word[left1] in 'aeiou':
26+
cnt11[word[left1]] -= 1
27+
if not cnt11[word[left1]]:
28+
del cnt11[word[left1]]
29+
else:
30+
cnt21 -= 1
31+
left1 += 1
32+
while len(cnt12) == 5 and cnt22 > k:
33+
if word[left2] in 'aeiou':
34+
cnt12[word[left2]] -= 1
35+
if not cnt12[word[left2]]:
36+
del cnt12[word[left2]]
37+
else:
38+
cnt22 -= 1
39+
left2 += 1
40+
ans += left1 - left2
41+
return ans

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@
920920
|3285.找到稳定山的下标|简单|<a href="https://leetcode.cn/problems/find-indices-of-stable-mountains/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/12/19/LeetCode%203285.%E6%89%BE%E5%88%B0%E7%A8%B3%E5%AE%9A%E5%B1%B1%E7%9A%84%E4%B8%8B%E6%A0%87/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144596618" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-indices-of-stable-mountains/solutions/3025068/letmefly-3285zhao-dao-wen-ding-shan-de-x-u3wc/" target="_blank">LeetCode题解</a>|
921921
|3297.统计重新排列后包含另一个字符串的子字符串数目I|中等|<a href="https://leetcode.cn/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/09/LeetCode%203297.%E7%BB%9F%E8%AE%A1%E9%87%8D%E6%96%B0%E6%8E%92%E5%88%97%E5%90%8E%E5%8C%85%E5%90%AB%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%95%B0%E7%9B%AEI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145031494" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/solutions/3042787/letmefly-3297tong-ji-zhong-xin-pai-lie-h-8ele/" target="_blank">LeetCode题解</a>|
922922
|3305.元音辅音字符串计数I|中等|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/12/LeetCode%203305.%E5%85%83%E9%9F%B3%E8%BE%85%E9%9F%B3%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%AE%A1%E6%95%B0I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146197747" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i/solutions/3607571/letmefly-3305yuan-yin-fu-yin-zi-fu-chuan-ptkg/" target="_blank">LeetCode题解</a>|
923+
|3306.元音辅音字符串计数II|中等|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/13/LeetCode%203306.%E5%85%83%E9%9F%B3%E8%BE%85%E9%9F%B3%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%AE%A1%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146228751" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/solutions/3609545/letmefly-3306yuan-yin-fu-yin-zi-fu-chuan-7y2q/" target="_blank">LeetCode题解</a>|
923924
|剑指Offer0047.礼物的最大价值|简单|<a href="https://leetcode.cn/problems/li-wu-de-zui-da-jie-zhi-lcof/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/03/08/LeetCode%20%E5%89%91%E6%8C%87%20Offer%2047.%20%E7%A4%BC%E7%89%A9%E7%9A%84%E6%9C%80%E5%A4%A7%E4%BB%B7%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/129408765" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/li-wu-de-zui-da-jie-zhi-lcof/solutions/2155672/letmefly-jian-zhi-offer-47li-wu-de-zui-d-rekb/" target="_blank">LeetCode题解</a>|
924925
|剑指OfferII0041.滑动窗口的平均值|简单|<a href="https://leetcode.cn/problems/qIsx9U/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/16/LeetCode%20%E5%89%91%E6%8C%87%20Offer%20II%200041.%20%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E7%9A%84%E5%B9%B3%E5%9D%87%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125819216" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/qIsx9U/solution/by-tisfy-30mq/" target="_blank">LeetCode题解</a>|
925926
|剑指OfferII0091.粉刷房子|中等|<a href="https://leetcode.cn/problems/JEj789/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/06/25/LeetCode%20%E5%89%91%E6%8C%87%20Offer%20II%200091.%20%E7%B2%89%E5%88%B7%E6%88%BF%E5%AD%90/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125456885" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/JEj789/solution/letmefly-jian-zhi-offer-ii-091fen-shua-f-3olz/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)