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

GOOLE NYC

🔗
 楼主| zhengshuomm 2015-12-2 07:11:43 | 只看该作者
全局:
cancerlk 发表于 2015-12-2 01:30
楼主会有offer的。。。

楼主今天突然发现第搞了一个大bug
回复

使用道具 举报

🔗
 楼主| zhengshuomm 2015-12-2 07:12:25 | 只看该作者
全局:
bobzhang2004 发表于 2015-12-2 02:49
比赛那题暴力解是数学的计算?

我是暴力解法,相当与列出所有可能性了
回复

使用道具 举报

🔗
yjfox 2015-12-2 08:48:37 | 只看该作者
全局:
lz你的题多和数学有关,背景原因?
回复

使用道具 举报

🔗
 楼主| zhengshuomm 2015-12-2 09:07:38 | 只看该作者
全局:
yjfox 发表于 2015-12-2 08:48
lz你的题多和数学有关,背景原因?

大一上过高数吧。。。
回复

使用道具 举报

🔗
cancerlk 2015-12-2 09:18:59 | 只看该作者
全局:
zhengshuomm 发表于 2015-12-2 09:07
大一上过高数吧。。。

上过高数亮了 你越来越冷幽默!
回复

使用道具 举报

🔗
bobzhang2004 2015-12-11 11:34:34 | 只看该作者
全局:
请问第五题有哪位大神解答下吗?贴下二次方的code,有些复杂啊。。
  1. public class SortSortedArray {

  2.         public static void main(String[] args) {
  3.                 int[] arr = {-5, -3, -1, 0, 4, 9, 11, 13};
  4.                 int[] res = sortSortedArray(arr, -1, 2, 0);
  5.                 for (int i : res) {
  6.                         System.out.print(i + " ");
  7.                 }
  8.         }
  9.         public static int[] sortSortedArray(int[] arr, int a, int b, int c) {
  10.                 int pivot = -b / (2 * a);
  11.                 int[] res = new int[arr.length];
  12.                 int index = findPivot(arr, pivot);
  13.                 int left = index;
  14.                 int right = index + 1;
  15.                 boolean faceUp = true;
  16.                 if (a < 0) {
  17.                         faceUp = false;
  18.                 }
  19.                 int pos = 0;
  20.                 if (faceUp) {
  21.                         while (left >= 0 && right < arr.length) {
  22.                                 if (getResult(arr[left], a, b, c) > getResult(arr[right], a, b, c)) {
  23.                                         res[pos++] = getResult(arr[right], a, b, c);
  24.                                         right++;
  25.                                 } else {
  26.                                         res[pos++] = getResult(arr[left], a, b, c);
  27.                                         left--;
  28.                                 }
  29.                         }
  30.                         while (left >= 0) {
  31.                                 res[pos++] = getResult(arr[left], a, b, c);
  32.                                 left--;
  33.                         }
  34.                         while (right < arr.length) {
  35.                                 res[pos++] = getResult(arr[right], a, b, c);
  36.                                 right++;
  37.                         }
  38.                 } else {
  39.                         pos = res.length - 1;
  40.                         while (left >= 0 && right < arr.length) {
  41.                                 if (getResult(arr[left], a, b, c) > getResult(arr[right], a, b, c)) {
  42.                                         res[pos--] = getResult(arr[left], a, b, c);
  43.                                         left--;
  44.                                 } else {
  45.                                         res[pos--] = getResult(arr[right], a, b, c);
  46.                                         right++;
  47.                                 }
  48.                         }
  49.                         while (left >= 0) {
  50.                                 res[pos--] = getResult(arr[left], a, b, c);
  51.                                 left--;
  52.                         }
  53.                         while (right < arr.length) {
  54.                                 res[pos--] = getResult(arr[right], a, b, c);
  55.                                 right++;
  56.                         }
  57.                 }
  58.                 return res;
  59.         }

  60.         private static int getResult(int i, int a, int b, int c) {
  61.                 return a * i * i + b * i + c;
  62.         }

  63.         private static int findPivot(int[] arr, int pivot) {
  64.                 int start = 0;
  65.                 int end = arr.length - 1;
  66.                 while (start + 1 < end) {
  67.                         int mid = (end - start) / 2 + start;
  68.                         if (arr[mid] == pivot) {
  69.                                 return mid;
  70.                         } else if (arr[mid] > pivot) {
  71.                                 end = mid;
  72.                         } else {
  73.                                 start = mid;
  74.                         }
  75.                 }
  76.                 if (arr[end] <= pivot) {
  77.                         return end;
  78.                 } else {
  79.                         return start;
  80.                 }
  81.         }
  82. }
复制代码
回复

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

本版积分规则

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