HashMap

题目

通过index和value来进行1对1映射(这里要求我们的value range和index range基本相近,在之后通过简单的swap可以rearrange values)

  • Leetcode 41. First Missing Positive

通过key来分组

  • Leetcode 6. ZigZag Conversion
  • Leetcode 49. Group Anagrams

记录并查询位置

  • Leetcode 380. Insert Delete GetRandom O(1) (remove时记得用到swap的技巧)
  • Insert Delete GetRandom O(1) - Duplicates allowed (remove时记得用到swap的技巧)
  • Leetcode 311. Sparse Matrix Multiplication

记录并查询当前key最后出现的位置

记录并查询数量/count

  • Leetcode 348. Design Tic-Tac-Toe
  • Leetcode 383. Ransom Note
  • Leetcode 362. Design Hit Counter
  • Leetcode 387. First Unique Character in a String
  • Leetcode 389. Find the Difference
  • Leetcode 30. Substring with Concatenation of All Words
  • Leetcode 36. Valid Sudoku
  • Leetcode 391. Perfect Rectangle (思路非常巧妙的一道题,通过统计每个corner出现的次数以及大矩形的面积来判断)

求对称点

  • Leetcode 356. Line Reflection

求关注者/求neighbor

  • Leetcode 355. Design Twitter

LRU思想 (queue + HashMap)这样可以达到O(1)的查找以及增删

  • Leetcode 379. Design Phone Directory

results matching ""

    No results matching ""