Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .commitmsg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3120: AC.cpp (#1606) - AC,22.22%,57.14% + (en)
29 changes: 29 additions & 0 deletions Codes/3120-count-the-number-of-special-characters-i.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@
|3110.字符串的分数|简单|<a href="https://leetcode.cn/problems/score-of-a-string/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/15/LeetCode%203110.%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E5%88%86%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146275888" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/score-of-a-string/solutions/3612406/letmefly-3110zi-fu-chuan-de-fen-shu-mo-n-aqpo/" target="_blank">LeetCode题解</a>|
|3112.访问消失节点的最少时间|中等|<a href="https://leetcode.cn/problems/minimum-time-to-visit-disappearing-nodes/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/18/LeetCode%203112.%E8%AE%BF%E9%97%AE%E6%B6%88%E5%A4%B1%E8%8A%82%E7%82%B9%E7%9A%84%E6%9C%80%E5%B0%91%E6%97%B6%E9%97%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140530368" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-time-to-visit-disappearing-nodes/solutions/2848666/letmefly-3112fang-wen-xiao-shi-jie-dian-1cgwc/" target="_blank">LeetCode题解</a>|
|3115.质数的最大距离|中等|<a href="https://leetcode.cn/problems/maximum-prime-difference/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/02/LeetCode%203115.%E8%B4%A8%E6%95%B0%E7%9A%84%E6%9C%80%E5%A4%A7%E8%B7%9D%E7%A6%BB/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140121329" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-prime-difference/solutions/2828631/letmefly-3115zhi-shu-de-zui-da-ju-chi-zh-1yvd/" target="_blank">LeetCode题解</a>|
|3120.统计特殊字母的数量I|简单|<a href="https://leetcode.cn/problems/count-the-number-of-special-characters-i/" target="_blank">题目地址</a>|<a href="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/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/161432822" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-the-number-of-special-characters-i/solutions/3974744/letmefly-3120tong-ji-te-shu-zi-mu-de-shu-bata/" target="_blank">LeetCode题解</a>|
|3127.构造相同颜色的正方形|简单|<a href="https://leetcode.cn/problems/make-a-square-with-the-same-color/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/08/31/LeetCode%203127.%E6%9E%84%E9%80%A0%E7%9B%B8%E5%90%8C%E9%A2%9C%E8%89%B2%E7%9A%84%E6%AD%A3%E6%96%B9%E5%BD%A2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/141756605" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/make-a-square-with-the-same-color/solutions/2899199/letmefly-3127gou-zao-xiang-tong-yan-se-d-xp4l/" target="_blank">LeetCode题解</a>|
|3131.找出与数组相加的整数I|简单|<a href="https://leetcode.cn/problems/find-the-integer-added-to-array-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/08/08/LeetCode%203131.%E6%89%BE%E5%87%BA%E4%B8%8E%E6%95%B0%E7%BB%84%E7%9B%B8%E5%8A%A0%E7%9A%84%E6%95%B4%E6%95%B0I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/141037760" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-integer-added-to-array-i/solutions/2873708/letmefly-3131zhao-chu-yu-shu-zu-xiang-ji-mfd3/" target="_blank">LeetCode题解</a>|
|3132.找出与数组相加的整数II|中等|<a href="https://leetcode.cn/problems/find-the-integer-added-to-array-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/08/09/LeetCode%203132.%E6%89%BE%E5%87%BA%E4%B8%8E%E6%95%B0%E7%BB%84%E7%9B%B8%E5%8A%A0%E7%9A%84%E6%95%B4%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/141072842" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-integer-added-to-array-ii/solutions/2874942/letmefly-3132zhao-chu-yu-shu-zu-xiang-ji-eljs/" target="_blank">LeetCode题解</a>|
Expand Down
105 changes: 105 additions & 0 deletions Solutions/LeetCode 3120.统计特殊字母的数量I.md
Original file line number Diff line number Diff line change
@@ -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/)

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

<p>返回 <code>word</code> 中<strong> </strong><strong>特殊字母 </strong>的数量。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">word = "aaAbcBC"</span></p>

<p><strong>输出:</strong><span class="example-io">3</span></p>

<p><strong>解释:</strong></p>

<p><code>word</code> 中的特殊字母是 <code>'a'</code>、<code>'b'</code> 和 <code>'c'</code>。</p>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">word = "abc"</span></p>

<p><strong>输出:</strong><span class="example-io">0</span></p>

<p><strong>解释:</strong></p>

<p><code>word</code> 中不存在大小写形式同时出现的字母。</p>
</div>

<p><strong class="example">示例 3:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">word = "abBCab"</span></p>

<p><strong>输出:</strong>1</p>

<p><strong>解释:</strong></p>

<p><code>word</code> 中唯一的特殊字母是 <code>'b'</code>。</p>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= word.length &lt;= 50</code></li>
<li><code>word</code> 仅由小写和大写英文字母组成。</li>
</ul>



## 解题方法:哈希表

遍历一般字符串并把所有出现过的字符放入哈希表中,从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)
24 changes: 0 additions & 24 deletions test.cpp

This file was deleted.

9 changes: 9 additions & 0 deletions toSay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
* @Author: LetMeFly
* @Date: 2026-05-26 23:54:27
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2026-05-26 23:54:34
-->
todo: merge confilct

今日扇贝单词web端改版了
Loading