背景不多说了,入正题,先说下笔试吧,研发岗位总共三道编程题,总的来说不是特别难,但要求要纸上写代码,所以写代码前先三思下,可以在试卷上写伪代码思路(答卷分开),后在答卷上写题,切记:一定别忘记注释。
笔试题:
一、部分有序旋转数组查找问题。
有一递增数组可向右移动,如:{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