일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- data science
- iterator
- 43. Multiply Strings
- 30. Substring with Concatenation of All Words
- 715. Range Module
- attribute
- concurrency
- Python Implementation
- Regular Expression
- shiba
- 컴퓨터의 구조
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- Protocol
- kaggle
- 운영체제
- DWG
- 프로그래머스
- 밴픽
- 시바견
- t1
- Class
- 파이썬
- LeetCode
- Decorator
- Convert Sorted List to Binary Search Tree
- 109. Convert Sorted List to Binary Search Tree
- Python Code
- Python
- Generator
Archives
- Today
- Total
Scribbling
[Java] 1481. Least Number of Unique Integers after K Removals 본문
Computer Science/Java
[Java] 1481. Least Number of Unique Integers after K Removals
focalpoint 2024. 2. 16. 21:06class Solution {
public int findLeastNumOfUniqueInts(int[] arr, int k) {
Map<Integer, Integer> counter = new HashMap<>();
for (int num : arr) {
counter.merge(num, 1, Integer::sum);
}
List<List<Integer>> list = new ArrayList<>();
for (Integer key : counter.keySet()) {
Integer val = counter.get(key);
List<Integer> tmp = new ArrayList<>();
tmp.add(val);
tmp.add(key);
list.add(tmp);
}
List<List<Integer>> sorted = list.stream().sorted((l1, l2) -> {
return l1.get(0) - l2.get(0);
}).toList();
int i = 0;
int total = 0;
while (i < sorted.size()) {
total += sorted.get(i).get(0);
if (total > k) break;
i++;
}
return sorted.size() - i;
}
}
'Computer Science > Java' 카테고리의 다른 글
[Java] LeetCode: 1606. Find Servers That Handled Most Number of Requests (0) | 2023.08.27 |
---|---|
[Java 101] 435. Non-overlapping Intervals - Comparator (0) | 2023.03.15 |
[Java 101] 211. Design Add and Search Words Data Structure - trie (0) | 2023.03.11 |
[Java101] Trie Implementation (0) | 2023.03.08 |
[Java 101] 102. Binary Tree Level Order Traversal - Queue (0) | 2023.03.04 |