Skip to content

Commit f58f423

Browse files
committed
update: 添加问题“3305.元音辅音字符串计数I”的代码和题解(#803)
feat: (#797) close #795 如果这个commit成功close掉(#795)了,就说明(#795)完成了。 因为close(#795)的信息是来自.commitmsg文件的。 fix: python`os.system(f'git commit -s -m "{commitMsg}"')`无法处理多行 Signed-off-by: LetMeFly666 <[email protected]>
1 parent f363e04 commit f58f423

14 files changed

+528
-4
lines changed

.commitmsg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ close #795
44
如果这个commit成功close掉(#795)了,就说明(#795)完成了。
55
因为close(#795)的信息是来自.commitmsg文件的。
66

7-
fix: 忘记转义了
8-
https://github.com/LetMeFly666/LeetCode/pull/799#discussion_r1986604369
7+
fix: python`os.system(f'git commit -s -m "{commitMsg}"')`无法处理多行

COMMITmultiline.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-03-11 14:35:27
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-03-11 14:35:27
6+
'''
7+
'''
8+
Author: LetMeFly
9+
Date: 2025-03-11 14:23:47
10+
LastEditors: LetMeFly.xyz
11+
LastEditTime: 2025-03-11 14:33:39
12+
'''
13+
import os
14+
import subprocess
15+
commitMsg = "2s2d323\nsf\nf3"
16+
os.system('git add .')
17+
subprocess.run(['git', 'commit', '-s', '-m', commitMsg])
18+
19+
"""
20+
import os
21+
commitMsg = "f\n2\n3"
22+
os.system('git add .')
23+
os.system(f'git commit -s -m "{commitMsg}"')
24+
25+
执行这段代码执行结果的commit msg只会是f而无法添加下面的行
26+
"""
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-12 09:29:51
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-12 09:40:21
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
static constexpr char yuanyin[] = "aeiou";
14+
15+
inline bool allYuan(int* cnt) {
16+
for (int i = 0; i < 5; i++) {
17+
if (!cnt[i]) {
18+
return false;
19+
}
20+
}
21+
return true;
22+
}
23+
public:
24+
int countOfSubstrings(string word, int k) {
25+
int ans = 0;
26+
for (int i = 0; i < word.size(); i++) {
27+
for (int j = i; j < word.size(); j++) {
28+
int cnt[5] = {0};
29+
int cntk = 0;
30+
for (int m = i; m <= j; m++) {
31+
bool isYuan = false;
32+
for (int n = 0; n < 5; n++) {
33+
if (word[m] == yuanyin[n]) {
34+
isYuan = true;
35+
cnt[n]++;
36+
break;
37+
}
38+
}
39+
cntk += !isYuan;
40+
}
41+
ans += allYuan(cnt) && cntk == k;
42+
}
43+
}
44+
return ans;
45+
}
46+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-12 09:38:45
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-12 09:40:10
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
static constexpr char yuanyin[] = "aeiou";
14+
15+
inline bool allYuan(int* cnt) {
16+
for (int i = 0; i < 5; i++) {
17+
if (!cnt[i]) {
18+
return false;
19+
}
20+
}
21+
return true;
22+
}
23+
public:
24+
int countOfSubstrings(string word, int k) {
25+
int ans = 0;
26+
for (int i = 0; i < word.size(); i++) {
27+
int cnt[5] = {0};
28+
int cntk = 0;
29+
for (int j = i; j < word.size(); j++) {
30+
bool isYuan = false;
31+
for (int n = 0; n < 5; n++) {
32+
if (word[j] == yuanyin[n]) {
33+
isYuan = true;
34+
cnt[n]++;
35+
break;
36+
}
37+
}
38+
cntk += !isYuan;
39+
ans += allYuan(cnt) && cntk == k;
40+
}
41+
}
42+
return ans;
43+
}
44+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-12 09:54:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-12 10:03:41
6+
*/
7+
package main
8+
9+
var aeiou map[byte]bool = map[byte]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': true}
10+
11+
func countOfSubstrings(word string, k int) (ans int) {
12+
for i, _ := range word {
13+
cnt5 := map[byte]bool{}
14+
cntk := 0
15+
for _, c := range word[i:] {
16+
if aeiou[byte(c)] {
17+
cnt5[byte(c)] = true
18+
} else {
19+
cntk++
20+
}
21+
if len(cnt5) == 5 && cntk == k {
22+
ans++
23+
}
24+
}
25+
}
26+
return
27+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-12 09:44:49
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-12 09:53:33
6+
*/
7+
class Solution {
8+
private final char[] aeiou = {'a', 'e', 'i', 'o', 'u'};
9+
10+
private int isaeiou(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+
private boolean all(int[] cnt) {
20+
for (int i = 0; i < 5; i++) {
21+
if (cnt[i] == 0) {
22+
return false;
23+
}
24+
}
25+
return true;
26+
}
27+
28+
public int countOfSubstrings(String word, int k) {
29+
int ans = 0;
30+
for (int i = 0; i < word.length(); i++) {
31+
int[] cnt5 = new int[5];
32+
int cntk = 0;
33+
for (int j = i; j < word.length(); j++) {
34+
int index = isaeiou(word.charAt(j));
35+
if (index == -1) {
36+
cntk++;
37+
} else {
38+
cnt5[index]++;
39+
}
40+
if (all(cnt5) && cntk == k) {
41+
ans++;
42+
}
43+
}
44+
}
45+
return ans;
46+
}
47+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-03-12 09:41:17
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-03-12 09:44:21
6+
'''
7+
AEIOU = 'aeiou'
8+
class Solution:
9+
def countOfSubstrings(self, word: str, k: int) -> int:
10+
ans = 0
11+
for i in range(len(word)):
12+
cnt5 = [0] * 5
13+
cntk = 0
14+
for j in range(i, len(word)):
15+
for n in range(5):
16+
if word[j] == AEIOU[n]:
17+
cnt5[n] += 1
18+
break
19+
cntk += word[j] not in AEIOU
20+
ans += all(cnt5) and cntk == k
21+
return ans

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@
919919
|3280.将日期转换为二进制表示|简单|<a href="https://leetcode.cn/problems/convert-date-to-binary/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/01/LeetCode%203280.%E5%B0%86%E6%97%A5%E6%9C%9F%E8%BD%AC%E6%8D%A2%E4%B8%BA%E4%BA%8C%E8%BF%9B%E5%88%B6%E8%A1%A8%E7%A4%BA/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144870892" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/convert-date-to-binary/solutions/3036032/letmefly-3280jiang-ri-qi-zhuan-huan-wei-149mv/" target="_blank">LeetCode题解</a>|
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>|
922+
|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>|
922923
|剑指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>|
923924
|剑指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>|
924925
|剑指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)