10.11美团笔试 交流
第二题晋级人数,怎么改都是18,哪里有问题?
public static int furtherNum(int n,int x,int[] score){
Arrays.sort(score);//从小到大排序
//翻转
for (int i = 0; i < n / 2; i++) {
int temp = score[i];
score[i] = score[n - i - 1];
score[n - i - 1] = temp;
}
if (score[0] == 0) {
return 0;
}
int tmp = x;
//第x个人的分数为0
if (score[tmp - 1] == 0){
while (tmp - 1 >= 0 && score[tmp - 1] == 0){
tmp--;
}
}else {//第x个人的分数不为0,考虑后面的人同分情况
while (tmp < n && score[tmp] > 0) {
tmp++;
}
}
return tmp;
}
第三题思路是循环队列,但是没用过。。有没有大佬指点一下
#笔试题目##美团#