public int[] maxDeletion(int[] nums, int[] res) {
        int last = nums.length - 1;
        for (int i = 1; i < nums.length; ++i) {
            res[res.length - i] = nums[1];
            nums[1] = nums[last];
            heapify(nums, --last);
        }
        return res;
    }