yozyyyqls / leetcode-notebook

Slowly constructing my leetcode notes...
0 stars 0 forks source link

概念 #2

Open yozyyyqls opened 1 year ago

yozyyyqls commented 1 year ago

Anagram

An anagram is a word formed by rearranging the letters of a word, typically using the original letters only once.

original word = "anagram"
anagram = "nagaram"
yozyyyqls commented 1 year ago

Trie (Prefix Tree)

Description

Trie is a data structure used to retrieve a key in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

Implement

The definition of the node in the prefix tree:

class TrieNode:
    self.children = {}
    # It is essential and easy to ignore that we should mark the end of a word.
    self.endOfWord = False