Problem0211

package
v0.0.0-...-4e682c9 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: MIT Imports: 0 Imported by: 0

README

211. Add and Search Word - Data structure design

题目

Design a data structure that supports the following two operations:

void addWord(word)
bool search(word)

search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter.

For example:

addWord("bad")
addWord("dad")
addWord("mad")
search("pad") -> false
search("bad") -> true
search(".ad") -> true
search("b..") -> true

Note: You may assume that all words are consist of lowercase letters a-z.

click to show hint.

You should be familiar with how a Trie works. If not, please work on this problem: Implement Trie (Prefix Tree) first.

解题思路

见程序注释

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WordDictionary

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

WordDictionary 是字典

func Constructor

func Constructor() WordDictionary

Constructor 构建 WordDictionary Initialize your data structure here.

func (*WordDictionary) AddWord

func (d *WordDictionary) AddWord(word string)

AddWord 往 WordDictionary 中添加 word Adds a word into the data structure.

func (*WordDictionary) Search

func (d *WordDictionary) Search(word string) bool

Search 返回 true 如果 WordDictionary 中包含有 word Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter.

Jump to

Keyboard shortcuts

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