-
Notifications
You must be signed in to change notification settings - Fork 0
1029_TwoCityScheduling
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
int twoCitySchedCost(vector<vector<int>>& costs) {
int ret = 0, n = costs.size()/2;
vector<int> refund;
for(auto & cost:costs){
ret+=cost[0];
refund.push_back(cost[1] - cost[0]);
}
sort(refund.begin(), refund.end());
for(int i=0;i<n;++i) ret+=refund[i];
return ret;
}
};
- time complexity
O(nlogn)
- space complexity
O(n)
footer