zoukankan      html  css  js  c++  java
  • 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:

    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

  • 相关阅读:
    《将博客搬至CSDN》
    选课系统
    ATM_购物车
    python基础 面向对象编程
    python 基础 模块
    python基础 函数基础 模块:总复习
    第三篇:操作系统基础
    浅谈红黑树
    浅谈B和B+树
    第二篇:网络基础
  • 原文地址:https://www.cnblogs.com/wzj4858/p/7722297.html
Copyright © 2011-2022 走看看