Created
June 12, 2020 09:49
-
-
Save praneethreddymallupally/daf7841857cc45429ca5b5425cd7fd71 to your computer and use it in GitHub Desktop.
Data Structures and Algorithms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
static bool comparator(vector<int>& a,vector<int>& b) | |
{ | |
return a[1]-a[0] > b[1]-b[0]; | |
} | |
public: | |
int twoCitySchedCost(vector<vector<int>>& costs) { | |
int n = costs.size(); | |
sort(costs.begin(),costs.end(),comparator); | |
int ans = 0; | |
for(int i=0;i<n;++i) | |
ans += i>=n/2?costs[i][1]:costs[i][0]; | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment