楼主: youling_tong
跳转到指定楼层
上一主题 下一主题
收起左侧

2021刷题打卡

🔗
 楼主| youling_tong 2021-8-9 12:22:56 | 只看该作者
全局:
2021/08/08

Backtracking

79. Word Search
489. Robot Room Cleaner
  • This solution is based on the same idea as maze solving algorithm called right-hand rule
  • backtrack: how to restore to original position



回复

使用道具 举报

🔗
 楼主| youling_tong 2021-8-9 23:26:57 | 只看该作者
全局:
✅ HashTable
✅ Depth-First Search
✅ Dynamic Programming
✅ Union Find
✅ Backtracking
⏹ Heap (Priority Queue)
⭕ Breadth-First Search
⭕ Stack
⭕ Queue
⭕ Graph
⭕ Two Pointers
⭕ Prefix Sum
⭕ Binary Search

2021/08/09

Backtracking

126. Word Ladder II
  • The key here is to treat word as vertexes, so we will translate this question to a graph problem
  • The trickiest part is to build the graph and there are several places need to be cautious about: 1) previously traversed nodes should not be treated as curr node's neighbor; 2) the nodes at the same level should not be treated as curr node's neighbor; 3) next level's nodes, if it's already enqueued, we shouldn't enqueue it again.
  • By doing this, we built a DAG, which ensures shortedst path for to reach the destination. We only need to do DFS/backtracking to search for the destination node
47. Permutations II
  • use boolean[] to track if current element is used or not
  • to remove duplication, when curr element == prev element, and prev element is not used, we should skip.
131. Palindrome Partitioning
  • Nothing specital, just need careful thought processing
46. Permutations
17. Letter Combinations of a Phone Number

Heap (PriorityQueue)
973. K Closest Points to Origin
  • maxHeap approach and minHeap approach
347. Top K Frequent Elements
23. Merge k Sorted Lists



回复

使用道具 举报

🔗
 楼主| youling_tong 2021-9-8 01:04:58 | 只看该作者
全局:
本帖最后由 youling_tong 于 2021-9-7 10:07 编辑

✅ HashTable
✅ Depth-First Search
✅ Dynamic Programming
✅ Union Find
✅ Backtracking
⏹ Heap (Priority Queue)
⭕ Breadth-First Search
⭕ Stack
⭕ Queue
⭕ Graph
⭕ Two Pointers
⭕ Prefix Sum
⭕ Binary Search


2021/09/07
Heap (PriorityQueue)

1263. Minimum Moves to Move a Box to Their Target Location
  • Two BFS: the first one to check if the box can be moved to target, the second one to check if the person can reach to the position to move the box
658. Find K Closest Elements
  • Used PriorityQueue but the time complexity is O(NlogK + KlogK)
  • Binary search is the optimal solution, time complexity is O(log(N-K))

1424. Diagonal Traverse II
  • Draw diagram to figure out the solution


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表