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:

  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 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的更多相关文章

  1. Week6 - 676.Implement Magic Dictionary

    Week6 - 676.Implement Magic Dictionary Implement a magic directory with buildDict, and search method ...

  2. LC 676. Implement Magic Dictionary

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

  3. LeetCode 676. Implement Magic Dictionary实现一个魔法字典 (C++/Java)

    题目: Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll ...

  4. [LeetCode] 676. Implement Magic Dictionary 实现神奇字典

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

  5. 【LeetCode】676. Implement Magic Dictionary 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 汉明间距 日期 题目地址:https://le ...

  6. [LeetCode] Implement Magic Dictionary 实现神奇字典

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

  7. [Swift]LeetCode676. 实现一个魔法字典 | Implement Magic Dictionary

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

  8. LeetCode - Implement Magic Dictionary

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

  9. [leetcode-676-Implement Magic Dictionary]

    Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...

随机推荐

  1. 最强最全面的大数据SQL经典面试题(由31位大佬共同协作完成)

    本套SQL题的答案是由许多小伙伴共同贡献的,1+1的力量是远远大于2的,有不少题目都采用了非常巧妙的解法,也有不少题目有多种解法.本套大数据SQL题不仅题目丰富多样,答案更是精彩绝伦! 注:以下参考答 ...

  2. c++之记一次常见数据类型在fedora和wind10下所占的长度

    包括: char , int , float, double, long ,long long , unsigned long long , long double 1.源码 #include < ...

  3. 【LeetCode】817. Linked List Components 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. 比例阀驱动电路后级PWM滤波尖刺如何消除?PWM通过RC低通滤波器模拟DAC

    双头比例阀驱动电路,采用单片机输出2路PWM,分别驱动功率器件(U100的2和4脚),经过U100的8和10脚输出供电电源的高压PWM波形,这个高压PWM经过R104和R114分别采样后经过电流放大器 ...

  5. AVD Pixel_2_API_30 is already running. lf that is not the case, delete the files at

    AVD Pixel_2_API_30 is already running. lf that is not the case, delete the files at C:\Users\Adminis ...

  6. 使用 Eclipse 可视化插件 windowbuilder 进行Java GUI开发(插件安装的两种方法)

    对于Java GUI开发 其实最方便的方法是用插件制作,当然先了解完代码原理是最好的. eclispe安装windowbuilder有两种方式,一种是离线安装,一种是在线安装. 一.第一种在线安装: ...

  7. Solr单机安装Version5.5.2

    Solr安装单机模式,基于Solr的安装版本为5.5.2. 安装规划 IP/机器名 安装软件 运行进程 zdh-9 solr jar 安装用户 solr/zdh1234 hadoop useradd ...

  8. 三角网格上的寻路算法Part.2—A*算法

    背景 继上一篇三角网格Dijkstra寻路算法之后,本篇将继续介绍一种更加智能,更具效率的寻路算法-A*算法,本文将首先介绍该算法的思想原理,再通过对比来说明二者之间的相同与不同之处,然后采用类似Di ...

  9. Docker_容器(container)使用(4)

    参数说明 -i: 交互式操作. -t: 终端. -d: 指定容器运行模式. --name:指定容器的NAMES字段名称,不指定则随机生成名称 --restart:容器启动策略.默认为no,常用为alw ...

  10. Git_使用SSH密钥操作远端仓库

    git支持多种传输协议,ssh协议是其中一种. 初次使用git的用户要使用ssh协议大概需要三个步骤: 生成密钥 设置远程仓库(本文以github为例)上的公钥 把git的 remote url 修改 ...