Skip to content

Commit 9f03252

Browse files
committed
test: [20250914] Add (966)
1 parent 4451eb6 commit 9f03252

File tree

15 files changed

+264
-5
lines changed

15 files changed

+264
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ members = [
317317
"problems/problems_2785",
318318
"problems/problems_3227",
319319
"problems/problems_3541",
320+
"problems/problems_966",
320321
]
321322

322323
[package]
@@ -656,3 +657,4 @@ solution_1733 = { path = "problems/problems_1733", features = ["solution_1733"]
656657
solution_2785 = { path = "problems/problems_2785", features = ["solution_2785"] }
657658
solution_3227 = { path = "problems/problems_3227", features = ["solution_3227"] }
658659
solution_3541 = { path = "problems/problems_3541", features = ["solution_3541"] }
660+
solution_966 = { path = "problems/problems_966", features = ["solution_966"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "3541",
2+
"daily": "966",
33
"plans": ["3674", "problems", "3675", "problems", "3676", "problems"]
44
}

golang/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
problem "leetCode/problems/problems_3541"
4+
problem "leetCode/problems/problems_966"
55
"testing"
66
)
77

88
func TestSolution(t *testing.T) {
9-
TestEach(t, "3541", "problems", problem.Solve)
9+
TestEach(t, "966", "problems", problem.Solve)
1010
}

problems/problems_966/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "solution_966"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 966 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_966 = []
12+
13+
[dependencies]
14+
serde_json = "1.0"
15+
rand = "0.8.4"
16+
regex = "1.10.5"
17+
library = { path = "../../rust/library", features = ["model"] }
18+
19+
[lib]
20+
name = "solution_966"
21+
path = "solution.rs"

problems/problems_966/Solution.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
5+
using namespace std;
6+
using json = nlohmann::json;
7+
8+
class Solution {
9+
public:
10+
vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) {
11+
12+
}
13+
};
14+
15+
json leetcode::qubh::Solve(string input_json_values) {
16+
vector<string> inputArray;
17+
size_t pos = input_json_values.find('\n');
18+
while (pos != string::npos) {
19+
inputArray.push_back(input_json_values.substr(0, pos));
20+
input_json_values = input_json_values.substr(pos + 1);
21+
pos = input_json_values.find('\n');
22+
}
23+
inputArray.push_back(input_json_values);
24+
25+
Solution solution;
26+
vector<string> wordlist = json::parse(inputArray.at(0));
27+
vector<string> queries = json::parse(inputArray.at(1));
28+
return solution.spellchecker(wordlist, queries);
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package problems.problems_966;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import java.util.*;
5+
import qubhjava.BaseSolution;
6+
7+
8+
public class Solution extends BaseSolution {
9+
public String[] spellchecker(String[] wordlist, String[] queries) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
String[] wordlist = jsonArrayToStringArray(inputJsonValues[0]);
16+
String[] queries = jsonArrayToStringArray(inputJsonValues[1]);
17+
return JSON.toJSON(spellchecker(wordlist, queries));
18+
}
19+
}

problems/problems_966/problem.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 966. Vowel Spellchecker [Rating: 1795.04]
2+
3+
<p>Given a <code>wordlist</code>, we want to implement a spellchecker that converts a query word into a correct word.</p>
4+
5+
<p>For a given <code>query</code> word, the spell checker handles two categories of spelling mistakes:</p>
6+
7+
<ul>
8+
<li>Capitalization: If the query matches a word in the wordlist (<strong>case-insensitive</strong>), then the query word is returned with the same case as the case in the wordlist.
9+
<ul>
10+
<li>Example: <code>wordlist = [&quot;yellow&quot;]</code>, <code>query = &quot;YellOw&quot;</code>: <code>correct = &quot;yellow&quot;</code></li>
11+
<li>Example: <code>wordlist = [&quot;Yellow&quot;]</code>, <code>query = &quot;yellow&quot;</code>: <code>correct = &quot;Yellow&quot;</code></li>
12+
<li>Example: <code>wordlist = [&quot;yellow&quot;]</code>, <code>query = &quot;yellow&quot;</code>: <code>correct = &quot;yellow&quot;</code></li>
13+
</ul>
14+
</li>
15+
<li>Vowel Errors: If after replacing the vowels <code>(&#39;a&#39;, &#39;e&#39;, &#39;i&#39;, &#39;o&#39;, &#39;u&#39;)</code> of the query word with any vowel individually, it matches a word in the wordlist (<strong>case-insensitive</strong>), then the query word is returned with the same case as the match in the wordlist.
16+
<ul>
17+
<li>Example: <code>wordlist = [&quot;YellOw&quot;]</code>, <code>query = &quot;yollow&quot;</code>: <code>correct = &quot;YellOw&quot;</code></li>
18+
<li>Example: <code>wordlist = [&quot;YellOw&quot;]</code>, <code>query = &quot;yeellow&quot;</code>: <code>correct = &quot;&quot;</code> (no match)</li>
19+
<li>Example: <code>wordlist = [&quot;YellOw&quot;]</code>, <code>query = &quot;yllw&quot;</code>: <code>correct = &quot;&quot;</code> (no match)</li>
20+
</ul>
21+
</li>
22+
</ul>
23+
24+
<p>In addition, the spell checker operates under the following precedence rules:</p>
25+
26+
<ul>
27+
<li>When the query exactly matches a word in the wordlist (<strong>case-sensitive</strong>), you should return the same word back.</li>
28+
<li>When the query matches a word up to capitlization, you should return the first such match in the wordlist.</li>
29+
<li>When the query matches a word up to vowel errors, you should return the first such match in the wordlist.</li>
30+
<li>If the query has no matches in the wordlist, you should return the empty string.</li>
31+
</ul>
32+
33+
<p>Given some <code>queries</code>, return a list of words <code>answer</code>, where <code>answer[i]</code> is the correct word for <code>query = queries[i]</code>.</p>
34+
35+
<p>&nbsp;</p>
36+
<p><strong class="example">Example 1:</strong></p>
37+
<pre><strong>Input:</strong> wordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]
38+
<strong>Output:</strong> ["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]
39+
</pre><p><strong class="example">Example 2:</strong></p>
40+
<pre><strong>Input:</strong> wordlist = ["yellow"], queries = ["YellOw"]
41+
<strong>Output:</strong> ["yellow"]
42+
</pre>
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= wordlist.length, queries.length &lt;= 5000</code></li>
48+
<li><code>1 &lt;= wordlist[i].length, queries[i].length &lt;= 7</code></li>
49+
<li><code>wordlist[i]</code> and <code>queries[i]</code> consist only of only English letters.</li>
50+
</ul>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# 966. 元音拼写检查器 [难度分: 1795.04]
2+
3+
<p>在给定单词列表&nbsp;<code>wordlist</code>&nbsp;的情况下,我们希望实现一个拼写检查器,将查询单词转换为正确的单词。</p>
4+
5+
<p>对于给定的查询单词&nbsp;<code>query</code>,拼写检查器将会处理两类拼写错误:</p>
6+
7+
<ul>
8+
<li>大小写:如果查询匹配单词列表中的某个单词(<strong>不区分大小写</strong>),则返回的正确单词与单词列表中的大小写相同。
9+
<ul>
10+
<li>例如:<code>wordlist = ["yellow"]</code>, <code>query = "YellOw"</code>: <code>correct = "yellow"</code></li>
11+
<li>例如:<code>wordlist = ["Yellow"]</code>, <code>query = "yellow"</code>: <code>correct = "Yellow"</code></li>
12+
<li>例如:<code>wordlist = ["yellow"]</code>, <code>query = "yellow"</code>: <code>correct = "yellow"</code></li>
13+
</ul>
14+
</li>
15+
<li>元音错误:如果在将查询单词中的元音 <code>('a', 'e', 'i', 'o', 'u')</code>&nbsp;&nbsp;分别替换为任何元音后,能与单词列表中的单词匹配(<strong>不区分大小写</strong>),则返回的正确单词与单词列表中的匹配项大小写相同。
16+
<ul>
17+
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yollow"</code>: <code>correct = "YellOw"</code></li>
18+
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yeellow"</code>: <code>correct = ""</code> (无匹配项)</li>
19+
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yllw"</code>: <code>correct = ""</code> (无匹配项)</li>
20+
</ul>
21+
</li>
22+
</ul>
23+
24+
<p>此外,拼写检查器还按照以下优先级规则操作:</p>
25+
26+
<ul>
27+
<li>当查询完全匹配单词列表中的某个单词(<strong>区分大小写</strong>)时,应返回相同的单词。</li>
28+
<li>当查询匹配到大小写问题的单词时,您应该返回单词列表中的第一个这样的匹配项。</li>
29+
<li>当查询匹配到元音错误的单词时,您应该返回单词列表中的第一个这样的匹配项。</li>
30+
<li>如果该查询在单词列表中没有匹配项,则应返回空字符串。</li>
31+
</ul>
32+
33+
<p>给出一些查询 <code>queries</code>,返回一个单词列表 <code>answer</code>,其中 <code>answer[i]</code> 是由查询 <code>query = queries[i]</code> 得到的正确单词。</p>
34+
35+
<p>&nbsp;</p>
36+
37+
<p><strong>示例 1:</strong></p>
38+
39+
<pre>
40+
<strong>输入:</strong>wordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]
41+
<strong>输出:</strong>["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]</pre>
42+
43+
<p><strong>示例 2:</strong></p>
44+
45+
<pre>
46+
<b>输入:</b>wordlist = ["yellow"], queries = ["YellOw"]
47+
<b>输出:</b>["yellow"]
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
52+
<p><strong>提示:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= wordlist.length, queries.length &lt;= 5000</code></li>
56+
<li><code>1 &lt;= wordlist[i].length, queries[i].length &lt;= 7</code></li>
57+
<li><code>wordlist[i]</code>&nbsp;和&nbsp;<code>queries[i]</code>&nbsp;只包含英文字母</li>
58+
</ul>

problems/problems_966/solution.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package problem966
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func spellchecker(wordlist []string, queries []string) []string {
10+
11+
}
12+
13+
func Solve(inputJsonValues string) any {
14+
inputValues := strings.Split(inputJsonValues, "\n")
15+
var wordlist []string
16+
var queries []string
17+
18+
if err := json.Unmarshal([]byte(inputValues[0]), &wordlist); err != nil {
19+
log.Fatal(err)
20+
}
21+
if err := json.Unmarshal([]byte(inputValues[1]), &queries); err != nil {
22+
log.Fatal(err)
23+
}
24+
25+
return spellchecker(wordlist, queries)
26+
}

problems/problems_966/solution.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import solution
2+
from typing import *
3+
4+
5+
class Solution(solution.Solution):
6+
def solve(self, test_input=None):
7+
return self.spellchecker(*test_input)
8+
9+
def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:
10+
pass
11+

0 commit comments

Comments
 (0)