2448. Minimum Cost to Make Array Equal
You are given two 0-indexed arrays nums
and cost
consisting each of n
positive integers.
You can do the following operation any number of times:
nums
by 1
.The cost of doing one operation on the ith element is cost[i]
.
Return the minimum total cost such that all the elements of the array nums
become equal.
Example 1:
Example 2:
Constraints:
n
== nums.length
== cost.length
n
<= 105nums[i]
, cost[i]
<= 106Jerry Wu21 June, 2023
Yen-Chi ChenWed, Jun 21, 2023
本來一看到題目感覺跟2602很像,就嘗試sort + prefix sum再用binary search猜答案,結果一直錯,看答案抄別人的binary search解法。
MarsgoatWed, Jun 21, 2023