Skip to content

Commit 82de725

Browse files
committed
Create 1029-two-city-scheduling.rs
1 parent eaa9036 commit 82de725

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

1029-two-city-scheduling.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub fn two_city_sched_cost(costs: Vec<Vec<i32>>) -> i32 {
2+
let n = costs.len();
3+
let mut sorted_costs = costs.clone();
4+
sorted_costs.sort_by(|a, b|(a[0]-a[1]).cmp(&(b[0]-b[1])));
5+
&sorted_costs[0..n/2].iter().map(|e|e[0]).sum::<i32>() + &sorted_costs[n/2..].iter().map(|e|e[1]).sum::<i32>()
6+
}
7+
8+
fn main() {
9+
let costs = vec![[10,20],[30,200],[400,50],[30,20]].iter().map(|e|e.to_vec()).collect();
10+
println!("{:?}", two_city_sched_cost(costs));
11+
}

0 commit comments

Comments
 (0)