Skip to content

Commit 4266524

Browse files
authored
Update 2448-minimum-cost-to-make-array-equal.js
1 parent c64f9cd commit 4266524

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

2448-minimum-cost-to-make-array-equal.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ const minCost = function (nums, cost) {
88
let l = Math.min(...nums)
99
let r = Math.max(...nums)
1010

11-
let res = calc(l)
1211
while(l < r) {
1312
const mid = Math.floor((l + r) / 2)
1413
const v1 = calc(mid)
1514
const v2 = calc(mid + 1)
16-
res = Math.min(res, v1, v2)
1715
if(v1 < v2) {
1816
r = mid
1917
} else {
2018
l = mid + 1
2119
}
2220
}
2321

24-
return res
22+
return calc(l)
2523

2624
function calc(v) {
2725
let res = 0

0 commit comments

Comments
 (0)