更新拼多多

This commit is contained in:
xiongraorao 2018-08-19 23:19:31 +08:00
parent 475ef3bd63
commit ca83243104
5 changed files with 35 additions and 5 deletions

View File

@ -1,4 +1,4 @@
package com.raorao.interview.beike.t1;
package com.raorao.interview.beike;
import java.util.Arrays;
import java.util.Comparator;

View File

@ -1,4 +1,4 @@
package com.raorao.interview.beike.t1.t2;
package com.raorao.interview.beike.t2;
import java.util.Scanner;

View File

@ -1,4 +1,4 @@
package com.raorao.interview.beike.t1.t3;
package com.raorao.interview.beike.t3;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,5 +1,10 @@
package com.raorao.interview.bytedance;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;
/**
* .
*
@ -8,4 +13,9 @@ package com.raorao.interview.bytedance;
*/
public class Test {
public static void main(String[] args) {
ArrayList a;
LinkedList b;
Vector v;
}
}

View File

@ -1,18 +1,38 @@
package com.raorao.leetcode.q406;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 根据身高和序号重组队列.
*
* 题目描述一个学生用两个分量 (h, k) 描述h 表示身高k 表示排在前面的有 k 个学生的身高比他高或者和他一样高\
*
* 思路贪心算法为了在每次插入操作时不影响后续的操作身高较高的学生应该先做插入操作否则身高较小的学生原先正确插入第 k 个位置可能会变成第 k+1 个位置
*
* 身高降序k 值升序然后按排好序的顺序插入队列的第 k 个位置中
*
* @author Xiong Raorao
* @since 2018-08-17-15:22
*/
public class Solution {
public static void main(String[] args) {
int[][] input = new int[][] {{7, 0}, {4, 4}, {7, 1}, {5, 0}, {6, 1}, {5, 2}};
}
public int[][] reconstructQueue(int[][] people) {
return null;
public static int[][] reconstructQueue(int[][] people) {
if (people == null || people.length == 0 || people[0].length == 0) {
return new int[0][0];
}
Arrays.sort(people, (a, b) -> a[0] == b[0] ? a[1] - b[1] : b[0] - a[0]); //升序排列就是小的放前面大的放后面
List<int[]> queue = new ArrayList<>();
for (int[] p : people) {
queue.add(p[1], p);
}
return queue.toArray(new int[queue.size()][]);
}
}