去哪儿java面试_《去哪儿》JAVA研发笔试+一面

背景不多说了,入正题,先说下笔试吧,研发岗位总共三道编程题,总的来说不是特别难,但要求要纸上写代码,所以写代码前先三思下,可以在试卷上写伪代码思路(答卷分开),后在答卷上写题,切记:一定别忘记注释。

笔试题:

一、部分有序旋转数组查找问题。

有一递增数组可向右移动,如:{1,2,3,4,5}向右移动后可为:{3,4,5,1,2},现在类似的数组中想找一个固定值,若存在则返回对应下标,若不存在则返回-1。需要考虑算法效率。

题解:很容易的就想到二分查找,是不是?但问题来了:数组有可能是由两部分递增的数组组成的,这样子就不能用二分查找法了。等等,这两部分有特别发现了没?数组第一个元素和最后一个比较,如果第一个比最后一个大,那么数组就是旋转了,此时很容易就想到先将原数组分割成两个递增数组再分别二分查找。

public int indexInTurnedArray(int[] array, int index) {//find out where the target int is

int tmp = -1;if(null == array || 0 == array.length) {//error input

tmp = -1;

}else{int bound = findArrayBound(array);//get the boundary of the array, which means the bigest one in array

if(index == array[bound]) {//the target int is the boundary

tmp = bound + 1;

}else{//the target int should in the left side of the boundary, or the right side//anyside should return the index of the array, else return -1//so, if none exist in both sides, the result will be -1//if the target is matc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值