/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2026年2月1日 星期日

C++ Py3用nth_element, nsmallest解Leetcode 3010 Divide an Array Into Subar...


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:]))
 

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章