📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
楼主: theWANDERER
跳转到指定楼层
上一主题 下一主题
收起左侧

FB两轮面经

🔗
 楼主| theWANDERER 2016-4-3 10:15:28 | 只看该作者
全局:
honeyBear142857 发表于 2016-3-31 10:34
楼主的面试有什么update的消息了吗?

offer了,强运
回复

使用道具 举报

🔗
sealove999 2016-4-3 13:50:52 | 只看该作者
全局:
一面一
  1. public class Solution {
  2.   Integer nextVal(TreeNode root, int target) {
  3.     Integer ret = null; // if NA, return null
  4.     TreeNode p = root;
  5.     while (p != null && p.val != target) {
  6.       if (target < p.val) {
  7.         ret = p.val; // candidate
  8.         p = p.left;
  9.       } else if (p.val < target) {
  10.         p = p.right;
  11.       }
  12.     }
  13.     if (p != null) { // target found
  14.       for (TreeNode q = p.right; q != null; q = q.left) { // find the left in right subtree
  15.         ret = q.val;
  16.       }
  17.     }
  18.     return ret;
  19.   }

  20.   public static void main(String[] args) {
  21.     TreeNode tn1 = new TreeNode(1);
  22.     TreeNode tn2 = new TreeNode(2);
  23.     TreeNode tn3 = new TreeNode(3);
  24.     TreeNode tn4 = new TreeNode(4);
  25.     TreeNode tn5 = new TreeNode(5);
  26.     TreeNode tn6 = new TreeNode(6);
  27.     TreeNode tn7 = new TreeNode(7);
  28.     TreeNode tn8 = new TreeNode(8);
  29.     TreeNode tn9 = new TreeNode(9);
  30.     tn5.left = tn2;
  31.     tn5.right = tn8;
  32.     tn2.left = tn1;
  33.     tn2.right = tn4;
  34.     tn4.left = tn3;
  35.     tn8.left = tn7;
  36.     tn8.right = tn9;
  37.     tn7.left = tn6;

  38.     Solution s = new Solution();
  39.     System.out.println(s.nextVal(tn5, 4));
  40.     System.out.println(s.nextVal(tn5, 2));
  41.     System.out.println(s.nextVal(tn5, 8));
  42.     System.out.println(s.nextVal(tn5, 5));
  43.     System.out.println(s.nextVal(tn5, -1));
  44.     System.out.println(s.nextVal(tn5, 10));
  45.     return;
  46.   }
  47. }
复制代码
回复

使用道具 举报

🔗
sealove999 2016-4-3 13:51:12 | 只看该作者
全局:
一面二
  1. public class Solution {
  2.   TreeNode pre = null;
  3.   TreeNode head = null;

  4.   void inThreading(TreeNode root) {
  5.     if (root == null)
  6.       return;
  7.     inThreading(root.left);
  8.     if (head == null) {
  9.       head = root;
  10.     }
  11.     if (pre != null) {
  12.       pre.next = root;
  13.     }
  14.     pre = root;
  15.     inThreading(root.right);
  16.   }

  17.   public static void main(String[] args) {
  18.     TreeNode tn1 = new TreeNode(1);
  19.     TreeNode tn2 = new TreeNode(2);
  20.     TreeNode tn3 = new TreeNode(3);
  21.     TreeNode tn4 = new TreeNode(4);
  22.     TreeNode tn5 = new TreeNode(5);
  23.     TreeNode tn6 = new TreeNode(6);
  24.     TreeNode tn7 = new TreeNode(7);
  25.     TreeNode tn8 = new TreeNode(8);
  26.     TreeNode tn9 = new TreeNode(9);
  27.     tn5.left = tn2;
  28.     tn5.right = tn8;
  29.     tn2.left = tn1;
  30.     tn2.right = tn4;
  31.     tn4.left = tn3;
  32.     tn8.left = tn7;
  33.     tn8.right = tn9;
  34.     tn7.left = tn6;

  35.     Solution s = new Solution();
  36.     s.inThreading(tn5);
  37.     for (TreeNode p = s.head; p != null; p = p.next) {
  38.       System.out.println(p.val);
  39.     }
  40.     return;
  41.   }
  42. }
复制代码
回复

使用道具 举报

🔗
sealove999 2016-4-3 14:14:24 | 只看该作者
全局:
二面一
  1. public class Solution {
  2.   boolean validPalindrome(String s) {
  3.     int count = 0;
  4.     for (int i = 0; i < s.length(); i++) {
  5.       if (s.charAt(i) == '(') {
  6.         count++;
  7.       } else if (s.charAt(i) == ')') {
  8.         count--;
  9.         if (count < 0)
  10.           return false;
  11.       }
  12.     }
  13.     return count == 0;
  14.   }

  15.   public static void main(String[] args) {
  16.     Solution s = new Solution();
  17.     System.out.println(s.validPalindrome("((())(())"));
  18.     System.out.println(s.validPalindrome("((())(()))"));
  19.     return;
  20.   }
  21. }
复制代码
回复

使用道具 举报

🔗
sealove999 2016-4-3 14:14:43 | 只看该作者
全局:
二面二
  1. public class Solution {
  2.   int palindromic(String s, int i, int j) {
  3.     int ret = 0;
  4.     while (i - ret >= 0 && j + ret < s.length() && s.charAt(i - ret) == s.charAt(j + ret)) {
  5.       ret++;
  6.     }
  7.     return ret - 1;
  8.   }

  9.   Set<String> palindromicSubstring(String s) {
  10.     Set<String> ret = new HashSet<>();
  11.     for (int i = 0; i < s.length(); i++) {
  12.       int r = palindromic(s, i, i);
  13.       if (r > 0) {
  14.         ret.add(s.substring(i - r, i + r + 1));
  15.       }
  16.       if (i + 1 < s.length() && s.charAt(i) == s.charAt(i + 1)) { // make sure at least 1
  17.         r = palindromic(s, i, i + 1);
  18.         ret.add(s.substring(i - r, i + 1 + r + 1));
  19.       }
  20.     }
  21.     return ret;
  22.   }

  23.   public static void main(String[] args) {
  24.     Solution s = new Solution();
  25.     System.out.println(s.palindromicSubstring("aabba"));
  26.     System.out.println(s.palindromicSubstring("aabaabababa"));
  27.     return;
  28.   }
  29. }
复制代码
回复

使用道具 举报

🔗
sealove999 2016-4-3 14:23:13 | 只看该作者
全局:

刚才那个错了。。
  1. public class Solution {
  2.   void palindromic(String s, int i, int j, Set<String> ret) {
  3.     int count = 0;
  4.     while (i - count >= 0 && j + count < s.length() && s.charAt(i - count) == s.charAt(j + count)) {
  5.       if (j + count + 1 - (i - count) > 1) {
  6.         ret.add(s.substring(i - count, j + count + 1));
  7.       }
  8.       count++;
  9.     }
  10.   }

  11.   Set<String> palindromicSubstring(String s) {
  12.     Set<String> ret = new HashSet<>();
  13.     for (int i = 0; i < s.length(); i++) {
  14.       palindromic(s, i, i, ret);
  15.       palindromic(s, i, i + 1, ret);
  16.     }
  17.     return ret;
  18.   }

  19.   public static void main(String[] args) {
  20.     Solution s = new Solution();
  21.     System.out.println(s.palindromicSubstring("aabba"));
  22.     System.out.println(s.palindromicSubstring("aabaabababa"));
  23.     return;
  24.   }
  25. }
复制代码
回复

使用道具 举报

🔗
sealove999 2016-4-3 14:24:13 | 只看该作者
全局:

楼主好棒
回复

使用道具 举报

🔗
angryR 2016-11-19 04:22:18 | 只看该作者
全局:
freemail165 发表于 2016-3-27 22:50
这个比第二题难?
而且你说的放在vendor,岂不用了额外内存?

谢谢分享。请问你这个是不是假设了left child要比自己小?

我没理解楼主的这题,不是bst树是怎样的?
回复

使用道具 举报

🔗
MicX 2016-11-21 06:56:05 | 只看该作者
全局:
求问楼主palindrome那里要用到manchester吗?还是直接O(N^2)的找就可以了?
回复

使用道具 举报

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

本版积分规则

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