Skip to content

Commit 4bb6541

Browse files
authored
Create 1029-two-city-scheduling.kt
1 parent e0af0f7 commit 4bb6541

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: kotlin/1029-two-city-scheduling.kt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun twoCitySchedCost(costs: Array<IntArray>): Int {
3+
val diffs = mutableListOf<IntArray>().apply {
4+
costs.forEach { (c1, c2) ->
5+
add(intArrayOf(c2 - c1, c1, c2))
6+
}
7+
}
8+
.sortedWith(compareBy { it[0] })
9+
10+
var res = 0
11+
val k = diffs.size / 2
12+
return diffs.withIndex()
13+
.sumBy { (i, a) -> if (i < k) a[2] else a[1] }
14+
}
15+
}

0 commit comments

Comments
 (0)