↓快轉到主要內容

String-Matching

LeetCode 796: Rotate String
·1 分鐘
LeetCode Easy String String-Matching
LeetCode 796 解題筆記:goal 是 s 的旋轉,等價於兩者長度相同而且 goal 出現在 s + s 裡
LeetCode 572: Subtree of Another Tree
·1 分鐘
LeetCode Easy Tree Depth-First-Search String-Matching Binary-Tree
LeetCode 572 解題筆記:對 root 的每一個節點都檢查一次「以它為根的子樹跟 subRoot 是否相同」;遞迴時要呼叫 isSubtree,不是只比左右小孩
LeetCode 459: Repeated Substring Pattern
·1 分鐘
LeetCode Easy String String-Matching Z-Algorithm Knuth-Morris-Pratt-Algorithm
LeetCode 459 解題筆記:s 由某個子字串重複組成,等價於 s 出現在 (s + s) 去掉頭尾字元之後的字串裡
LeetCode 28: Find the Index of the First Occurrence in a String
·1 分鐘
LeetCode Easy Two-Pointers String String-Matching Z-Algorithm
LeetCode 28 解題筆記:在每個起點比對 needle,或直接用 str.find;index 找不到會丟例外