GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/thinkings/trie.md at master · zfcfuture/leetcode

Expand file tree

/

trie.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
27 lines (17 loc) · 1.89 KB
/

trie.md

Copy path

File metadata and controls

27 lines (17 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

前缀树问题

截止目前(2020-02-04) 前缀树(字典树) 在 LeetCode 一共有 17 道题目。其中 2 道简单,8 个中等,7 个困难。

这里总结了四道题,弄懂这几道, 那么前缀树对你应该不是大问题, 希望这个专题可以帮到正在学习前缀树 的你。

前缀树的 api 主要有以下几个:

  • insert(word): 插入一个单词
  • search(word):查找一个单词是否存在
  • startWith(word): 查找是否存在以 word 为前缀的单词

其中 startWith 是前缀树最核心的用法,其名称前缀树就从这里而来。大家可以先拿 208 题开始,熟悉一下前缀树,然后再尝试别的题目。

一个前缀树大概是这个样子:

如图每一个节点存储一个字符,然后外加一个控制信息表示是否是单词结尾,实际使用过程可能会有细微差别,不过变化不大。

以下是本专题的四道题目的题解,内容会持续更新,感谢你的关注~

  • 0208.implement-trie-prefix-tree
  • 0211.add-and-search-word-data-structure-design
  • 0212.word-search-ii
  • 0472.concatenated-words
  • 0820.short-encoding-of-words
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.