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

  • 相关阅读:
    手把手教你使用markdown
    spring WebSocket详解
    springmvc请求参数异常处理
    蓝桥杯java 算法提高 摆花
    蓝桥杯java 算法提高 扶老奶奶过街
    蓝桥杯java 算法训练 未名湖边的烦恼
    蓝桥杯java 算法训练 Torry的困惑(基本型)
    java算法 硬币
    java算法 牌型种数
    java算法 方格填数
  • 原文地址:https://www.cnblogs.com/wzj4858/p/7722297.html
Copyright © 2011-2022 走看看