Home > Back-end >  : 2020-11-16 handwritten code: leetcode 406 items. Suppose you have the order of a group of people s
: 2020-11-16 handwritten code: leetcode 406 items. Suppose you have the order of a group of people s

Time:11-17

: 2020-11-16 handwritten code: leetcode 406 problem, suppose you have the order of a group of people standing in a queue, to everyone by an integer (h, k), said the h is the height of the man, k is row in front of the person and the height is greater than or equal to the number of h, write an algorithm to reconstruct the queue, # # f greatly architects a daily topic

CodePudding user response:

 
Public int [] [] reconstructQueue (int [] [] people) {
The Arrays. Sort (people, (o1, o2) - & gt; O1 [0]==o2 [0]? O2 o1 [1] - [1] : o2 [0] - o1 [0]);

LinkedList (a);
For (int [] I: people) {
List. The add (I [1], I);
}

The return list. ToArray (new int [list. The size (a)] [2]).
}

CodePudding user response:

reference 1st floor KeepSayingNo response:
 
Public int [] [] reconstructQueue (int [] [] people) {
The Arrays. Sort (people, (o1, o2) - & gt; O1 [0]==o2 [0]? O2 o1 [1] - [1] : o2 [0] - o1 [0]);

LinkedList (a);
For (int [] I: people) {
List. The add (I [1], I);
}

The return list. ToArray (new int [list. The size (a)] [2]).
}

Learning, the use of two-dimensional array + LinkedList