Skip to content

Commit 4ee8a9e

Browse files
authored
Update 1029-two-city-scheduling.js
1 parent 1461e42 commit 4ee8a9e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

1029-two-city-scheduling.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ const twoCitySchedCost = function(costs) {
2424

2525
// another
2626

27+
/**
28+
* @param {number[][]} costs
29+
* @return {number}
30+
*/
31+
const twoCitySchedCost = function(costs) {
32+
const N = costs.length
33+
let res = 0
34+
const refund = []
35+
for(let i = 0; i < N; i++) {
36+
refund[i] = costs[i][1] - costs[i][0]
37+
res += costs[i][0]
38+
}
39+
refund.sort((a, b) => a - b)
40+
for(let i = 0; i < N / 2; i++) {
41+
res += refund[i]
42+
}
43+
return res
44+
};
45+
46+
// another
47+
2748
/**
2849
* @param {number[][]} costs
2950
* @return {number}

0 commit comments

Comments
 (0)