Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- hash table
- bit manipulation
- SQL
- implement
- Data Structure
- greedy
- two pointers
- array
- Tree
- java
- 자바
- 코테
- Binary Search
- simulation
- Stack
- Class
- Matrix
- database
- Method
- dynamic programming
- geometry
- sorting
- 코딩테스트
- 구현
- Number Theory
- Counting
- Math
- 파이썬
- string
- Binary Tree
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2656. Maximum Sum With Exactly K Elements 본문
1. Input
1) int[] nums
2) int k
2. Output
1) 다음 과정을 k번 한 후에 나오는 점수 중 가장 큰 것을 반환
- nums에서 숫자를 하나 고른 후 nums에서 제거한다.
- 고른 숫자를 내 점수에 더한다.
- 고른 숫자보다 1 큰 수를 nums에 더한다.
3. Constraint
1) 1 <= nums.length <= 100
2) 1 <= nums[i] <= 100
3) 1 <= k <= 100
4. Example
Input: nums = [5,5,5], k = 2 -> Output: 11
설명:
- 1번째: 5를 고른다 -> 점수=5 -> nums = [5,5,6]
- 2번째: 6을 고른다 -> 점수=11 -> [5,5,7]
5. Code
1) 첫 코드(2023/05/08)
class Solution {
public int maximizeSum(int[] nums, int k) {
int max = 0;
for(int i=0 ; i<nums.length ; i++)
if(max<nums[i]) max = nums[i];
return k*(2*max+k-1)/2;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.1] 추억 점수 (0) | 2023.05.08 |
---|---|
[LeetCode/Easy] 2670. Find the Distinct Difference Array (0) | 2023.05.08 |
[LeetCode/Easy] 2652. Sum Multiples (0) | 2023.05.08 |
[LeetCode/Easy] 2651. Calculate Delayed Arrival Time (0) | 2023.05.08 |
[LeetCode/Easy] 2644. Find the Maximum Divisibility Score (0) | 2023.05.08 |