📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
12
返回列表 发新帖
楼主: xialanxuan
跳转到指定楼层
上一主题 下一主题
收起左侧

ad组面经

🔗
aiwojiujiu 2017-4-25 02:56:41 | 只看该作者
全局:
感觉楼主用heap没毛病啊! 不然还用什么。。。
回复

使用道具 举报

🔗
 楼主| xialanxuan 2017-4-25 03:02:19 | 只看该作者
全局:
aiwojiujiu 发表于 2017-4-25 02:56
感觉楼主用heap没毛病啊! 不然还用什么。。。

他就说你把全部都放进去,时间太长了,叫我优化。还说你算node和friend的时候,friend是相互的,那你时间没有足够优化……
回复

使用道具 举报

🔗
小蝈蝈 2017-5-4 12:22:08 | 只看该作者
全局:
感谢楼主分享,第二题followup是说把程序改为线程安全的么,直接简单的加锁可以么?因为多线程不是很懂,写了一个不知道对不对,希望能给指点一下
  1. public class ImpQueue {
  2.         private int[] queue;
  3.         private int curSize = 0;
  4.         private int size;
  5.         private int head = 0;
  6.         private int tail = 0;
  7.        
  8.         public ImpQueue(int size) {
  9.                 queue = new int[size];
  10.                 this.size = size;
  11.         }
  12.        
  13.         public void offer(int value) throws Exception {
  14.                 synchronized(this) {
  15.                         if (curSize != size) {
  16.                                 queue[head] = value;
  17.                                 curSize++;
  18.                                 head++;
  19.                                 if (head == size) {
  20.                                         head = 0;
  21.                                 }
  22.                                 return;
  23.                         }
  24.                         throw new Exception("Queue is full");
  25.                 }
  26.         }
  27.        
  28.         public int poll() throws Exception{
  29.                 synchronized (this) {
  30.                         if (curSize != 0) {
  31.                                 int output = queue[tail];
  32.                                 curSize--;
  33.                                 Thread.sleep(100);
  34.                                 tail++;
  35.                                 if (tail == size) {
  36.                                         tail = 0;
  37.                                 }
  38.                                 return output;
  39.                         }
  40.                         throw new Exception("Queue is empty");
  41.                 }
  42.         }
  43. }
复制代码
回复

使用道具 举报

全局:
不知道为什么,觉得最后一题有一点像page rank,这个大牛博士能不能看看我的猜测。。。。。就像是一个网页的page rank 由所有链向它的页面的重要性决定, 一个人的危险值也是有和自己相关的朋友决定,而朋友之间也是相互决定的。找出三个最危险的人,就像是找出三个page rank最大的网站。。。
回复

使用道具 举报

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

本版积分规则

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