leetcode

package
v0.0.0-...-3200de1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: MIT Imports: 0 Imported by: 0

README

208. Implement Trie (Prefix Tree)

题目

Implement a trie with insertsearch, and startsWith methods.

Example:

Trie trie = new Trie();

trie.insert("apple");
trie.search("apple");   // returns true
trie.search("app");     // returns false
trie.startsWith("app"); // returns true
trie.insert("app");   
trie.search("app");     // returns true

Note:

  • You may assume that all inputs are consist of lowercase letters a-z.
  • All inputs are guaranteed to be non-empty strings.

题目大意

实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作。

解题思路

  • 要求实现一个 Trie 的数据结构,具有 insertsearch, startsWith 三种操作
  • 这一题就是经典的 Trie 实现。本题的实现可以作为 Trie 的模板。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trie

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

func Constructor208

func Constructor208() Trie

* Initialize your data structure here.

func (*Trie) Insert

func (this *Trie) Insert(word string)

* Inserts a word into the trie.

func (*Trie) Search

func (this *Trie) Search(word string) bool

* Returns if the word is in the trie.

func (*Trie) StartsWith

func (this *Trie) StartsWith(prefix string) bool

* Returns if there is any word in the trie that starts with the given prefix.

Jump to

Keyboard shortcuts

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