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

狗家OA面经 12月果然有新题

🔗
 楼主| inhow 2018-12-7 14:58:34 | 只看该作者
全局:
64203221 发表于 2018-12-7 14:52
刚做完OA, 我发现题意好像是 有重复数字的话 跳 index最小的那个

这样嘛,感觉我没仔细看题目,那样看来我没凉啊哈哈哈哈哈哈
回复

使用道具 举报

🔗
 楼主| inhow 2018-12-7 15:03:49 | 只看该作者
全局:
LalalaX 发表于 2018-12-7 11:14
谢谢lZ分享。其实是怕烙印来看资料~哈哈哈

学到了学到了哈哈哈哈哈哈哈
回复

使用道具 举报

🔗
pengbomuzzy 2018-12-9 04:39:19 | 只看该作者
全局:
  1. class Solution {
  2.     // 第一题 给一个全是int的array A,可以选择从array的任何一个index开始跳往后跳。
  3.     // 记当前是第i次jump,如果i是奇数,需要跳到后面所有比当前数字大的数字中最小的一个的位置,如果i是偶数,就要跳到所有比当前数字小的中,数字最大的一个的位置。
  4.     // 求输出整个array中能跳到最后一位的数字有几个。
  5.     // 比如说[10,13,12,14,15], 只有14可以跳到15(第1次跳,是奇数,14后面只有15,且15>14,到达),以及15本身就在最后,所以输出2.
  6.     int num = 0;

  7.     public int findAll(int[] input) {
  8.         for(int i=0;i<input.length;i++){
  9.             findNumberOfJumps(input, i, i, true);
  10.         }
  11.         return num;
  12.     }

  13.     public void findNumberOfJumps(int[] input, int pivotIndex, int currIndex, boolean isOdd) {
  14.         if(currIndex >= input.length){
  15.             return;
  16.         }

  17.         if(currIndex==input.length-1){
  18.             num++;
  19.             return;
  20.         }

  21.         int index;
  22.         if(isOdd){
  23.             index = findSmallestOfLarge(input, pivotIndex, currIndex);
  24.         }else{
  25.             index = findLargestOfSmall(input, pivotIndex, currIndex);
  26.         }

  27.         if(index==-1){
  28.             return;
  29.         }

  30.         findNumberOfJumps(input, pivotIndex, index, !isOdd);

  31.     }

  32.     public int findSmallestOfLarge(int[] arr, int pivotIndex, int currIndex) {
  33.         int result = arr[pivotIndex];
  34.         int index = 0;
  35.         for(int i = currIndex+1; i<arr.length; i++) {
  36.             int elem = arr[i];
  37.             if(i == currIndex+1 && elem > result) {
  38.                 result = elem;
  39.                 index = i;
  40.                 continue;
  41.             }

  42.             if(elem > arr[pivotIndex] && elem < result){
  43.                 result = elem;
  44.                 index = 1;
  45.             }
  46.         }

  47.         return result == arr[pivotIndex] ? - 1 : index;
  48.     }

  49.     public int findLargestOfSmall(int[] arr, int pivotIndex, int currIndex) {
  50.         int result = arr[pivotIndex];
  51.         int index = 0;
  52.         for(int i = currIndex+1; i<arr.length; i++) {
  53.             int elem = arr[i];
  54.             if(i == currIndex+1 && elem < result) {
  55.                 result = elem;
  56.                 index = i;
  57.                 continue;
  58.             }

  59.             if(elem < arr[pivotIndex] && elem > result){
  60.                 result = elem;
  61.                 index = i;
  62.             }
  63.         }

  64.         return result == arr[pivotIndex] ? - 1 : index;
  65.     }
  66. }
复制代码

补充内容 (2018-12-9 04:40):
随手写了一下,求大神们指点。。。

补充内容 (2018-12-9 04:41):
应该还有特别简单的方法,求大神po下~
回复

使用道具 举报

🔗
balla2011 2018-12-12 08:53:04 | 只看该作者
全局:
lz请问下给你发据信的跟给你发oa的是同一个人么?多谢
回复

使用道具 举报

🔗
 楼主| inhow 2018-12-12 09:26:44 | 只看该作者
全局:
balla2011 发表于 2018-12-12 08:53
lz请问下给你发据信的跟给你发oa的是同一个人么?多谢

对的,就是那个对接的recruiter
回复

使用道具 举报

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

本版积分规则

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