Skip to content

Commit a0f8841

Browse files
authored
feat: update ts solution to lc problem: No.1481 (#3191)
1 parent f5031fc commit a0f8841

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,11 @@ func findLeastNumOfUniqueInts(arr []int, k int) int {
160160
function findLeastNumOfUniqueInts(arr: number[], k: number): number {
161161
const cnt: Map<number, number> = new Map();
162162
for (const x of arr) {
163-
cnt.set(x, (cnt.get(x) || 0) + 1);
163+
cnt.set(x, (cnt.get(x) ?? 0) + 1);
164164
}
165-
const nums: number[] = [];
166-
for (const [_, v] of cnt) {
167-
nums.push(v);
168-
}
169-
nums.sort((a, b) => a - b);
165+
166+
const nums = [...cnt.values()].sort((a, b) => a - b);
167+
170168
for (let i = 0; i < nums.length; ++i) {
171169
k -= nums[i];
172170
if (k < 0) {

solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,11 @@ func findLeastNumOfUniqueInts(arr []int, k int) int {
174174
function findLeastNumOfUniqueInts(arr: number[], k: number): number {
175175
const cnt: Map<number, number> = new Map();
176176
for (const x of arr) {
177-
cnt.set(x, (cnt.get(x) || 0) + 1);
177+
cnt.set(x, (cnt.get(x) ?? 0) + 1);
178178
}
179-
const nums: number[] = [];
180-
for (const [_, v] of cnt) {
181-
nums.push(v);
182-
}
183-
nums.sort((a, b) => a - b);
179+
180+
const nums = [...cnt.values()].sort((a, b) => a - b);
181+
184182
for (let i = 0; i < nums.length; ++i) {
185183
k -= nums[i];
186184
if (k < 0) {

solution/1400-1499/1481.Least Number of Unique Integers after K Removals/Solution.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
function findLeastNumOfUniqueInts(arr: number[], k: number): number {
22
const cnt: Map<number, number> = new Map();
33
for (const x of arr) {
4-
cnt.set(x, (cnt.get(x) || 0) + 1);
4+
cnt.set(x, (cnt.get(x) ?? 0) + 1);
55
}
6-
const nums: number[] = [];
7-
for (const [_, v] of cnt) {
8-
nums.push(v);
9-
}
10-
nums.sort((a, b) => a - b);
6+
7+
const nums = [...cnt.values()].sort((a, b) => a - b);
8+
119
for (let i = 0; i < nums.length; ++i) {
1210
k -= nums[i];
1311
if (k < 0) {

0 commit comments

Comments
 (0)