Skip to content

Commit d7d83e1

Browse files
committed
💀 [2448] JavaScript heap out of memory
1 parent 6273e1d commit d7d83e1

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

2448/my_solution.js

+44-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2448/solution.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number[]} cost
4+
* @return {number}
5+
*/
6+
const minCost = (nums, cost) => {
7+
let minCost = Infinity, diffList = [];
8+
9+
for (let i = 0; i < nums.length; i++) {
10+
let tmpList = [];
11+
for (let j = 0; j < nums.length; j++) {
12+
let curr = nums[i], comp = nums[j]
13+
if (i === j || curr === comp) continue;
14+
tmpList.push((curr > comp) ? curr - comp : comp - curr);
15+
}
16+
diffList.push(tmpList);
17+
}
18+
19+
let idx = 0;
20+
while (0 < diffList.length) {
21+
let curr = diffList.shift(), tmpCostList = [...cost], tmpCostCount = 0;
22+
tmpCostList.splice(idx, 1);
23+
24+
for (let i = 0; i < curr.length; i++) {
25+
tmpCostCount += curr[i] * tmpCostList[i];
26+
}
27+
28+
minCost = Math.min(minCost, tmpCostCount);
29+
idx++;
30+
}
31+
32+
return minCost;
33+
};

0 commit comments

Comments
 (0)