Skip to content

Commit f0fcfb2

Browse files
committed
update: 添加问题“966.元音拼写检查器”的代码和题解 (#1129)
word: en+jp cpp - AC,5.87%,44.44% my.conf -> my.cnf ``` -> ` Signed-off-by: LetMeFly666 <[email protected]>
1 parent 1e7b6fe commit f0fcfb2

11 files changed

+339
-137
lines changed

.commitmsg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
word: en+jp
2+
cpp - AC,5.87%,44.44%
3+
my.conf -> my.cnf
4+
``` -> `

Codes/0966-vowel-spellchecker.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-14 15:21:26
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-14 15:33:04
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
string toLower(string s) {
14+
for (char& c : s) {
15+
if ('A' <= c && c <= 'Z') {
16+
c = tolower(c);
17+
}
18+
}
19+
return s;
20+
}
21+
22+
string toAeiou(string s) {
23+
for (char& c : s) {
24+
if (c == 'e' || c == 'i' || c == 'o' || c == 'u') {
25+
c = 'a';
26+
}
27+
}
28+
return s;
29+
}
30+
public:
31+
vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) {
32+
unordered_set<string> original;
33+
unordered_map<string, string> lowers, aeious; // 其实改为<string, int>只存下标也行
34+
for (string& s : wordlist) {
35+
original.insert(s);
36+
string lower = toLower(s);
37+
if (!lowers.count(lower)) {
38+
lowers[lower] = s;
39+
}
40+
string aeiou = toAeiou(lower);
41+
if (!aeious.count(aeiou)) {
42+
aeious[aeiou] = s;
43+
}
44+
}
45+
for (string& q : queries) {
46+
if (original.count(q)) {
47+
continue;
48+
}
49+
string lower = toLower(q);
50+
if (lowers.count(lower)) {
51+
q = lowers[lower];
52+
continue;
53+
}
54+
string aeiou = toAeiou(lower);
55+
if (aeious.count(aeiou)) {
56+
q = aeious[aeiou];
57+
continue;
58+
}
59+
q = ""; // 这个别忘了
60+
}
61+
return queries;
62+
}
63+
};

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: LetMeFly
33
* @Date: 2022-05-19 18:48:53
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-09-01 23:59:01
5+
* @LastEditTime: 2025-09-14 16:20:27
66
-->
77
# LetLeet Blog
88

@@ -123,6 +123,7 @@
123123
|QT - 实例 - 可点击的进度条、无窗口应用|<a href="https://blog.letmefly.xyz/2023/08/02/Other-QT-Example-ClickableProgressBar-noWindow/">本平台博客</a>|无|
124124
|北邮暑期课 - R语言数据分析|<a href="https://blog.letmefly.xyz/2023/06/26/Other-RLanguageDataAnalysis">本平台博客</a>|无|
125125
|域名转到国外注册商-备案失效风险折腾日记|<a href="https://blog.letmefly.xyz/2025/06/23/Other-Server-BeiAnXiaoTuCao/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/148844350">CSDN博客</a>|
126+
|服务器 - 从一台服务器切换至另一台服务器(损失数十条PV记录为代价)|<a href="https://blog.letmefly.xyz/2025/09/14/Other-Server-From1Server2Another/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/151684306">CSDN博客</a>|
126127
|SVG(可缩放矢量图形) - toLearn 和 创建|<a href="https://blog.letmefly.xyz/2023/07/06/Other-SVG-ToLearnAndToCreate/">本平台博客</a>|无|
127128
|Verilog学习笔记 - 极简极入门级|<a href="https://blog.letmefly.xyz/2023/01/06/Other-Verilog-Note/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/128584160">CSDN博客</a>|
128129
|Cloudflare Warp+,1.1.1.1,如何使用,如何获取免费流量,如何优选IP|<a href="https://blog.letmefly.xyz/2023/08/25/Other-VPN-CloudflareWarp+1.1.1.1">本平台博客</a>|无|
@@ -453,6 +454,7 @@
453454
|0946.验证栈序列|中等|<a href="https://leetcode.cn/problems/validate-stack-sequences/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/08/31/LeetCode%200946.%E9%AA%8C%E8%AF%81%E6%A0%88%E5%BA%8F%E5%88%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/126616819" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/validate-stack-sequences/solution/letmefly-946yan-zheng-zhan-xu-lie-by-tis-st5n/" target="_blank">LeetCode题解</a>|
454455
|0952.按公因数计算最大组件大小|困难|<a href="https://leetcode.cn/problems/largest-component-size-by-common-factor/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/30/LeetCode%200952.%E6%8C%89%E5%85%AC%E5%9B%A0%E6%95%B0%E8%AE%A1%E7%AE%97%E6%9C%80%E5%A4%A7%E7%BB%84%E4%BB%B6%E5%A4%A7%E5%B0%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/126069985" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/largest-component-size-by-common-factor/solution/letmefly-952an-gong-yin-shu-ji-suan-zui-4ljri/" target="_blank">LeetCode题解</a>|
455456
|0961.在长度2N的数组中找出重复N次的元素|简单|<a href="https://leetcode.cn/problems/n-repeated-element-in-size-2n-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/05/21/LeetCode%200961.%E5%9C%A8%E9%95%BF%E5%BA%A62N%E7%9A%84%E6%95%B0%E7%BB%84%E4%B8%AD%E6%89%BE%E5%87%BA%E9%87%8D%E5%A4%8DN%E6%AC%A1%E7%9A%84%E5%85%83%E7%B4%A0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/124897591" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-closest-palindrome/solution/letmefly-da-an-hou-xuan-by-letmefly-2-k2vn/" target="_blank">LeetCode题解</a>|
457+
|0966.元音拼写检查器|中等|<a href="https://leetcode.cn/problems/vowel-spellchecker/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/14/LeetCode%200966.%E5%85%83%E9%9F%B3%E6%8B%BC%E5%86%99%E6%A3%80%E6%9F%A5%E5%99%A8/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151690858" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/vowel-spellchecker/solutions/3781983/letmefly-966yuan-yin-pin-xie-jian-cha-qi-16uh/" target="_blank">LeetCode题解</a>|
456458
|0970.强整数|中等|<a href="https://leetcode.cn/problems/powerful-integers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/05/02/LeetCode%200970.%E5%BC%BA%E6%95%B4%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/130461751" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/powerful-integers/solutions/2253101/letmefly-970qiang-zheng-shu-by-tisfy-w22m/" target="_blank">LeetCode题解</a>|
457459
|0982.按位与为零的三元组|困难|<a href="https://leetcode.cn/problems/triples-with-bitwise-and-equal-to-zero/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/03/04/LeetCode%200982.%E6%8C%89%E4%BD%8D%E4%B8%8E%E4%B8%BA%E9%9B%B6%E7%9A%84%E4%B8%89%E5%85%83%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/129334313" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/triples-with-bitwise-and-equal-to-zero/solutions/2146568/letmefly-982an-wei-yu-wei-ling-de-san-yu-071t/" target="_blank">LeetCode题解</a>|
458460
|0983.最低票价|中等|<a href="https://leetcode.cn/problems/minimum-cost-for-tickets/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/01/LeetCode%200983.%E6%9C%80%E4%BD%8E%E7%A5%A8%E4%BB%B7/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142672522" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-cost-for-tickets/solutions/2936476/letmefly-983zui-di-piao-jie-ji-yi-hua-so-o7w3/" target="_blank">LeetCode题解</a>|
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
title: 966.元音拼写检查器:三个哈希表实现
3+
date: 2025-09-14 22:53:03
4+
tags: [题解, LeetCode, 中等, 数组, 哈希表, set, map, 字符串]
5+
categories: [题解, LeetCode]
6+
---
7+
8+
# 【LetMeFly】966.元音拼写检查器:三个哈希表实现
9+
10+
力扣题目链接:[https://leetcode.cn/problems/vowel-spellchecker/](https://leetcode.cn/problems/vowel-spellchecker/)
11+
12+
<p>在给定单词列表&nbsp;<code>wordlist</code>&nbsp;的情况下,我们希望实现一个拼写检查器,将查询单词转换为正确的单词。</p>
13+
14+
<p>对于给定的查询单词&nbsp;<code>query</code>,拼写检查器将会处理两类拼写错误:</p>
15+
16+
<ul>
17+
<li>大小写:如果查询匹配单词列表中的某个单词(<strong>不区分大小写</strong>),则返回的正确单词与单词列表中的大小写相同。
18+
19+
<ul>
20+
<li>例如:<code>wordlist = ["yellow"]</code>, <code>query = "YellOw"</code>: <code>correct = "yellow"</code></li>
21+
<li>例如:<code>wordlist = ["Yellow"]</code>, <code>query = "yellow"</code>: <code>correct = "Yellow"</code></li>
22+
<li>例如:<code>wordlist = ["yellow"]</code>, <code>query = "yellow"</code>: <code>correct = "yellow"</code></li>
23+
</ul>
24+
</li>
25+
<li>元音错误:如果在将查询单词中的元音 <code>('a', 'e', 'i', 'o', 'u')</code>&nbsp;&nbsp;分别替换为任何元音后,能与单词列表中的单词匹配(<strong>不区分大小写</strong>),则返回的正确单词与单词列表中的匹配项大小写相同。
26+
<ul>
27+
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yollow"</code>: <code>correct = "YellOw"</code></li>
28+
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yeellow"</code>: <code>correct = ""</code> (无匹配项)</li>
29+
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yllw"</code>: <code>correct = ""</code> (无匹配项)</li>
30+
</ul>
31+
</li>
32+
</ul>
33+
34+
<p>此外,拼写检查器还按照以下优先级规则操作:</p>
35+
36+
<ul>
37+
<li>当查询完全匹配单词列表中的某个单词(<strong>区分大小写</strong>)时,应返回相同的单词。</li>
38+
<li>当查询匹配到大小写问题的单词时,您应该返回单词列表中的第一个这样的匹配项。</li>
39+
<li>当查询匹配到元音错误的单词时,您应该返回单词列表中的第一个这样的匹配项。</li>
40+
<li>如果该查询在单词列表中没有匹配项,则应返回空字符串。</li>
41+
</ul>
42+
43+
<p>给出一些查询 <code>queries</code>,返回一个单词列表 <code>answer</code>,其中 <code>answer[i]</code> 是由查询 <code>query = queries[i]</code> 得到的正确单词。</p>
44+
45+
<p>&nbsp;</p>
46+
47+
<p><strong>示例 1:</strong></p>
48+
49+
<pre>
50+
<strong>输入:</strong>wordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]
51+
<strong>输出:</strong>["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]</pre>
52+
53+
<p><strong>示例 2:</strong></p>
54+
55+
<pre>
56+
<b>输入:</b>wordlist = ["yellow"], queries = ["YellOw"]
57+
<b>输出:</b>["yellow"]
58+
</pre>
59+
60+
<p>&nbsp;</p>
61+
62+
<p><strong>提示:</strong></p>
63+
64+
<ul>
65+
<li><code>1 &lt;= wordlist.length, queries.length &lt;= 5000</code></li>
66+
<li><code>1 &lt;= wordlist[i].length, queries[i].length &lt;= 7</code></li>
67+
<li><code>wordlist[i]</code>&nbsp;和&nbsp;<code>queries[i]</code>&nbsp;只包含英文字母</li>
68+
</ul>
69+
70+
71+
72+
## 解题方法:哈希表
73+
74+
第一优先级:字符串完全相同。我们只需要使用一个哈希表把原始字符加入哈希表中,对于一个query就能知道是否存在完全匹配的word了。若存在则返回,不存在进入第二优先级。
75+
76+
第二优先级:字符串忽略大小写看是否相同。我们只需要将每个字符串全转为小写字母后插入哈希表即可。键为小写字符串,值为第一个对应这个小写字符串的原始字符串。对于一个query,小写字符化后看是否在哈希表中,若在则返回否则进入第三优先级。
77+
78+
第三优先级:字符串忽略大小写且可以自由替换元音音符。将字符串小写后并将所有元音音符替换为'a'并插入哈希表中。插入方式和query方式同上。
79+
80+
第四优先级:直接返回空字符串。
81+
82+
+ 时间复杂度$O((w+q)L)$,其中$w=len(wordlist)$,$q=len(queries)$,$L$是平均一个单词的长度
83+
+ 空间复杂度$O(wL)$
84+
85+
### AC代码
86+
87+
#### C++
88+
89+
```cpp
90+
/*
91+
* @Author: LetMeFly
92+
* @Date: 2025-09-14 15:21:26
93+
* @LastEditors: LetMeFly.xyz
94+
* @LastEditTime: 2025-09-14 15:33:04
95+
*/
96+
class Solution {
97+
private:
98+
string toLower(string s) {
99+
for (char& c : s) {
100+
if ('A' <= c && c <= 'Z') {
101+
c = tolower(c);
102+
}
103+
}
104+
return s;
105+
}
106+
107+
string toAeiou(string s) {
108+
for (char& c : s) {
109+
if (c == 'e' || c == 'i' || c == 'o' || c == 'u') {
110+
c = 'a';
111+
}
112+
}
113+
return s;
114+
}
115+
public:
116+
vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) {
117+
unordered_set<string> original;
118+
unordered_map<string, string> lowers, aeious; // 其实改为<string, int>只存下标也行
119+
for (string& s : wordlist) {
120+
original.insert(s);
121+
string lower = toLower(s);
122+
if (!lowers.count(lower)) {
123+
lowers[lower] = s;
124+
}
125+
string aeiou = toAeiou(lower);
126+
if (!aeious.count(aeiou)) {
127+
aeious[aeiou] = s;
128+
}
129+
}
130+
for (string& q : queries) {
131+
if (original.count(q)) {
132+
continue;
133+
}
134+
string lower = toLower(q);
135+
if (lowers.count(lower)) {
136+
q = lowers[lower];
137+
continue;
138+
}
139+
string aeiou = toAeiou(lower);
140+
if (aeious.count(aeiou)) {
141+
q = aeious[aeiou];
142+
continue;
143+
}
144+
q = ""; // 这个别忘了
145+
}
146+
return queries;
147+
}
148+
};
149+
```
150+
151+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/151690858)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/09/14/LeetCode%200966.%E5%85%83%E9%9F%B3%E6%8B%BC%E5%86%99%E6%A3%80%E6%9F%A5%E5%99%A8/)哦~
152+
>
153+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ categories: [自用]
12131213
|prayer|n. 祷告,祈祷文,经文|
12141214
|better-off|adj. 比较富裕的,境况较好的|
12151215
|||
1216-
|courteous|adj. 有礼貌的,客气的|
1216+
|<font color="#28bea0" title="二次复习">courteous</font>|adj. 有礼貌的,客气的|
12171217
|postpone|v. 延期,延迟|
12181218
|||
12191219
|gaol|n. 监狱(jail的英式拼法)|
@@ -1434,6 +1434,10 @@ categories: [自用]
14341434
|||
14351435
|vest|n. 汗衫,背心<br/>v. 给xx穿上(法衣),赋予xx权力,授予|
14361436
|breach|n. (对法规等的)违背,破坏;缺口,突破口<br/>v. 违背,在..上打开缺口|
1437+
|||
1438+
|fuss|n. 大惊小怪,反应过度;争吵<br/>v. 大惊小怪,过度关心|
1439+
|arrear|n. 落后,欠款<details><summary>例句</summary>The arts of medicine and surgery are somewhat in <font color="#28bea0">arrear</font> in Africa.<br/>医疗和外科手术在非洲稍微有些落后。</details>|
1440+
|frail|adj. 脆弱的,虚弱的,易碎的|
14371441

14381442
+ 这个web要是能设计得可以闭眼(完全不睁眼)键盘控制背单词就好了。
14391443
+ 也许可以加个AI用最近词编故事功能(返回接口中支持标注所使用单词高亮?)

Solutions/Other-Japanese-LearningNotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ xx型
14621462
|何を持って行きますか。<br/>要带什么去。|
14631463
|帽子がいります。<br/>需要帽子。|
14641464
|中山さんはトロント出身ですか。<br/>中山先生是多伦多人吗?|
1465-
|<br/>|
1465+
|どこかに行きませんか。<br/>要不要去某个地方呢?|
14661466
|<br/>|
14671467
|<br/>|
14681468
|<br/>|

Solutions/Other-Linux-MysqlMemReduce.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ ps aux|head -1;ps aux|sort -rn -k3|head -10
2929

3030
**解释:**
3131

32-
```ps aux|head -1;ps aux|sort -rn -k3|head -10```相当于```ps aux|head -1``````ps aux|sort -rn -k3|head -10```分别执行
32+
`ps aux|head -1;ps aux|sort -rn -k3|head -10`相当于`ps aux|head -1``ps aux|sort -rn -k3|head -10`分别执行
3333

3434
**ps**
3535

36-
其中```ps```的参数```a```代表“所有进程(all with tty, including other users)”,```u```代表“user(user-oriented format)”,```x```代表“显示所有进程(processes without controlling ttys)”
36+
其中`ps`的参数`a`代表“所有进程(all with tty, including other users)”,`u`代表“user(user-oriented format)”,`x`代表“显示所有进程(processes without controlling ttys)”
3737

38-
那么```ps aux```就显示了所有进程的资源占用信息:
38+
那么`ps aux`就显示了所有进程的资源占用信息:
3939

4040
```bash
4141
[Tisfy@LetMeFly ~]# ps aux
@@ -50,21 +50,21 @@ root 6 0.0 0.0 0 0 ? I< 2022 0:00 [kworker/0:0H
5050

5151
**head**
5252

53-
```head```命令用于显示前几行。```head -1```就是显示第一行的内容,也就是
53+
`head`命令用于显示前几行。`head -1`就是显示第一行的内容,也就是
5454

5555
```
5656
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
5757
```
5858

59-
同理,```head -10```就是显示前10行
59+
同理,`head -10`就是显示前10行
6060

6161
**sort**
6262

63-
```sort```命令用于排序,```-r```是“从大到小排序(reverse the result of comparisons)”默认从小到大,```-n```是“根据数值排序(compare according to string numerical value)”,```-k```是“以第几列为依据进行排序(sort via a key; KEYDEF gives location and type)”(下标从1开始,没有-k0)
63+
`sort`命令用于排序,`-r`是“从大到小排序(reverse the result of comparisons)”默认从小到大,`-n`是“根据数值排序(compare according to string numerical value)”,`-k`是“以第几列为依据进行排序(sort via a key; KEYDEF gives location and type)”(下标从1开始,没有-k0)
6464

6565
## How to do
6666

67-
我修改了Mysql的配置文件(文件路径:```/etc/my.conf```
67+
我修改了Mysql的配置文件(文件路径:`/etc/my.cnf`
6868

6969
可以修改或在下方添加这些参数。参数的具体意义可以在网上搜索
7070

@@ -103,7 +103,7 @@ PS,今日添加了table_definition_cache,内存占用大概降低了5%(2G
103103
free
104104
```
105105

106-
其中```free -m```是以M形式显示(显示多少M),```free -g```是以G的形式显示(1.7G会显示为1G哈哈)
106+
其中`free -m`是以M形式显示(显示多少M),`free -g`是以G的形式显示(1.7G会显示为1G哈哈)
107107

108108
**对于我的服务器**,MySQL大约会使用300M,远程VSCode在有连接时大约会使用160M,无连接时大约会使用70M,django项目每个约70M,nginx大约会使用5M
109109

0 commit comments

Comments
 (0)