LeetCode Trie常見的題型以及要注意的點

Tech In Pieces發表於2020-12-14

LeetCode: Word Squares
LeetCode: Word Search II
LeetCode: Stream of Characters
LeetCode: Short Encoding of Words
LeetCode: Replace Words
LeetCode: Remove Sub-Folders from the Filesystem
LeetCode: Prefix and Suffix Search
LeetCode: Maximum XOR of Two Numbers in an Array
LeetCode: Map Sum Pairs
LeetCode: Longest Word in Dictionary
LeetCode: Implement Trie (Prefix Tree)
LeetCode: Implement Magic Dictionary
LeetCode: Add and Search Word – Data structure design

Trie可以解決哪些抽象問題呢?
Count of distinct substrings of a string (計算String裡面有多少獨一無二的substrings)
Generate all unique substrings for given string (輸出所有獨一無二的substrings)
Finding the longest repeated substring (找出最長的有重複的substring)
Finding the longest common substring (找出LCS)
Finding the longest palindrome in a string (找出最長的palindrome)
(其實除了第二個 其他的都像是DP問題 但是Trie可能解決輸出結果而不是長度的問題)

Trie都有哪些要注意的點:
常見的trie的operations: insert/search/startsWith

Trie常見的用處:
fuzzy matching
live data stream
遇到這兩個東西要能想起來可以用trie來處理。

相關文章