diff --git a/solution/0200-0299/0219.Contains Duplicate II/README.md b/solution/0200-0299/0219.Contains Duplicate II/README.md index e52457fe70649..3d54404ef3563 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/README.md +++ b/solution/0200-0299/0219.Contains Duplicate II/README.md @@ -148,6 +148,26 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean { } ``` +#### JavaScript + +```js +/** + * @param {number[]} nums + * @param {number} k + * @return {boolean} + */ +var containsNearbyDuplicate = function (nums, k) { + const d = new Map(); + for (let i = 0; i < nums.length; ++i) { + if (d.has(nums[i]) && i - d.get(nums[i]) <= k) { + return true; + } + d.set(nums[i], i); + } + return false; +}; +``` + #### C# ```cs diff --git a/solution/0200-0299/0219.Contains Duplicate II/README_EN.md b/solution/0200-0299/0219.Contains Duplicate II/README_EN.md index 41cff32cb8e68..ec2180534edb0 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/README_EN.md +++ b/solution/0200-0299/0219.Contains Duplicate II/README_EN.md @@ -147,6 +147,26 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean { } ``` +#### JavaScript + +```js +/** + * @param {number[]} nums + * @param {number} k + * @return {boolean} + */ +var containsNearbyDuplicate = function (nums, k) { + const d = new Map(); + for (let i = 0; i < nums.length; ++i) { + if (d.has(nums[i]) && i - d.get(nums[i]) <= k) { + return true; + } + d.set(nums[i], i); + } + return false; +}; +``` + #### C# ```cs diff --git a/solution/0200-0299/0219.Contains Duplicate II/Solution.js b/solution/0200-0299/0219.Contains Duplicate II/Solution.js index bf68ed04ea3ec..031e7aa8894bf 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/Solution.js +++ b/solution/0200-0299/0219.Contains Duplicate II/Solution.js @@ -3,7 +3,7 @@ * @param {number} k * @return {boolean} */ -var containsNearbyDuplicate = function(nums, k) { +var containsNearbyDuplicate = function (nums, k) { const d = new Map(); for (let i = 0; i < nums.length; ++i) { if (d.has(nums[i]) && i - d.get(nums[i]) <= k) { diff --git a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md index 95e7e7b50593e..cdc97bf308dff 100644 --- a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md +++ b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md @@ -3,6 +3,7 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README.md tags: + - 栈 - 数组 - 哈希表 - 数学 diff --git a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md index 38e1bbc6239d3..0310abfee45d6 100644 --- a/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md +++ b/solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md @@ -3,6 +3,7 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README_EN.md tags: + - Stack - Array - Hash Table - Math diff --git a/solution/2600-2699/2685.Count the Number of Complete Components/README.md b/solution/2600-2699/2685.Count the Number of Complete Components/README.md index 893eaa6793605..ee26c911069af 100644 --- a/solution/2600-2699/2685.Count the Number of Complete Components/README.md +++ b/solution/2600-2699/2685.Count the Number of Complete Components/README.md @@ -7,6 +7,7 @@ source: 第 345 场周赛 Q4 tags: - 深度优先搜索 - 广度优先搜索 + - 并查集 - 图 --- diff --git a/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md b/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md index 0332511b38152..b107a866a0eab 100644 --- a/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md +++ b/solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md @@ -7,6 +7,7 @@ source: Weekly Contest 345 Q4 tags: - Depth-First Search - Breadth-First Search + - Union Find - Graph --- diff --git a/solution/3100-3199/3163.String Compression III/README.md b/solution/3100-3199/3163.String Compression III/README.md index 33d38e003cded..765e74956a2e5 100644 --- a/solution/3100-3199/3163.String Compression III/README.md +++ b/solution/3100-3199/3163.String Compression III/README.md @@ -209,6 +209,33 @@ function compressedString(word: string): string { } ``` +#### JavaScript + +```js +/** + * @param {string} word + * @return {string} + */ +var compressedString = function (word) { + const ans = []; + const n = word.length; + for (let i = 0; i < n; ) { + let j = i + 1; + while (j < n && word[j] === word[i]) { + ++j; + } + let k = j - i; + while (k) { + const x = Math.min(k, 9); + ans.push(x + word[i]); + k -= x; + } + i = j; + } + return ans.join(''); +}; +``` + diff --git a/solution/3100-3199/3163.String Compression III/README_EN.md b/solution/3100-3199/3163.String Compression III/README_EN.md index f903d2ca2c447..a01e2474f2a89 100644 --- a/solution/3100-3199/3163.String Compression III/README_EN.md +++ b/solution/3100-3199/3163.String Compression III/README_EN.md @@ -205,6 +205,33 @@ function compressedString(word: string): string { } ``` +#### JavaScript + +```js +/** + * @param {string} word + * @return {string} + */ +var compressedString = function (word) { + const ans = []; + const n = word.length; + for (let i = 0; i < n; ) { + let j = i + 1; + while (j < n && word[j] === word[i]) { + ++j; + } + let k = j - i; + while (k) { + const x = Math.min(k, 9); + ans.push(x + word[i]); + k -= x; + } + i = j; + } + return ans.join(''); +}; +``` + diff --git a/solution/3100-3199/3163.String Compression III/Solution.js b/solution/3100-3199/3163.String Compression III/Solution.js index 9b08e0d39f6fd..a6e675be71eb3 100644 --- a/solution/3100-3199/3163.String Compression III/Solution.js +++ b/solution/3100-3199/3163.String Compression III/Solution.js @@ -2,10 +2,10 @@ * @param {string} word * @return {string} */ -var compressedString = function(word) { +var compressedString = function (word) { const ans = []; const n = word.length; - for (let i = 0; i < n;) { + for (let i = 0; i < n; ) { let j = i + 1; while (j < n && word[j] === word[i]) { ++j; diff --git a/solution/README.md b/solution/README.md index 4e29eb4c172b4..f3dd02bf42898 100644 --- a/solution/README.md +++ b/solution/README.md @@ -2534,7 +2534,7 @@ | 2521 | [数组乘积中的不同质因数数目](/solution/2500-2599/2521.Distinct%20Prime%20Factors%20of%20Product%20of%20Array/README.md) | `数组`,`哈希表`,`数学`,`数论` | 中等 | 第 326 场周赛 | | 2522 | [将字符串分割成值不超过 K 的子字符串](/solution/2500-2599/2522.Partition%20String%20Into%20Substrings%20With%20Values%20at%20Most%20K/README.md) | `贪心`,`字符串`,`动态规划` | 中等 | 第 326 场周赛 | | 2523 | [范围内最接近的两个质数](/solution/2500-2599/2523.Closest%20Prime%20Numbers%20in%20Range/README.md) | `数学`,`数论` | 中等 | 第 326 场周赛 | -| 2524 | [子数组的最大频率分数](/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README.md) | `数组`,`哈希表`,`数学`,`滑动窗口` | 困难 | 🔒 | +| 2524 | [子数组的最大频率分数](/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README.md) | `栈`,`数组`,`哈希表`,`数学`,`滑动窗口` | 困难 | 🔒 | | 2525 | [根据规则将箱子分类](/solution/2500-2599/2525.Categorize%20Box%20According%20to%20Criteria/README.md) | `数学` | 简单 | 第 95 场双周赛 | | 2526 | [找到数据流中的连续整数](/solution/2500-2599/2526.Find%20Consecutive%20Integers%20from%20a%20Data%20Stream/README.md) | `设计`,`队列`,`哈希表`,`计数`,`数据流` | 中等 | 第 95 场双周赛 | | 2527 | [查询数组异或美丽值](/solution/2500-2599/2527.Find%20Xor-Beauty%20of%20Array/README.md) | `位运算`,`数组`,`数学` | 中等 | 第 95 场双周赛 | @@ -2695,7 +2695,7 @@ | 2682 | [找出转圈游戏输家](/solution/2600-2699/2682.Find%20the%20Losers%20of%20the%20Circular%20Game/README.md) | `数组`,`哈希表`,`模拟` | 简单 | 第 345 场周赛 | | 2683 | [相邻值的按位异或](/solution/2600-2699/2683.Neighboring%20Bitwise%20XOR/README.md) | `位运算`,`数组` | 中等 | 第 345 场周赛 | | 2684 | [矩阵中移动的最大次数](/solution/2600-2699/2684.Maximum%20Number%20of%20Moves%20in%20a%20Grid/README.md) | `数组`,`动态规划`,`矩阵` | 中等 | 第 345 场周赛 | -| 2685 | [统计完全连通分量的数量](/solution/2600-2699/2685.Count%20the%20Number%20of%20Complete%20Components/README.md) | `深度优先搜索`,`广度优先搜索`,`图` | 中等 | 第 345 场周赛 | +| 2685 | [统计完全连通分量的数量](/solution/2600-2699/2685.Count%20the%20Number%20of%20Complete%20Components/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集`,`图` | 中等 | 第 345 场周赛 | | 2686 | [即时食物配送 III](/solution/2600-2699/2686.Immediate%20Food%20Delivery%20III/README.md) | `数据库` | 中等 | 🔒 | | 2687 | [自行车的最后使用时间](/solution/2600-2699/2687.Bikes%20Last%20Time%20Used/README.md) | `数据库` | 简单 | 🔒 | | 2688 | [查找活跃用户](/solution/2600-2699/2688.Find%20Active%20Users/README.md) | `数据库` | 中等 | 🔒 | diff --git a/solution/README_EN.md b/solution/README_EN.md index 871f4f9731f5d..6e495fc3d19d6 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -2532,7 +2532,7 @@ Press Control + F(or Command + F on | 2521 | [Distinct Prime Factors of Product of Array](/solution/2500-2599/2521.Distinct%20Prime%20Factors%20of%20Product%20of%20Array/README_EN.md) | `Array`,`Hash Table`,`Math`,`Number Theory` | Medium | Weekly Contest 326 | | 2522 | [Partition String Into Substrings With Values at Most K](/solution/2500-2599/2522.Partition%20String%20Into%20Substrings%20With%20Values%20at%20Most%20K/README_EN.md) | `Greedy`,`String`,`Dynamic Programming` | Medium | Weekly Contest 326 | | 2523 | [Closest Prime Numbers in Range](/solution/2500-2599/2523.Closest%20Prime%20Numbers%20in%20Range/README_EN.md) | `Math`,`Number Theory` | Medium | Weekly Contest 326 | -| 2524 | [Maximum Frequency Score of a Subarray](/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README_EN.md) | `Array`,`Hash Table`,`Math`,`Sliding Window` | Hard | 🔒 | +| 2524 | [Maximum Frequency Score of a Subarray](/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README_EN.md) | `Stack`,`Array`,`Hash Table`,`Math`,`Sliding Window` | Hard | 🔒 | | 2525 | [Categorize Box According to Criteria](/solution/2500-2599/2525.Categorize%20Box%20According%20to%20Criteria/README_EN.md) | `Math` | Easy | Biweekly Contest 95 | | 2526 | [Find Consecutive Integers from a Data Stream](/solution/2500-2599/2526.Find%20Consecutive%20Integers%20from%20a%20Data%20Stream/README_EN.md) | `Design`,`Queue`,`Hash Table`,`Counting`,`Data Stream` | Medium | Biweekly Contest 95 | | 2527 | [Find Xor-Beauty of Array](/solution/2500-2599/2527.Find%20Xor-Beauty%20of%20Array/README_EN.md) | `Bit Manipulation`,`Array`,`Math` | Medium | Biweekly Contest 95 | @@ -2693,7 +2693,7 @@ Press Control + F(or Command + F on | 2682 | [Find the Losers of the Circular Game](/solution/2600-2699/2682.Find%20the%20Losers%20of%20the%20Circular%20Game/README_EN.md) | `Array`,`Hash Table`,`Simulation` | Easy | Weekly Contest 345 | | 2683 | [Neighboring Bitwise XOR](/solution/2600-2699/2683.Neighboring%20Bitwise%20XOR/README_EN.md) | `Bit Manipulation`,`Array` | Medium | Weekly Contest 345 | | 2684 | [Maximum Number of Moves in a Grid](/solution/2600-2699/2684.Maximum%20Number%20of%20Moves%20in%20a%20Grid/README_EN.md) | `Array`,`Dynamic Programming`,`Matrix` | Medium | Weekly Contest 345 | -| 2685 | [Count the Number of Complete Components](/solution/2600-2699/2685.Count%20the%20Number%20of%20Complete%20Components/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Graph` | Medium | Weekly Contest 345 | +| 2685 | [Count the Number of Complete Components](/solution/2600-2699/2685.Count%20the%20Number%20of%20Complete%20Components/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Union Find`,`Graph` | Medium | Weekly Contest 345 | | 2686 | [Immediate Food Delivery III](/solution/2600-2699/2686.Immediate%20Food%20Delivery%20III/README_EN.md) | `Database` | Medium | 🔒 | | 2687 | [Bikes Last Time Used](/solution/2600-2699/2687.Bikes%20Last%20Time%20Used/README_EN.md) | `Database` | Easy | 🔒 | | 2688 | [Find Active Users](/solution/2600-2699/2688.Find%20Active%20Users/README_EN.md) | `Database` | Medium | 🔒 |