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

新鲜出炉的谷歌面经

🔗
Neil_Acton 2015-11-23 00:42:55 | 只看该作者
全局:
第一题BFS才需要复制路径吧 用dfs time complexity 直接就是o(n)
回复

使用道具 举报

🔗
echo33 2015-11-23 01:59:06 | 只看该作者
全局:
lz你想太多了啦。。。。。。。。think quickly咋就讽刺你了,笑死我了,哈哈
回复

使用道具 举报

🔗
bobzhang2004 2015-12-5 00:31:03 | 只看该作者
全局:
写了下good number的代码,感觉不需要sort啊,和two sum一样,sort时间复杂度就是O(nlgn)了用hashset存就可以了时间复杂度是O(n),n是不同和的数量。
  1. public class GoodNumber {

  2.         public static void main(String[] args) {
  3.                 List<Integer> res = findNumber(10000);
  4.                 for (int i : res) {
  5.                         System.out.println(i);
  6.                 }
  7.         }
  8.        
  9.         public static List<Integer> findNumber(int n) {
  10.                 if (n <= 0) {
  11.                         return new ArrayList<Integer>();
  12.                 }
  13.                 List<Integer> candidates = new ArrayList<Integer>();
  14.                 for (int i = 1; Math.pow(i, 3) <= n; i++) {
  15.                         candidates.add((int)Math.pow(i, 3));
  16.                 }
  17.                 List<Integer> numbers = new ArrayList<Integer>();
  18.                 for (int i = 0; i < candidates.size(); i++) {
  19.                         for (int j = i + 1; j < candidates.size(); j++) {
  20.                                 numbers.add(candidates.get(i) + candidates.get(j));
  21.                         }
  22.                 }
  23.                 HashSet<Integer> set = new HashSet<Integer>();
  24.                 HashSet<Integer> res = new HashSet<Integer>();
  25.                 for (int num : numbers) {
  26.                         if (set.contains(num)) {
  27.                                 res.add(num);
  28.                         } else {
  29.                                 set.add(num);
  30.                         }
  31.                 }
  32.                
  33.                 return new ArrayList<Integer>(res);
  34.         }
  35. }
复制代码
回复

使用道具 举报

🔗
MCwong 2015-12-28 13:37:31 | 只看该作者
全局:
lz请问good number那题需不需要考虑负数? 91 =(-5)^3 + 6^3 = 3^3+4^3
回复

使用道具 举报

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

本版积分规则

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