博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LC 676. Implement Magic Dictionary
阅读量:5297 次
发布时间:2019-06-14

本文共 1496 字,大约阅读时间需要 4 分钟。

Implement a magic directory with buildDict, and search methods.

For the method buildDict, you'll be given a list of non-repetitive words to build a dictionary.

For the method search, you'll be given a word, and judge whether if you modify exactly one character into another character in this word, the modified word is in the dictionary you just built.

Example 1:

Input: buildDict(["hello", "leetcode"]), Output: NullInput: search("hello"), Output: FalseInput: search("hhllo"), Output: TrueInput: search("hell"), Output: FalseInput: search("leetcoded"), Output: False

 

Note:

  1. You may assume that all the inputs are consist of lowercase letters a-z.
  2. For contest purpose, the test data is rather small by now. You could think about highly efficient algorithm after the contest.
  3. Please remember to RESET your class variables declared in class MagicDictionary, as static/class variables are persisted across multiple test cases. Please see  for more details.

 

 

Runtime: 0 ms, faster than 100.00% of C++ online submissions for Implement Magic Dictionary.

 

class MagicDictionary {public:  vector
strvec; explicit MagicDictionary() = default; void buildDict(const vector
& dict) { strvec = dict; } bool search(const string& word) { for(auto& vs : strvec){ if(vs.size() != word.size()) continue; int idx = -1; bool fit = true; unordered_set
s; for(int i=0; i

 

转载于:https://www.cnblogs.com/ethanhong/p/10208027.html

你可能感兴趣的文章
自动化构建工具
查看>>
Jan 15 - Next Permutation; Array; Pointer;
查看>>
分布式网上商城项目-项目查询功能错误
查看>>
如何使用帮助文档
查看>>
Form表单与ajax提交文件方式
查看>>
ubuntu中安装mongo
查看>>
USACO 1.1.1 Your Ride Is Here
查看>>
STL_Vector
查看>>
HBase之Table.put客户端流程
查看>>
二叉树模板(调试中)
查看>>
编程中常用的几个特殊值
查看>>
UEditor 在 Layer 模态框中无法使用问题
查看>>
【vue】如何引用外部cdn资源
查看>>
BBS-评论功能
查看>>
这又是一个测试
查看>>
Github入门操作实录
查看>>
生成300道小学四则运算题
查看>>
Windows怎么从命令行下载文件
查看>>
Chrome 及其 插件“个性化设置”备份
查看>>
第二章ARP——地址解析协议
查看>>