C++ Py3用nth_element, nsmallest解Leetcode 3010 Divide an Array Into Subarrays With Minimum Cost I
問題簡單,但應該是同類問題入門,先提供幾個簡易解答
[Py3一行解請進]
The question is simple, but it should be used as an introduction to similar questions. Here are a few simplified solutions.
>class Solution:
def minimumCost(self, nums: List[int]) -> int:
return nums[0]+sum(heapq.nsmallest(2, nums[1:]))
沒有留言:
張貼留言