Skip to content

Latest commit

 

History

History
14 lines (12 loc) · 302 Bytes

2656.md

File metadata and controls

14 lines (12 loc) · 302 Bytes

2656. Maximum Sum With Exactly K Elements

Solution 1 (time O(n), space O(1))

class Solution(object):
    def maximizeSum(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        return k * (2 * max(nums) + k - 1) // 2