Simple Python Solution


  • 0
    R

    Simple naive python solution without list slicing:

    class Solution(object):
        def arrayPairSum(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            res = 0
            nums = sorted(nums)
            # Sum up nums[0], nums[2], nums[4].... 
            for i in range(0,len(nums)-1,2):
                res += nums[i]
            return res
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.