12
返回列表 发新帖
楼主: Lookielooky
跳转到指定楼层
上一主题 下一主题
收起左侧

谷歌ng vo

🔗
johnnya 2021-5-21 06:41:35 | 只看该作者
全局:
请问下楼主,Facebook的好友推荐怎么做的啊,是直接brute force嘛
回复

使用道具 举报

🔗
lllxin37 2021-5-21 08:10:44 | 只看该作者
全局:
第一题想法, 输入是forest和set

  1. // forest contains root nodes on trees;
  2. // toRemove cotains the node object to be deleted from forest
  3. // use dfs to through all children nodes, if anything match, remove the subtree, also remove the node from Set

  4. // the only concern is how HashSet checks contains on TreeNode. It depends on hashcode method

  5. public List<TreeNode> delNodes(List<TreeNode> forest, Set<TreeNode> toRemove) {
  6.     List<TreeNode> ret = new ArrayList<>();
  7.     for (TreeNode curRoot : forest) {
  8.         if (toRemove.contains(curRoot)) {
  9.             toRemove.remove(curRoot);
  10.             continue;
  11.         }
  12.         ret.add(curRoot);
  13.     }
  14.     // use preorder to remove all nodes. It's possible that after below,
  15.     // toRemove not empty.
  16.     // for example if we have 3 is 5's children. And both 5, 3 in toRemove set.
  17.     // preorder will remove 5 first. Not touch 3.
  18.    
  19.     for (TreeNode curRoot : ret) {
  20.         preorder(curRoot, toRemove);
  21.     }
  22.     return ret;
  23. }

  24. private TreeNode preorder(TreeNode cur, Set<TreeNode> toRemove()) {
  25.     if (cur == null) return null;
  26.     if (toRemove.contains(cur)) {
  27.         toRemove.remove(cur);
  28.         return null;
  29.     }
  30.    
  31.     List<TreeNode> newChildren = new ArrayList<>();
  32.     for (TreeNode child : cur.children) {
  33.         TreeNode tmp = preorder(child, toRemove());
  34.         if (tmp == null) continue;
  35.         newChildren.add(tmp);
  36.     }
  37.     cur.children = newChildren;
  38.     return cur;
  39. }
复制代码

评分

参与人数 2大米 +2 收起 理由
fangzheng + 1 给你点个赞!
一片云的猫 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
salinghang17 2021-5-22 08:40:23 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
salinghang17 2021-5-22 09:10:40 | 只看该作者
全局:
最后一道题应该就是一个 Union Find 吧,请问一下给的是 一维坐标还是二维坐标呀
回复

使用道具 举报

🔗
kashimoto 2021-5-23 10:01:33 | 只看该作者
全局:
请问最后一题 “Then, that router shuts down, and can no longer send or receive messages.” 这个条件有被用到吗,还是followup里面用到了的
回复

使用道具 举报

🔗
fangzheng 2021-5-24 17:56:38 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

评分

参与人数 1大米 +1 收起 理由
damonguo + 1 赞第四题解释。

查看全部评分

回复

使用道具 举报

🔗
fangzheng 2021-5-24 18:29:13 | 只看该作者
全局:
lllxin37 发表于 2021-5-20 19:10
第一题想法, 输入是forest和set

[mw_shl_code=java,true]// forest contains root nodes on trees;

请问层主,这边为什么每次删完一个node要在set里同时删除哇,已加米!
回复

使用道具 举报

🔗
lllxin37 2021-5-25 01:32:13 | 只看该作者
全局:
fangzheng 发表于 2021-5-24 18:29
请问层主,这边为什么每次删完一个node要在set里同时删除哇,已加米!

没有啥特殊原因,就是顺手写的。唯一的好处就是如果set已经为空,就不用继续forest的遍历。 当然这个判断条件我没写进codes...

多谢加米!
回复

使用道具 举报

🔗
 楼主| Lookielooky 2021-5-25 02:28:54 来自APP | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
fangzheng 2021-5-25 03:21:43 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

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

本版积分规则

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