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

Google Onsite (Search Infra) MTV

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

使用道具 举报

🔗
jinzheyu 2015-11-15 11:33:55 | 只看该作者
全局:
楼主拿到HR提供的各个面试的feedback了吗?方便分享一下吗?谢谢。
回复

使用道具 举报

🔗
mmliu 2015-11-15 13:05:15 | 只看该作者
全局:
木有design? 不是说有经验的都会有一轮design么
回复

使用道具 举报

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

使用道具 举报

🔗
bobzhang2004 2015-12-8 04:06:19 | 只看该作者
全局:
snail_914 发表于 2015-9-15 19:23
如17楼所说 如果不能出现重复数字 那么candy解法就不行了。 不然的话, 之前忘了考虑0,同样以ididdi 为 ...

这个应该不对,不许是不同的数字, 123456这种
回复

使用道具 举报

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

使用道具 举报

🔗
bobzhang2004 2015-12-8 05:41:30 | 只看该作者
全局:
改了下,应该是对的
  1. public class LongestConsectiveIncreasingSequenceInBinaryTree {

  2.         static class TreeNode {
  3.                 TreeNode left;
  4.                 TreeNode right;
  5.                 int val;

  6.                 public TreeNode(int val) {
  7.                         this.val = val;
  8.                 }
  9.         }

  10.         static class ResultType {
  11.                 int increaseNum;
  12.                 int decreaseNum;

  13.                 public ResultType(int i, int d) {
  14.                         this.increaseNum = i;
  15.                         this.decreaseNum = d;
  16.                 }
  17.         }

  18.         private static int res = 0;

  19.         public static int getLongestConsectiveSequence(TreeNode root) {
  20.                 longestConsectiveSequence(root);
  21.                 return res;
  22.         }

  23.         public static ResultType longestConsectiveSequence(TreeNode root) {
  24.                 if (root == null) {
  25.                         return new ResultType(0, 0);
  26.                 }
  27.                 ResultType left = longestConsectiveSequence(root.left);
  28.                 ResultType right = longestConsectiveSequence(root.right);
  29.                 ResultType curRes = new ResultType(1, 1);
  30.                 if (root.left != null) {
  31.                         if (root.left.val > root.val) {
  32.                                 curRes.increaseNum = left.increaseNum + 1;
  33.                         } else if (root.left.val < root.val) {
  34.                                 curRes.decreaseNum = left.decreaseNum + 1;
  35.                         }
  36.                 }
  37.                 if (root.right != null) {
  38.                         if (root.right.val > root.val) {
  39.                                 curRes.increaseNum = Math.max(right.increaseNum + 1,
  40.                                                 curRes.increaseNum);
  41.                         } else if (root.right.val < root.val) {
  42.                                 curRes.decreaseNum = Math.max(right.decreaseNum + 1,
  43.                                                 curRes.decreaseNum);
  44.                         }
  45.                 }
  46.                 System.out.print("val " + root.val + " ");
  47.                 System.out.print(curRes.decreaseNum + " ");
  48.                 System.out.println(curRes.increaseNum + " ");
  49.                 int leftToRightInc = 1;
  50.                 int rightToLeftInc = 1;
  51.                 if (root.left != null) {
  52.                         if (root.left.val > root.val) {
  53.                                 rightToLeftInc += left.increaseNum; // 2
  54.                         } else if (root.left.val < root.val) {
  55.                                 leftToRightInc += left.decreaseNum; //0
  56.                         }
  57.                 }
  58.                 if (root.right != null) {
  59.                         if (root.right.val > root.val) {
  60.                                 leftToRightInc += right.increaseNum;
  61.                         } else if (root.right.val < root.val) {
  62.                                 rightToLeftInc += right.decreaseNum;
  63.                         }
  64.                 }
  65.                 res = Math.max(leftToRightInc, rightToLeftInc);
  66.                 return curRes;
  67.         }

  68.         public static void main(String[] args) {
  69.                 TreeNode root = new TreeNode(3);
  70.                 root.left = new TreeNode(2);
  71.                 root.right = new TreeNode(4);
  72.                 root.left.left = new TreeNode(2);
  73.                 root.left.right = new TreeNode(1);
  74.                 root.right.left = new TreeNode(6);
  75.                 System.out.println(getLongestConsectiveSequence(root));
  76.         }
  77. }
复制代码
回复

使用道具 举报

🔗
bobzhang2004 2015-12-8 06:02:07 | 只看该作者
全局:
pyemma 发表于 2015-9-17 04:26
树的那道题稍微写了一下,主要就是递归,然后去重的话就是把生成的树serialize了一下去比较,没想到什么更 ...

每次都去遍历一遍树并且clone一遍树和产生新的树没什么区别吧?
回复

使用道具 举报

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

本版积分规则

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