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

Google 6.2电面

🔗
mingzhou1987 2016-6-3 12:38:51 | 只看该作者
全局:
stack的话恐怕不行吧,比如1,3,2插入顺序,stack top holds 3, erase 3后,stack top是1而不是2啊,不知道理解对不对。。
回复

使用道具 举报

🔗
huai10 2016-6-3 12:39:28 | 只看该作者
全局:
wzy0791 发表于 2016-6-3 11:58
用一个HashMap和一个Stack做应该可行啊

补充内容 (2016-6-3 12:29):

用PriorityQueue update很慢啊
回复

使用道具 举报

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

使用道具 举报

🔗
1peter 2016-6-3 12:59:26 | 只看该作者
全局:
huai10 发表于 2016-6-3 12:34
quad tree, 突然感觉cs225 学好了面试无敌啊

quadtree对于找max value的帮助在哪里呢?
回复

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

🔗
readman 2016-6-3 22:05:32 | 只看该作者
全局:
handsomecool 发表于 2016-6-3 16:19
楼主不是用的bst么? bst update是O(logN), getMax和getMin都可以O(1)吧,直接set.begin() / set.rbegin( ...

这个?
  1. import java.util.*;

  2. public class Grid {
  3.     public Grid(){}
  4.     int height;
  5.     int width;
  6.     Map<Integer, Integer> map;// index -> value
  7.     TreeMap<Integer, Set<Integer>> max; // max -> index array
  8.     public Grid(int height, int width){
  9.         this.height = height;
  10.         this.width = width;
  11.         map = new HashMap<>();
  12.         max  = new TreeMap<>();
  13.     }

  14.     public void set(int height, int width, int value) {
  15.         int index = setIndex(height, width);
  16.         if (map.containsKey(index)){
  17.             int oldValue = map.get(index); // get old value
  18.             Set oldValueSet = max.get(oldValue);
  19.             oldValueSet.remove(index);
  20.             if (oldValueSet.size()==0)
  21.                 max.remove(oldValue);
  22.             if (max.containsKey(value))
  23.                 max.get(value).add(index);
  24.             else
  25.                 max.computeIfAbsent(value, k->{
  26.                     Set set = new HashSet<Integer>();
  27.                     set.add(index);
  28.                     return set;
  29.                 });
  30.         }
  31.         else {
  32.             max.computeIfAbsent(value, k->{
  33.                 Set set = new HashSet<Integer>();
  34.                 set.add(index);
  35.                 return set;
  36.             });
  37.         }
  38.         map.put(index,value);
  39.     }

  40.     public int setIndex(int height, int width){
  41.         return  height * this.height + width;
  42.     }
  43.     public int getMax(){
  44.         return max.lastKey();
  45.     }

  46.     public static void main(String[] args) {
  47.         Grid grid = new Grid(5,5);
  48.         grid.set(1,1,5);
  49.         grid.set(2,2,10);
  50.         grid.set(3,3,10);
  51.         grid.set(4,4,15);
  52.         System.out.println(grid.getMax());    //15
  53.         grid.set(4,4,20);
  54.         System.out.println(grid.getMax());    //20
  55.         grid.set(4,4,15);
  56.         System.out.println(grid.getMax());    //15
  57.         grid.set(4,4,5);
  58.         grid.set(3,3,5);
  59.         System.out.println(grid.getMax());    //10
  60.         grid.set(1,1,50);
  61.         System.out.println(grid.getMax());    //50
  62.         grid.set(1,1,0);
  63.         grid.set(2,2,0);
  64.         grid.set(3,3,0);
  65.         grid.set(4,4,0);
  66.         System.out.println(grid.getMax());    //0
  67.     }
  68. }
复制代码
回复

使用道具 举报

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

本版积分规则

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