12
返回列表 发新帖
楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

脸书 电面 过经

🔗
collwe 2021-2-25 02:46:28 | 只看该作者
全局:
匿名者 发表于 2021-2-25 01:13
也不长。。。一年多sde,hr主动联系的,可能运气好吧。。

感谢大佬回复,我这边反正fb不给面,因为实习和part time的industry work都不给算work experience
回复

使用道具 举报

🔗
whiteboard 2021-3-10 02:42:42 | 只看该作者
全局:
第一题有0的情况写一个:

  1. class Solution {
  2. public:
  3.     vector<int> productExceptSelf(vector<int>& nums) {
  4.         int n = nums.size();
  5.         
  6.         vector<int> result(n, 0); //default all zero
  7.         int left_zero_idx = -1, right_zero_idx = -1;
  8.         int left = 1, right = 1;
  9.         
  10.         for (int i = 0; i < n; i++) {
  11.             if (nums[i] == 0) {
  12.                 left_zero_idx = i;
  13.                 break;
  14.             }
  15.             
  16.             left = left * nums[i];
  17.         }
  18.         
  19.         for (int i = n - 1; i >= 0; i--) {
  20.             if (nums[i] == 0) {
  21.                 right_zero_idx = i;
  22.                 break;
  23.             }
  24.             
  25.             right = right * nums[i];
  26.         }
  27.         
  28.         if (left_zero_idx != right_zero_idx) //two "0" found
  29.             return result;
  30.         
  31.         int total;
  32.         if (left_zero_idx != -1) //one "0" found
  33.             total = 0;
  34.         else
  35.             total = left; //no "0" found
  36.         
  37.         for (int i = 0; i < n; i++) {
  38.             if (nums[i] == 0) //If we come here, then we are sure there is only one "0"
  39.                 result[i] = left * right;
  40.             else
  41.                 result[i] = total / nums[i];
  42.         }
  43.         
  44.         return result;
  45.     }
  46. };
复制代码


回复

使用道具 举报

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

本版积分规则

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