diff --git a/.commitmsg b/.commitmsg new file mode 100644 index 000000000000..c1f77aeefcdf --- /dev/null +++ b/.commitmsg @@ -0,0 +1 @@ +3120: AC.cpp (#1606) - AC,22.22%,57.14% + (en) \ No newline at end of file diff --git a/Codes/3120-count-the-number-of-special-characters-i.cpp b/Codes/3120-count-the-number-of-special-characters-i.cpp new file mode 100644 index 000000000000..3e11b811af36 --- /dev/null +++ b/Codes/3120-count-the-number-of-special-characters-i.cpp @@ -0,0 +1,29 @@ +/* + * @Author: LetMeFly + * @Date: 2026-05-26 23:50:43 + * @LastEditors: LetMeFly.xyz + * @LastEditTime: 2026-05-26 23:53:14 + */ +#ifdef _DEBUG +#include "_[1,2]toVector.h" +#endif + +class Solution { +public: + int numberOfSpecialChars(string word) { + bool lower[26] = {false}, upper[26] = {false}; + for (char c : word) { + if ('a' <= c && c <= 'z') { + lower[c - 'a'] = true; + } else { + upper[c - 'A'] = true; + } + } + + int ans = 0; + for (int i = 0; i < 26; i++) { + ans += lower[i] && upper[i]; + } + return ans; + } +}; diff --git a/README.md b/README.md index 7c4579cb50fd..b79dcdb87e00 100644 --- a/README.md +++ b/README.md @@ -1057,6 +1057,7 @@ |3110.字符串的分数|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3112.访问消失节点的最少时间|中等|题目地址|题解地址|CSDN题解|LeetCode题解| |3115.质数的最大距离|中等|题目地址|题解地址|CSDN题解|LeetCode题解| +|3120.统计特殊字母的数量I|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3127.构造相同颜色的正方形|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3131.找出与数组相加的整数I|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3132.找出与数组相加的整数II|中等|题目地址|题解地址|CSDN题解|LeetCode题解| diff --git "a/Solutions/LeetCode 3120.\347\273\237\350\256\241\347\211\271\346\256\212\345\255\227\346\257\215\347\232\204\346\225\260\351\207\217I.md" "b/Solutions/LeetCode 3120.\347\273\237\350\256\241\347\211\271\346\256\212\345\255\227\346\257\215\347\232\204\346\225\260\351\207\217I.md" new file mode 100644 index 000000000000..3a3945deee19 --- /dev/null +++ "b/Solutions/LeetCode 3120.\347\273\237\350\256\241\347\211\271\346\256\212\345\255\227\346\257\215\347\232\204\346\225\260\351\207\217I.md" @@ -0,0 +1,105 @@ +--- +title: 3120.统计特殊字母的数量 I:(手写)哈希表 +date: 2026-05-26 23:55:19 +tags: [题解, LeetCode, 简单, 哈希表, set, 字符串] +categories: [题解, LeetCode] +--- + +# 【LetMeFly】3120.统计特殊字母的数量 I:(手写)哈希表 + +力扣题目链接:[https://leetcode.cn/problems/count-the-number-of-special-characters-i/](https://leetcode.cn/problems/count-the-number-of-special-characters-i/) + +

给你一个字符串 word。如果 word 中同时存在某个字母的小写形式和大写形式,则称这个字母为 特殊字母

+ +

返回 word 特殊字母 的数量。

+ +

 

+ +

示例 1:

+ +
+

输入:word = "aaAbcBC"

+ +

输出:3

+ +

解释:

+ +

word 中的特殊字母是 'a''b''c'

+
+ +

示例 2:

+ +
+

输入:word = "abc"

+ +

输出:0

+ +

解释:

+ +

word 中不存在大小写形式同时出现的字母。

+
+ +

示例 3:

+ +
+

输入:word = "abBCab"

+ +

输出:1

+ +

解释:

+ +

word 中唯一的特殊字母是 'b'

+
+ +

 

+ +

提示:

+ + + + + +## 解题方法:哈希表 + +遍历一般字符串并把所有出现过的字符放入哈希表中,从0到25遍历这26个字母,看哪个字母的大小写都出现过。 + +有办法使用数组代替(作为)哈希表吗?以及有办法使用52长度的数组作为哈希表吗?有,判断下大小写放入数组对应的位置就好。 + ++ 时间复杂度$O(len(word)+C)$,其中$C=26\times 2$ ++ 空间复杂度$O(C)$ + +### AC代码 + +#### C++ + +```cpp +/* + * @LastEditTime: 2026-05-26 23:53:14 + */ +class Solution { +public: + int numberOfSpecialChars(string word) { + bool lower[26] = {false}, upper[26] = {false}; + for (char c : word) { + if ('a' <= c && c <= 'z') { + lower[c - 'a'] = true; + } else { + upper[c - 'A'] = true; + } + } + + int ans = 0; + for (int i = 0; i < 26; i++) { + ans += lower[i] && upper[i]; + } + return ans; + } +}; +``` + +> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/161432822)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2026/05/26/LeetCode%203120.%E7%BB%9F%E8%AE%A1%E7%89%B9%E6%AE%8A%E5%AD%97%E6%AF%8D%E7%9A%84%E6%95%B0%E9%87%8FI/)哦~ +> +> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode) diff --git a/test.cpp b/test.cpp deleted file mode 100644 index d5a0ed9eedce..000000000000 --- a/test.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * @Author: LetMeFly - * @Date: 2026-05-13 12:08:45 - * @LastEditors: LetMeFly.xyz - * @LastEditTime: 2026-05-21 21:54:06 - * @Description: MacOS.ok - */ -#include -#include -#include -using namespace std; - -int main() { - vector v; - v.push_back("hello"); - v.push_back("world"); - - cout << v[0] << endl; - - int n; - cin >> n; - cout << n << endl; - return 0; -} diff --git a/toSay.md b/toSay.md new file mode 100644 index 000000000000..550858496fec --- /dev/null +++ b/toSay.md @@ -0,0 +1,9 @@ + +todo: merge confilct + +今日扇贝单词web端改版了 \ No newline at end of file