6 line java solution


  • 0
    3
        public int[][] reconstructQueue(int[][] people) {
            Arrays.sort(people, (p1, p2) -> p1[0] != p2[0] ? p2[0] - p1[0] : p1[1] - p2[1]);
            List<int[]> resultlist = new ArrayList<>();
            for (int[] p : people) {
                resultlist.add(p[1], p);
            }
            return resultlist.stream().toArray(int[][]::new);
        }
    
    

Log in to reply
 

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