Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 466 Bytes

File metadata and controls

19 lines (16 loc) · 466 Bytes

LeetCode Records - Question 2656 Maximum Sum With Exactly K Elements

Attempt 1: Find the maximum integer first

class Solution {
    public int maximizeSum(int[] nums, int k) {
        int max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            max = Math.max(max, nums[i]);
        }

        return max * k + (k - 1) * k / 2;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 44.85 MB (Beats: 41.44%)