problem0676

package
v0.0.0-...-db5e768 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2019 License: MIT Imports: 0 Imported by: 0

README

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.

解题思路

见程序注释

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MagicDictionary

type MagicDictionary struct {
	// contains filtered or unexported fields
}

MagicDictionary 是一个神奇的字典

func Constructor

func Constructor() MagicDictionary

Constructor 构建了神奇字典

func (*MagicDictionary) BuildDict

func (md *MagicDictionary) BuildDict(dict []string)

BuildDict 往字典里面添加内容

func (*MagicDictionary) Search

func (md *MagicDictionary) Search(word string) bool

Search returns if there is any word in the trie that equals to the given word after modifying exactly one character

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL