Skip to content

Commit 002f9d7

Browse files
authored
Create TwoCityScheduling.cpp
1 parent 3b6054b commit 002f9d7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

TwoCityScheduling.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
static bool compr(vector<int> v1,vector<int> v2){
4+
return v1[0]-v1[1]<v2[0]-v2[1];
5+
}
6+
int twoCitySchedCost(vector<vector<int>>& costs) {
7+
sort(costs.begin(),costs.end(),compr);
8+
int ans=0;
9+
for(int i=0;i<costs.size()/2;i++){
10+
ans+=costs[i][0]+costs[i+costs.size()/2][1];
11+
}
12+
return ans;
13+
}
14+
};

0 commit comments

Comments
 (0)