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

狗家淀面

🔗
congzi 2018-9-27 04:20:20 | 只看该作者
全局:
感谢楼主分享
回复

使用道具 举报

🔗
pxpxpxpx 2018-9-27 04:54:52 | 只看该作者
全局:
想问一下过了OA之后什么时候有消息会约电面或者是给拒信?
回复

使用道具 举报

🔗
 楼主| qianlizimu 2018-9-27 05:15:45 | 只看该作者
全局:
piggy1228 发表于 2018-9-27 04:54
想问一下过了OA之后什么时候有消息会约电面或者是给拒信?

每个人不一样,我大概是过了一周
回复

使用道具 举报

🔗
pxpxpxpx 2018-9-27 05:17:39 | 只看该作者
全局:
qianlizimu 发表于 2018-9-27 05:15
每个人不一样,我大概是过了一周

好的谢谢!因为我前两天收到一个调查问卷问我什么时候有空phone interview,结果到现在也没消息
回复

使用道具 举报

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

使用道具 举报

🔗
YZeng 2018-11-15 11:55:38 | 只看该作者
全局:

  1. import java.util.*;

  2. public class removeNodes {

  3.     static class Node {
  4.         int val;
  5.         Node left;
  6.         Node right;
  7.         boolean toRemove;
  8.         public Node(int val) {
  9.             this.val = val;
  10.         }
  11.     }

  12.     public static void main(String[] args) {


  13.         Node n1 = new Node(1);
  14.         Node n2 = new Node(2);
  15.         Node n3 = new Node(3);
  16.         Node n4 = new Node(4);
  17.         Node n5 = new Node(5);
  18.         Node n6 = new Node(6);
  19.         Node n7 = new Node(7);

  20.         n1.left = n2;
  21.         n1.right = n3;
  22.         n2.left = n4;
  23.         n2.right = n5;
  24.         n3.left = n6;
  25.         n3.right = n7;
  26.         n1.toRemove = true;
  27.         n2.toRemove = true;
  28.         n6.toRemove = true;

  29.         List<Node> list = removeNodes(n1);
  30.         for (Node n : list) {
  31.             print(n);
  32.         }
  33.     }

  34.     private static void print(Node root) {
  35.         System.out.println("===");
  36.         Deque<Node> q = new LinkedList<>();
  37.         q.offer(root);
  38.         while (!q.isEmpty()) {
  39.             int size = q.size();
  40.             while (size-- > 0) {
  41.                 Node cur = q.poll();
  42.                 if (cur == null) {
  43.                     System.out.print("#");
  44.                 } else {
  45.                     System.out.print(cur.val);
  46.                     q.offer(cur.left);
  47.                     q.offer(cur.right);
  48.                 }
  49.             }
  50.             System.out.println();
  51.         }
  52.         System.out.println("===");
  53.     }

  54.     private static List<Node> removeNodes(Node root) {
  55.         List<Node> res = new ArrayList<>();
  56.         if (root == null) {
  57.             return res;
  58.         }

  59.         List<Node> left = removeNodes(root.left);
  60.         List<Node> right = removeNodes(root.right);

  61.         if (!root.toRemove) {
  62.             res.add(root);
  63.         }

  64.         if (root.left != null && root.left.toRemove) {
  65.             root.left = null;
  66.         }
  67.         if (root.right != null && root.right.toRemove) {
  68.             root.right = null;
  69.         }

  70.         res.addAll(left);
  71.         res.addAll(right);
  72.         return res;
  73.     }

  74.     private static void helper(List<Node> res, Node root) {
  75.         if (root == null) {
  76.             return;
  77.         }

  78.         if (root.toRemove) {
  79.             helper(res, root.left);
  80.             helper(res, root.right);
  81.         } else {

  82.         }
  83.     }
  84. }
复制代码

补充内容 (2018-11-15 11:56):
请忽略helper函数
回复

使用道具 举报

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

使用道具 举报

🔗
YZeng 2018-11-15 12:08:00 | 只看该作者
全局:
  1.     static List<Node> res;
  2.     private static List<Node> removeNodes(Node root) {
  3.         res = new ArrayList<>();
  4.         helper(root, null);
  5.         return res;
  6.     }

  7.     private static void helper(Node root, Node parent) {
  8.         if (root == null) {
  9.             return;
  10.         }

  11.         if ((parent == null || parent.toRemove) && !root.toRemove) {
  12.             res.add(root);
  13.         }


  14.         helper(root.left, root);
  15.         helper(root.right, root);

  16.         if (root.left != null && root.left.toRemove) {
  17.             root.left = null;
  18.         }
  19.         if (root.right != null && root.right.toRemove) {
  20.             root.right = null;
  21.         }
  22.     }
复制代码


这样应该是可以的。。。
回复

使用道具 举报

🔗
hlckl123456 2018-11-16 01:59:31 | 只看该作者
全局:

定义了一个全局变量res
一个boolean 变量来判断是root,还是非root
是root的话我们就要加入array,不是root的话 就正常遍历
  1. def get_forest(self, node):
  2.         if node is None:
  3.                 return []
  4.         res = []
  5.         self.helper(node, res, True)
  6.         return res

  7. def helper(self, node, res, is_root):
  8.         if node is None:
  9.                 return None

  10.         if shouldBeErased(root):
  11.                 if node.left:
  12.                         self.helper(node.left, res, True)
  13.                 if node.right:
  14.                         self.helper(node.right, res, True)

  15.         if not shouldBeErased(root):
  16.                 if is_root:
  17.                         res.append(node)
  18.                 if node.left:
  19.                         node.left = self.helper(node.left, res, False)
  20.                 if node.right:
  21.                         node.right = self.helper(node.right, res, False)
复制代码
回复

使用道具 举报

🔗
雨雪霏霏 2018-11-27 08:11:10 | 只看该作者
全局:
我用isLeft判断如果当前节点要被删除 它的parent是要删左还是右
不知道有没有问题请各位看一眼~

  1. List<Node> res = new LinkedList<Node>;
  2. public List<Node> nodesAfterRemove(Node root) {
  3.         dfs(root, null, true);
  4.         return res;
  5. }

  6. private void dfs(Node root, Node parent, boolean isLeft) {
  7.         if (root == null) return;

  8.         if (parent == null || willRemove(parent)) {
  9.         if (!willRemove(root)l) {
  10.         res.add(root);
  11. }
  12. }

  13. dfs(root.left, root, true);
  14. dfs(root.right, root, false);
  15. if (willRemove(root) && parent != null) {
  16.         if (isLeft) parent.left = null;
  17.         else parent.right = null;
  18. }
  19. return;
  20. }
复制代码
回复

使用道具 举报

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

本版积分规则

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