Simple java solution using priority queue


  • 0
    T
    public class Solution {
        public int[] sortTransformedArray(int[] nums, int a, int b, int c) {
            PriorityQueue<Integer> q = new PriorityQueue<>();
            for(int i = 0;i<nums.length;i++){
                nums[i] = (a*nums[i]*nums[i]) + (b*nums[i]) + c;
                q.offer(nums[i]);
            }
            int i = 0;
            while(!q.isEmpty()){
                nums[i++] = q.poll();
            }
            return nums;
        }
    }
    

Log in to reply
 

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