Easy Priority Queue Jav Solution

  • 0
    public class Solution {
        public String[] findRelativeRanks(int[] nums) {
        //Define Priority Queue in Reverse order  
       PriorityQueue<Integer> pq = new PriorityQueue<Integer>(nums.length,Collections.reverseOrder());
    	//Map to store the index ordering
                Map<Integer,Integer> map = new HashMap<Integer,Integer>();
    	String[] result = new String[nums.length];
    	//Add elements to the queue
    	for(int i=0;i<nums.length;i++){
    	//populate the map with the index
    	for(int i=0;i<nums.length;i++){
                //extract max and find the index in the map
    	for(int i=0;i<nums.length;i++){
    		int val = map.get(nums[i]);
    		if(val == 1)
    			result[i] = "Gold Medal";
    		else if(val == 2)
    			result[i] = "Silver Medal";
    		else if(val == 3)
    			result[i] = "Bronze Medal";
    	return result;

Log in to reply

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