LeetCode406. Queue Reconstruction by Height
来源:互联网 发布:淘宝购物车降价提醒 编辑:程序博客网 时间:2024/06/05 16:45
406. Queue Reconstruction by Height
让身高按照降序排列,高的在前面,同身高的情况下让要求前面人数人少的在前面
import java.util.List;import java.util.Arrays;import java.util.Comparator;import java.util.LinkedList;public class LeetCode406 { public int[][] reconstructQueue(int[][] people) { if(people.length == 0) return people; Arrays.sort(people, new Comparator<int[]>() { public int compare(int[] o1, int[] o2){ return o1[0] == o2[0]? o1[1] - o2[1] : o2[0] - o1[0]; } }); List<int[]> list = new LinkedList<>(); for(int[] cur : people){ list.add(cur[1], cur); //list.add(index,element)将element增加在指定位置index处 } return list.toArray(new int[people.length][2]); } }
0 0
- leetcode406. Queue Reconstruction by Height
- LeetCode406. Queue Reconstruction by Height
- LeetCode406. Queue Reconstruction by Height
- Leetcode406 Queue Reconstruction by Height
- leetcode406 Queue Reconstruction By Height java
- 26.leetCode406:Queue Reconstruction by Height
- python--leetcode406. Queue Reconstruction by Height
- LeetCode406. Queue Reconstruction by Height Add to List
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- Queue Reconstruction by Height
- c++ primer plus
- 使用spring遇到"BeanNotOfRequiredTypeException......but was actually of type [com.sun.proxy.$Proxy18]"异常
- Hello World
- 一步一步使用Unity3d工具实现AR开发入门
- JavaScript中对象的深拷贝
- LeetCode406. Queue Reconstruction by Height
- LeetCode : Majority Element
- 名单真相
- spring的IOC
- Android 退出多Activity的application的方式
- POJ3320:Jessica's Reading Problem(尺取法)
- JavaScript:获取url的querystring参数
- C陷阱与缺陷 读后笔记
- AsyncTask的详解与服务的结合下载文件例子