My Simple Java Solution using Lambda Expression

  • 0
        public int[][] reconstructQueue(int[][] people) {
            Arrays.sort(people,(a,b)->a[0]>b[0]?1:(a[0]==b[0]?(a[1]<b[1]?1:-1):-1));//sort by people[0] asc , people[1] desc
            for(int i=people.length-1;i>=0;i--){
                int move = people[i][1];
                if(move>0){//move backward
                    for(int j=0;j<move;j++){
                        int[] tmp = people[j+i];
                        people[j+i] = people[j+i+1];
                        people[j+i+1] = tmp;
            return people;

Log in to reply

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