Advertisement
Guest User

Grokking 243-2

a guest
Dec 1st, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Solution {
  2. public int twoCitySchedCost(int[][] costs) {
  3. int minCost = 0;
  4. int[] refund = new int[costs.length];
  5.  
  6. for (int i = 0; i < costs.length; i++) {
  7. minCost += costs[i][0];
  8. refund[i] = costs[i][0] - costs[i][1];
  9. }
  10.  
  11. Arrays.sort(refund);
  12. int len = refund.length;
  13. int cnt = 0;
  14. while (cnt < len / 2) {
  15. minCost = minCost - refund[len - cnt - 1];
  16. cnt++;
  17. }
  18. return minCost;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement