首页 / 快手2020春招笔试
#
快手2020春招笔试
#1314次浏览 1人互动
此刻你想和大家分享什么
2020-04-12 18:11
哈尔滨工业大学 Java 2020快手笔试 4.12
Yasu0:第三题贪心
```
class Man implements Comparable<Man> {
int a;
int b;
int id;
int c;
public Man(int a, int b, int id, int c) {
this.a = a;
this.b = b;
this.id = id;
this.c = c;
}
@Override
public int compareTo(Man o) {
if (o.c == this.c)
return o.a - this.a;
return o.c - this.c;
}
}
/**
* 根据顾客属性计算出顾客排队顺序
*
* @param a int整型一维数组 顾客a属性
* @param b int整型一维数组 顾客b属性
* @return int整型一维数组
*/
public int[] WaitInLine(int[] a, int[] b) {
int len = a.length;
List<Man> l = new ArrayList<>();
for (int i = 0; i < len; i++)
l.add(new Man(a[i], b[i], i + 1, a[i] - b[i]));
Collections.sort(l);
int[] res = new int[len];
for (int i = 0; i < len; i++)
res[i] = l.get(i).id;
return res;
}
```

点赞 评论 收藏
分享