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

herrDeng網內搜尋

自訂搜尋

Ads

2026年1月24日 星期六

計數排序與greedy 2 pointer解Leetcode 1877 Minimize Maximum Pair Sum in Array


計數排序與greedy 2 pointer解Leetcode 1877  Minimize Maximum Pair Sum in Array 重點是理解為何Greedy方法可行,code很簡單,就排序sort, counting sort, radix sort都來一遍
[Py3 一行解請進]
-----
Solving LeetCode 1877 Minimize Maximum Pair Sum in Array using counting sort and the Greedy 2-pointer problem. The key is understanding why the Greedy method works. The code itself is simple; it just tries sorting, counting sort, and radix sort.
class Solution:
    def minPairSum(self, nums: List[int]) -> int:
        return nums.sort() or max(nums[i]+nums[-1-i] for i in range((len(nums)>>1)+1))

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章