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

  • 相关阅读:
    如何使用反射技术获取泛型类的真实类型?
    applicationContext.xml文件如何调用外部properties等配置文件
    applicationContext.xml中的使用${}是代表什么意思?
    net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
    MySql中LongText字段对应Hibernate映射文件的设置(转)
    ckeditor的详细配置(转)
    XML-学习
    WSDL-学习总结
    ONVIF-WSDL
    sourceinsight相关配置
  • 原文地址:https://www.cnblogs.com/wzj4858/p/7722297.html
Copyright © 2011-2022 走看看