Java O(n) with Priority Queue, over 98% beats

  • 0
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, new Comparator<int[]>() {
                public int compare(int[] o1, int[] o2) {
                    int res =[0], o1[0]);
                	if (res == 0){
                    	return[1], o2[1]);
                    else return res;
            ArrayList<int[]> queue = new ArrayList<int[]>();
            for (int[] person : people){
            	queue.add(person[1], person);
            return queue.toArray(new int[people.length][2]);

Log in to reply

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