雜湊 Hashing
67 題(19 題以此為主技法)
🎯 何時用
需要 O(1) 查詢/去重/計數/分組(兩數和、群組變位詞)。
🧩 模板心法
HashMap 存值→索引或計數;HashSet 去重;以正規化後的字串/tuple 當 key 分組。
Easy 18 題
- #1Two Sum
- #217Contains Duplicate
- #242Valid Anagram
- #169Majority Element
- #13Roman to Integer
- #205Isomorphic Strings
- #290Word Pattern
- #448Find All Numbers Disappeared in An Array
- #929Unique Email Addresses
- #1189Maximum Number of Balloons
- #2215Find the Difference of Two Arrays
- #202Happy Number
- #160Intersection of Two Linked Lists
- #219Contains Duplicate II
- #496Next Greater Element I
- #705Design HashSet
- #706Design HashMap
- #953Verifying An Alien Dictionary
Medium 42 題
- #49Group Anagrams
- #36Valid Sudoku
- #12Integer to Roman
- #554Brick Wall
- #2001Number of Pairs of Interchangeable Rectangles
- #3Longest Substring Without Repeating Characters
- #105Construct Binary Tree from Preorder and Inorder Traversal
- #128Longest Consecutive Sequence
- #133Clone Graph
- #139Word Break
- #347Top K Frequent Elements
- #424Longest Repeating Character Replacement
- #17Letter Combinations of a Phone Number
- #138Copy List with Random Pointer
- #146LRU Cache
- #380Insert Delete Get Random O(1)
- #438Find All Anagrams in a String
- #567Permutation in String
- #621Task Scheduler
- #904Fruit Into Baskets
- #981Time Based Key-Value Store
- #106Construct Binary Tree from Inorder and Postorder Traversal
- #187Repeated DNA Sequences
- #523Continuous Subarray Sum
- #535Encode and Decode TinyURL
- #560Subarray Sum Equals K
- #652Find Duplicate Subtrees
- #740Delete And Earn
- #752Open The Lock
- #763Partition Labels
- #767Reorganize String
- #846Hand of Straights
- #1396Design Underground System
- #1461Check if a String Contains all Binary Codes of Size K
- #1647Minimum Deletions to Make Character Frequencies Unique
- #1658Minimum Operations to Reduce X to Zero
- #1930Unique Length 3 Palindromic Subsequences
- #1980Find Unique Binary String
- #1993Operations On Tree
- #2013Detect Squares
- #2405Optimal Partition of String
- #2707Extra Characters in a String