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

新鲜出炉的谷歌面经

🔗
 楼主| iverson1122 2015-8-10 01:20:52 | 只看该作者
全局:
enirinth 发表于 2015-8-10 01:02
第二题LZ看这样是否正确:
1. 创建数组,存储所有 ≤n 的立方数,value = index^3, 一共m个(m = n^1/3) ...

应该是对的~ 复杂度也比较低
回复

使用道具 举报

🔗
zxy_snow 2015-8-10 19:34:46 | 只看该作者
全局:
handsomecool 发表于 2015-8-8 11:39
第二题为啥是2 sum?
首先得到小于n的立方数k个(k

比较赞同这个补充的解法。。
回复

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

🔗
UmassJin 2015-8-13 06:40:10 | 只看该作者
全局:
iverson1122 发表于 2015-8-13 03:11
复杂度上面有人回复了O(n^2/3)可以做出来。我面试的时候看错了,以为是判断某一个数是不是good number。 ...

明白了,在第二层的时候为O(m^2), m = n^1/3, 所以最后复杂度可以为O(n^2/3),谢谢楼主!
回复

使用道具 举报

🔗
qjx026 2015-8-19 22:40:36 | 只看该作者
全局:
Can't using Chinese on office laptop.
Do I misunderstand your question? LZ please tell me whether my code correct.
  1. public ArrayList<Integer> goodNum(int n){
  2.                 ArrayList<Integer> res = new ArrayList<Integer>();
  3.                 if(n < 2)
  4.                         return res;
  5.                 ArrayList<Integer> cubeArr = new ArrayList<Integer>();
  6.                 int index = 1;
  7.                 int num = (int) Math.pow(index, 3);
  8.                 while(num < n){
  9.                         num = (int) Math.pow(index, 3);
  10.                         cubeArr.add(num);
  11.                         index++;
  12.                 }
  13.                 //Add the sum of cubeNum into HashMap, and store how many time appear.
  14.                 HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
  15.                 for(int i = 0; i < cubeArr.size(); i++){
  16.                         for(int j = i; j < cubeArr.size(); j++){
  17.                                 int cubeSum = cubeArr.get(i) + cubeArr.get(j);
  18.                                 if(cubeSum <= n){
  19.                                         if(!map.containsKey(cubeSum)){
  20.                                                 map.put(cubeSum, 1);
  21.                                         }else{
  22.                                                 map.put(cubeSum, map.get(cubeSum) + 1);
  23.                                         }
  24.                                 }else{
  25.                                         break;
  26.                                 }
  27.                         }
  28.                 }
  29.                 //Traverse the hashmap to find sum num appear more than twice.
  30.                 Iterator<Integer> it = map.keySet().iterator();
  31.                 while(it.hasNext()){
  32.                         int key = (Integer) it.next();
  33.                         if(map.get(key) > 1){
  34.                                 res.add(key);
  35.                         }
  36.                 }
  37.                 return res;                       
  38.         }
复制代码
回复

使用道具 举报

🔗
totolin 2015-10-3 00:59:06 | 只看该作者
全局:
给个题2 python解, O(n^2/3)
  1. def goodnum2(n):
  2.     cubicroot = int(n**(1.0/3))
  3.     cubics = set([x**3 for x in range(1, cubicroot+1)])
  4.     cubic_sums = [p+q for p in cubics for q in cubics if p <= q]
  5.     cnt = Counter(cubic_sums)
  6.     return [key for key, val in cnt.items() if val > 1]
复制代码
n = 10000 -> [1729, 4104]
回复

使用道具 举报

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

本版积分规则

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