↓快轉到主要內容

Hash-Table

LeetCode 1763: Longest Nice Substring
·1 分鐘
LeetCode Easy Sliding-Window Divide-and-Conquer Hash-Table String Bit-Manipulation
LeetCode 1763 解題筆記:沒有大小寫配對的字元一定不在答案裡,用它切開字串遞迴;長度相同時取左邊的
LeetCode 2781: Length of the Longest Valid Substring
·2 分鐘
LeetCode Hard Sliding-Window Hash-Table String Trie
LeetCode 2781 解題筆記:禁字最長只有 10,每個右端只檢查最後 10 個字元組成的後綴;找到禁字就把左端推到它後面,要找最短的那個(最靠右的起點)
LeetCode 2009: Minimum Number of Operations to Make Array Continuous
·1 分鐘
LeetCode Hard Sliding-Window Hash-Table Binary-Search Array
LeetCode 2009 解題筆記:最後的陣列是長度 n 的連續整數;去重排序後,用滑動視窗找值域寬度 <= n - 1 的最多不同值,其他都要改
LeetCode 3805: Count Caesar Cipher Pairs
·1 分鐘
LeetCode Medium Math Hash-Table String Counting
LeetCode 3805 解題筆記:把每個字串整串平移到第一個字母是 a,凱薩等價的字串會變成一樣;再數每種正規化結果的配對數
LeetCode 3804: Number of Centered Subarrays
·1 分鐘
LeetCode Medium Hash-Table Enumeration Array
LeetCode 3804 解題筆記:固定左端點往右擴,邊加總邊把元素放進集合,總和在集合裡就算一個
LeetCode 3803: Count Residue Prefixes
·1 分鐘
LeetCode Easy Hash-Table String
LeetCode 3803 解題筆記:邊掃邊把字元加進集合,前綴的不同字元數等於長度 % 3 就算一個
LeetCode 2831: Find the Longest Equal Subarray
·1 分鐘
LeetCode Medium Sliding-Window Hash-Table Binary-Search Array
LeetCode 2831 解題筆記:對每個值,把它出現的位置列出來;在位置列表上滑動視窗,要刪的數量 = 位置跨度 − 這個值的個數
LeetCode 2516: Take K of Each Character From Left and Right
·1 分鐘
LeetCode Medium Sliding-Window Hash-Table String
LeetCode 2516 解題筆記:從兩端拿等於中間留一段;留下的每種字元最多是總數 − k,找最長的這種中間視窗
LeetCode 3090: Maximum Length Substring With Two Occurrences
·1 分鐘
LeetCode Easy Sliding-Window Hash-Table String
LeetCode 3090 解題筆記:「求最長」的滑動視窗,剛加進來的字元超過 2 次就縮左邊
LeetCode 2958: Length of Longest Subarray With at Most K Frequency
·1 分鐘
LeetCode Medium Sliding-Window Hash-Table Array
LeetCode 2958 解題筆記:「求最長」的滑動視窗,剛加入的數字出現超過 k 次就縮左邊
LeetCode 1461: Check If a String Contains All Binary Codes of Size K
·1 分鐘
LeetCode Medium Hash-Table String Bit-Manipulation Rolling-Hash
LeetCode 1461 解題筆記:把所有長度 k 的子字串丟進集合,大小等於 2^k 就成立;最後一個起點是 len(s) - k
LeetCode 2953: Count Complete Substrings
·2 分鐘
LeetCode Hard Sliding-Window Hash-Table String
LeetCode 2953 解題筆記:先在相鄰字元差 > 2 的地方切段;每段枚舉有幾種字元 d,視窗長度固定是 d × k,維護「剛好出現 k 次的字元數」