676. Implement Magic Dictionary
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: Null
- Input: search("hello"), Output: False
- Input: search("hhllo"), Output: True
- Input: search("hell"), Output: False
- Input: search("leetcoded"), Output: False
Note:
- You may assume that all the inputs are consist of lowercase letters
a-z
. - For contest purpose, the test data is rather small by now. You could think about highly efficient algorithm after the contest.
- Please remember to RESET your class variables declared in class MagicDictionary, as static/class variables are persisted across multiple test cases. Please see here for more details.
题目含义:实现一个builddict方法和search方法。
builddict方法,你会得到多个不重复的单词列表。
对于方法搜索,你将得到一个词,并判断替换一个字符后,是否出现在了刚刚建立的词典中。
思路:建立字典时候,解析给定的多个单词,去掉位置i后剩余的字符串作为key,位置i以及上面的字符charat(i)构成数组作为value保存在map。
搜索时候,同样的方法,去掉位置i后剩余的字符串作为key,如果在map中出现了,进一步判断位置i和value中的值是否位置相等等内容不等,如果满足就返回true。遍历完成后返回false
676. Implement Magic Dictionary的更多相关文章
- Week6 - 676.Implement Magic Dictionary
Week6 - 676.Implement Magic Dictionary Implement a magic directory with buildDict, and search method ...
- LC 676. Implement Magic Dictionary
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
- LeetCode 676. Implement Magic Dictionary实现一个魔法字典 (C++/Java)
题目: Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll ...
- [LeetCode] 676. Implement Magic Dictionary 实现神奇字典
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
- 【LeetCode】676. Implement Magic Dictionary 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 汉明间距 日期 题目地址:https://le ...
- [LeetCode] Implement Magic Dictionary 实现神奇字典
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
- [Swift]LeetCode676. 实现一个魔法字典 | Implement Magic Dictionary
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
- LeetCode - Implement Magic Dictionary
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
- [leetcode-676-Implement Magic Dictionary]
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
随机推荐
- 有个奇怪的问题,配置成/system/index,jsp页面时没有经过过滤器进行拦截,而配置成redirectAction时是可以直接跳转刀片loginJsp.action
有个奇怪的问题,配置成/system/index,jsp页面时没有经过过滤器进行拦截,而配置成redirectAction时是可以直接跳转刀片loginJsp.action 但是我直接访问/syste ...
- Linux使用docker安装Jenkins 并进行jar包发布
拉取镜像 docker pull jenkins/jenkins:lts 创建docker-compose.yml 文件 (主要习惯 也可以不用这种方式) Linux安装docker-compose ...
- table中tr、td标签设置只读,不能修改(readonly属性)
在不能修改的位置加上代码:onselectstart="return false" οnselect="document.selection.empty()" ...
- 【LeetCode】448. Find All Numbers Disappeared in an Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 方法一:暴力求解 方法二:原地变负做标记 方法三:使用set ...
- 【LeetCode】447. Number of Boomerangs 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- web安全之xss跨站脚本攻击
实验(一) 一.预备知识 1.HTML基础知识 2.phpstudy运用 3.xss的分类 二.实验环境 1.火狐浏览器.Chrome浏览器 2.phpstudy 三.环境搭建 反射型xss环 ...
- Chapter 12 IP Weighting and Marginal Structural Model
目录 12.1 The causal question 12.2 Estimating IP weights via modeling 12.3 Stabilized IP weights 12.4 ...
- <数据结构>KMP算法
next数组 定义 严格定义:next[i]表示使子串s[0...k] == s[i-k...i]的最大的k(前后缀可以重叠,但不能是s[0..i]本身) 含义:最长相等前后缀的下标,没有则赋-1 图 ...
- UML 基本模型元素
目录 1. 结构模型元素 (1)类(class) (2)接口(interface) (3)协作(collaboration) (4)用例(use case) (5)活动类(active class) ...
- 日志分析系统 - k8s部署ElasticSearch集群
K8s部署ElasticSearch集群 1.前提准备工作 1.1 创建elastic的命名空间 namespace编排文件如下: elastic.namespace.yaml --- apiVers ...