diff --git a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md index 882fd0c11f691..a90f322df1d9d 100644 --- a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md +++ b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README.md @@ -160,13 +160,11 @@ func findLeastNumOfUniqueInts(arr []int, k int) int { function findLeastNumOfUniqueInts(arr: number[], k: number): number { const cnt: Map = new Map(); for (const x of arr) { - cnt.set(x, (cnt.get(x) || 0) + 1); + cnt.set(x, (cnt.get(x) ?? 0) + 1); } - const nums: number[] = []; - for (const [_, v] of cnt) { - nums.push(v); - } - nums.sort((a, b) => a - b); + + const nums = [...cnt.values()].sort((a, b) => a - b); + for (let i = 0; i < nums.length; ++i) { k -= nums[i]; if (k < 0) { diff --git a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md index ff98db3effecf..d367cf0458c18 100644 --- a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md +++ b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/README_EN.md @@ -174,13 +174,11 @@ func findLeastNumOfUniqueInts(arr []int, k int) int { function findLeastNumOfUniqueInts(arr: number[], k: number): number { const cnt: Map = new Map(); for (const x of arr) { - cnt.set(x, (cnt.get(x) || 0) + 1); + cnt.set(x, (cnt.get(x) ?? 0) + 1); } - const nums: number[] = []; - for (const [_, v] of cnt) { - nums.push(v); - } - nums.sort((a, b) => a - b); + + const nums = [...cnt.values()].sort((a, b) => a - b); + for (let i = 0; i < nums.length; ++i) { k -= nums[i]; if (k < 0) { diff --git a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/Solution.ts b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/Solution.ts index 66a3bbf45a1bf..875b7a67a8e62 100644 --- a/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/Solution.ts +++ b/solution/1400-1499/1481.Least Number of Unique Integers after K Removals/Solution.ts @@ -1,13 +1,11 @@ function findLeastNumOfUniqueInts(arr: number[], k: number): number { const cnt: Map = new Map(); for (const x of arr) { - cnt.set(x, (cnt.get(x) || 0) + 1); + cnt.set(x, (cnt.get(x) ?? 0) + 1); } - const nums: number[] = []; - for (const [_, v] of cnt) { - nums.push(v); - } - nums.sort((a, b) => a - b); + + const nums = [...cnt.values()].sort((a, b) => a - b); + for (let i = 0; i < nums.length; ++i) { k -= nums[i]; if (k < 0) {