計數排序與greedy 2 pointer解Leetcode 1877 Minimize Maximum Pair Sum in Array 重點是理解為何Greedy方法可行,code很簡單,就排序sort, counting sort, radix sort都來一遍
-----
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))
沒有留言:
張貼留言
HTML 編輯器