1029. Two City Scheduling
https://leetcode.com/problems/two-city-scheduling/
use greedy
ๅ ็บ้้่งๅฏ,
cost[0] - cost[1] ็่ฉฑ, ๆๆฏ -10, -170, 350, 10
ไปฃ่กจ่ถๅฐ็็ตๆ, ๆ่ฉฒๆดพๅป A, ๆๆๅฅฝ,
ๆฌ้ก่ชช่ฆไธๅ็ไบบๅป A ไธๅ็ๅป B, ๆไปฅ้้ๆๅบ cost[0] - cost[1] , ็ฑๅฐๅฐๅคง
ๅไธๅ็ไบบๅป A, ๅพไธๅ็ไบบๅป B , ๆๆฏๆไฝณ่งฃ!
O(nlogn), O(1)
dp ่งฃ
dp[i][j]
represents the cost when considering first (i + j)
people in which i
people assigned to city A and j
people assigned to city B.
O(n^2), O(n^2), N = costs.length / 2
Previous874. Walking Robot SimulationNext1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
Last updated