Trie
Trie 字典樹
·2 分鐘
演算法
Trie
String
Prefix
Bit-Manipulation
用巢狀 dict 建 Trie、在節點上記數量、搭配 DFS 搜尋,以及什麼時候其實不需要 Trie
LeetCode 212: Word Search II
·1 分鐘
LeetCode
Hard
Trie
Backtracking
Matrix
LeetCode 212 解題筆記:把所有單字建成 Trie,網格 DFS 時同步走 Trie,找到就移除、空節點就剪掉
LeetCode 2416: Sum of Prefix Scores of Strings
·1 分鐘
LeetCode
Hard
Trie
String
Counting
LeetCode 2416 解題筆記:Trie 每個節點記錄經過的單字數,單字的答案就是沿路計數的總和
LeetCode 1178: Number of Valid Words for Each Puzzle
·1 分鐘
LeetCode
Hard
Bit-Manipulation
Hash-Map
Trie
LeetCode 1178 解題筆記:單字只在乎用了哪些字母,轉成 26-bit 遮罩計數,再枚舉謎題遮罩的所有子集合
LeetCode 1023: Camelcase Matching
·1 分鐘
LeetCode
Medium
Two-Pointers
String
Trie
LeetCode 1023 解題筆記:雙指針逐字比對,pattern 以外多出來的只能是小寫字母
LeetCode 2781: Length of the Longest Valid Substring
·2 分鐘
LeetCode
Hard
Sliding-Window
Hash-Table
String
Trie
LeetCode 2781 解題筆記:禁字最長只有 10,每個右端只檢查最後 10 個字元組成的後綴;找到禁字就把左端推到它後面,要找最短的那個(最靠右的起點)
LeetCode 208: Implement Trie (Prefix Tree)
·1 分鐘
LeetCode
Medium
Hash-Table
String
Design
Trie
LeetCode 208 解題筆記:每個節點是 children 字典加一個 is_end 標記;insert、search、startsWith 都是沿著字元往下走
LeetCode 14: Longest Common Prefix
·1 分鐘
LeetCode
Easy
Array
String
Trie
LeetCode 14 解題筆記:用最短的字串當上限,逐個位置檢查所有字串是否相同,第一個不同的位置就是答案的長度