보통 0명 해결 정답률 0%

Spell Checker

List the words in a text that are missing from a dictionary, ignoring case and punctuation.

배우게 될 내용

  • Load words into a set for fast lookups
  • Split text into words with a character rule
  • Report results in first-seen order without duplicates

문제

번역본 보기

A word processor underlines words it does not know. Load the dictionary into a set (a hash table) so each lookup is fast, then scan the text.

A word is a maximal run of English letters (A-Z, a-z) and apostrophes; every other character (spaces, digits, punctuation) separates words. Words are compared without regard to case, so The matches the dictionary entry the.

Implement spell_checker(dictionary, text).

Input

dictionary: The known words. They may be in any case.

text: The text to check.

Output

Return the misspelled words in lowercase, in the order they first appear in the text, each listed only once. Return an empty list when every word is known.

제약 조건

0 ≤ dictionary size ≤ 2,000

0 ≤ length of text ≤ 10,000

예시

예시 1
입력:
dictionary = ["the", "cat", "sat", "on", "mat"]
text = "The cat sat on teh mat, the cta!"

예상 출력:
expected = ["teh", "cta"]
입력:
std::vector<std::string> dictionary = {"the", "cat", "sat", "on", "mat"};
std::string text = "The cat sat on teh mat, the cta!";

예상 출력:
std::vector<std::string> expected = {"teh", "cta"};
입력:
string[] dictionary = new string[] {"the", "cat", "sat", "on", "mat"};
string text = "The cat sat on teh mat, the cta!";

예상 출력:
string[] expected = new string[] {"teh", "cta"};

설명

teh and cta are not in the dictionary. Case and the comma do not matter for the other words: ["teh", "cta"].

예시 2
입력:
dictionary = ["Don't", "stop"]
text = "don't STOP, dont stop dont"

예상 출력:
expected = ["dont"]
입력:
std::vector<std::string> dictionary = {"Don't", "stop"};
std::string text = "don't STOP, dont stop dont";

예상 출력:
std::vector<std::string> expected = {"dont"};
입력:
string[] dictionary = new string[] {"Don't", "stop"};
string text = "don't STOP, dont stop dont";

예상 출력:
string[] expected = new string[] {"dont"};

설명

don't keeps its apostrophe and matches; dont is unknown and is listed once: ["dont"].

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Lowercase the dictionary words once when you build the set.

힌트 2

Build the current word character by character and finish it when you meet a non-letter that is not an apostrophe.

힌트 3

Keep a second set of words already reported.

예상 복잡도

O(D + T) time, O(D + T) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

아직 통과한 풀이가 없습니다. 풀어서 1위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.