All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0401_0500.s0406_queue_reconstruction_by_height.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package g0401_0500.s0406_queue_reconstruction_by_height;

// #Medium #Array #Sorting #Greedy

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, (a, b) -> a[0] != b[0] ? -a[0] + b[0] : a[1] - b[1]);
        List res = new ArrayList<>();
        for (int[] a : people) {
            res.add(a[1], a);
        }
        return res.toArray(new int[people.length][]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy