파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 7. 1. 23:45

https://leetcode.com/problems/maximum-units-on-a-truck/

 

Maximum Units on a Truck - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

Easy 난이도라, 문제가 말하는대로 풀면 된다.
다만 sort 하는게 익숙치 않아서 ㅋㅋㅋㅋ 좀 걸렸음

class Solution:
    def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:
        boxTypes.sort(key=lambda x:(x[1]), reverse=True)
        res = 0
        for b in boxTypes:
            if truckSize - b[0] >= 0:
                res += b[1] * b[0]
                truckSize -= b[0]
            else:
                res += b[1] * (truckSize)
                break
        return res
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.07.03
Today's Challenge  (0) 2022.07.02
Today's Challenge  (0) 2022.06.30
Today's Challenge  (0) 2022.06.29
Today's Challenge  (0) 2022.06.28
Comments