注意:
总人数少于1100人。
示例
输入:
[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
输出:
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
public static void main(String[] args) { List<Person> personList = new ArrayList<>(); Person person = new Person(); person.setHeight(7); person.setNum(0); personList.add(person); person = new Person(); person.setHeight(4); person.setNum(4); personList.add(person); person = new Person(); person.setHeight(7); person.setNum(1); personList.add(person); person = new Person(); person.setHeight(5); person.setNum(0); personList.add(person); person = new Person(); person.setHeight(6); person.setNum(1); personList.add(person); person = new Person(); person.setHeight(5); person.setNum(2); personList.add(person); Collections.sort(personList, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { if(o1.getHeight() == o2.getHeight()){ return o1.getNum() - o2.getNum(); } return o2.getHeight() - o1.getHeight(); } }); List<Person> list = new LinkedList<>(); for (Person p : personList) { list.add(p.getNum(),p); } System.out.println(list); }
作者:A_Zeee
链接:https://www.jianshu.com/p/1faee3c9d630
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。