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

FB intern Round1

🔗
yuxrose 2015-4-5 04:31:38 | 只看该作者
全局:
想问问lz第二题的binary tree是full tree还是any tree啊? any tree的话代码也不好写的
回复

使用道具 举报

🔗
ppips 2015-4-5 04:38:58 | 只看该作者
全局:
yuxrose 发表于 2015-4-5 04:31
想问问lz第二题的binary tree是full tree还是any tree啊? any tree的话代码也不好写的

好像没有什么区别吧 只要是前序遍历就可以吧?
回复

使用道具 举报

🔗
haoxuango 2015-4-5 04:40:48 | 只看该作者
全局:
strstr 能用brute force 吗
回复

使用道具 举报

🔗
yuxrose 2015-4-5 04:58:21 | 只看该作者
全局:
ppips 发表于 2015-4-5 04:38
好像没有什么区别吧 只要是前序遍历就可以吧?

不太一样吧,如果是full tree的话,left child直接连right child, 如果不是的话,像下面这个
     A
B         C
D null  E null

这种情况D是连E,还是不连,保持原状? 连E的话就得找下个同level的下个child,这里比较麻烦一下,也是我觉得next pointer II 比 I 最麻烦的地方。
回复

使用道具 举报

🔗
yuxrose 2015-4-5 07:06:22 | 只看该作者
全局:
汗我好像看错题了,不是要connect nodes,是successor啊!
回复

使用道具 举报

🔗
yuxrose 2015-4-5 07:10:24 | 只看该作者
全局:
lch04 发表于 2015-4-5 00:52
第二题还是LC原题吖

能告诉我是哪道题吗?
回复

使用道具 举报

🔗
ppips 2015-4-5 08:10:54 | 只看该作者
全局:
yuxrose 发表于 2015-4-5 07:10
能告诉我是哪道题吗?

lc原题是inorder iterator 这个是preorder 不过差不多实现起来
回复

使用道具 举报

🔗
haungge0385 2015-4-7 05:13:26 | 只看该作者
全局:
请问有大神贴一下tree iterator 的代码吗?烧香感谢。。。
回复

使用道具 举报

🔗
碇真嗣 2015-4-7 05:30:17 | 只看该作者
全局:
表示我二面的时候也遇到了差不多的面试官。。是个棒子。。爱理不理的。。LZ后来有结果了吗?
回复

使用道具 举报

🔗
ppips 2015-4-7 07:34:33 | 只看该作者
全局:
haungge0385 发表于 2015-4-6 16:13
请问有大神贴一下tree iterator 的代码吗?烧香感谢。。。

请指正
  1. // Tree iterator (preorder)
  2. public static class BSTIterator {
  3.         TreeNode next;
  4.         Stack<TreeNode> stack;
  5.         public BSTIterator(TreeNode root) {
  6.                 next = root;
  7.                 stack = new Stack<TreeNode>();
  8.                 if (next != null)
  9.                         stack.push(next);
  10.                 next = stack.isEmpty() ? null : stack.pop();
  11.         }

  12.         /** [url=home.php?mod=space&uid=160137]@return[/url] whether we have a next smallest number */
  13.         public boolean hasNext() {
  14.                 return next != null;
  15.         }

  16.         /** @return the next smallest number */
  17.         public int next() {
  18.                 int res = next.val;
  19.                 if (next != null) {
  20.                         TreeNode n = next;
  21.                         if (n.right != null)
  22.                                 stack.push(n.right);
  23.                         if (n.left != null)
  24.                                 stack.push(n.left);
  25.                 }
  26.                 next = stack.isEmpty() ? null : stack.pop();
  27.                 return res;
  28.         }
  29. }
复制代码
回复

使用道具 举报

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

本版积分规则

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