1710. Maximum Units on a Truck

Greedy

pick larger unit first, so sort by numberOfUnitsPerBoxi desc

ticky part is use left box number to gen the result (not like 背包問題, 只有一個包, 這裡有多個紙箱可以用, 所以可以用 貪心)

time: O(nlogn)

space: O(1)

Last updated

Was this helpful?