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

[高频题] 记录贴,互勉

🔗
 楼主| 微信用户_b99d1cc 2023-9-18 15:08:18 | 只看该作者
全局:
841. Keys and Rooms
DFS search

image.png (23.86 KB, 下载次数: 8)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-19 01:37:53 | 只看该作者
全局:
1202. Smallest String With Swaps
union-find
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-21 02:52:22 | 只看该作者
全局:
207. Course Schedule
Check indegree of each course

image.png (37.09 KB, 下载次数: 6)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-21 02:58:11 | 只看该作者
全局:
微信用户_b99d1cc 发表于 2023-9-20 10:52
207. Course Schedule
Check indegree of each course

可以对Queue里面的for loop优化,通过arrayList记住需要cur作为pre对应的课,只访问对应的课而不是所有的pair
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-21 09:50:22 | 只看该作者
全局:
210. Course Schedule II
Topological order

image.png (41.75 KB, 下载次数: 6)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-23 21:46:19 | 只看该作者
全局:
802. Find Eventual Safe States
Graph coloring:    1 if visited, 2 if terminal, 0 if unvisited
DFS solution

image.png (54.37 KB, 下载次数: 6)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-24 00:05:37 | 只看该作者
全局:
399. Evaluate Division
UnionFind solution
a/b = 2 which means a=2b we can set b as root, weight[a] = 2
In order to use unionFind, we need to map the String value to an index.
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-29 01:10:54 | 只看该作者
全局:
839. Similar String Groups
UnionFind, uses a function to check if the string is similar to another string.
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-29 01:21:22 | 只看该作者
全局:
905. Sort Array By Parity
use front counter and end counter to put the even and odd from the beginning and end of the array

image.png (325.23 KB, 下载次数: 11)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-29 02:37:18 | 只看该作者
全局:
952. Largest Component Size by Common Factor
Use union-find to union all the factors of the number, then find the largest common factor by map the root and count of each number.
Key point: for each number, the largest factor number is less than sqrt(num).

image.png (179.86 KB, 下载次数: 10)

image.png
回复

使用道具 举报

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

本版积分规则

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