Javascript solution with sort and in-place insert


  • 0
    R

    Javascript solution with sort and in-place insert, but it's too slow, any improvements?

    var reconstructQueue = function (people) {
        people.sort((x, y) => y[0] !== x[0] ? y[0] - x[0] : x[1] - y[1]);
        for (let i = 1; i < people.length; i++) {
            let man = people[i];
            people.splice(i, 1);
            people.splice(man[1], 0, man);
        }
        return people;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.