https://leetcode.com/problems/maximum-sum-with-exactly-k-elements/description/
Maximum Sum With Exactly K Elements - LeetCode
Can you solve this real interview question? Maximum Sum With Exactly K Elements - You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score: 1. Select an e
leetcode.com
1
2
3
4
5
|
class Solution:
def maximizeSum(self, nums: List[int], k: int) -> int:
answer = max(nums)*k + (k-1)*k//2
return answer
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2716. Minimize String Length (0) | 2023.06.27 |
---|---|
leetcode 2710. Remove Trailing Zeros From a String (0) | 2023.06.26 |
leetcode 35. Search Insert Position (0) | 2023.06.26 |
leetcode 172. Factorial Trailing Zeroes (0) | 2023.06.26 |
leetcode 9. Palindrome Number (0) | 2023.06.26 |
댓글