Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c233d3

Browse files
feat: update lc problems (doocs#3718)
1 parent 2e04c0f commit 8c233d3

File tree

12 files changed

+105
-7
lines changed

12 files changed

+105
-7
lines changed

‎solution/0200-0299/0219.Contains Duplicate II/README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean {
148148
}
149149
```
150150

151+
#### JavaScript
152+
153+
```js
154+
/**
155+
* @param {number[]} nums
156+
* @param {number} k
157+
* @return {boolean}
158+
*/
159+
var containsNearbyDuplicate = function (nums, k) {
160+
const d = new Map();
161+
for (let i = 0; i < nums.length; ++i) {
162+
if (d.has(nums[i]) && i - d.get(nums[i]) <= k) {
163+
return true;
164+
}
165+
d.set(nums[i], i);
166+
}
167+
return false;
168+
};
169+
```
170+
151171
#### C#
152172

153173
```cs

‎solution/0200-0299/0219.Contains Duplicate II/README_EN.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean {
147147
}
148148
```
149149

150+
#### JavaScript
151+
152+
```js
153+
/**
154+
* @param {number[]} nums
155+
* @param {number} k
156+
* @return {boolean}
157+
*/
158+
var containsNearbyDuplicate = function (nums, k) {
159+
const d = new Map();
160+
for (let i = 0; i < nums.length; ++i) {
161+
if (d.has(nums[i]) && i - d.get(nums[i]) <= k) {
162+
return true;
163+
}
164+
d.set(nums[i], i);
165+
}
166+
return false;
167+
};
168+
```
169+
150170
#### C#
151171

152172
```cs

‎solution/0200-0299/0219.Contains Duplicate II/Solution.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param {number} k
44
* @return {boolean}
55
*/
6-
var containsNearbyDuplicate = function(nums, k) {
6+
var containsNearbyDuplicate = function(nums, k) {
77
const d = new Map();
88
for (let i = 0; i < nums.length; ++i) {
99
if (d.has(nums[i]) && i - d.get(nums[i]) <= k) {

‎solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ comments: true
33
difficulty: 困难
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README.md
55
tags:
6+
-
67
- 数组
78
- 哈希表
89
- 数学

‎solution/2500-2599/2524.Maximum Frequency Score of a Subarray/README_EN.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ comments: true
33
difficulty: Hard
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2500-2599/2524.Maximum%20Frequency%20Score%20of%20a%20Subarray/README_EN.md
55
tags:
6+
- Stack
67
- Array
78
- Hash Table
89
- Math

‎solution/2600-2699/2685.Count the Number of Complete Components/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ source: 第 345 场周赛 Q4
77
tags:
88
- 深度优先搜索
99
- 广度优先搜索
10+
- 并查集
1011
-
1112
---
1213

‎solution/2600-2699/2685.Count the Number of Complete Components/README_EN.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ source: Weekly Contest 345 Q4
77
tags:
88
- Depth-First Search
99
- Breadth-First Search
10+
- Union Find
1011
- Graph
1112
---
1213

‎solution/3100-3199/3163.String Compression III/README.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,33 @@ function compressedString(word: string): string {
209209
}
210210
```
211211

212+
#### JavaScript
213+
214+
```js
215+
/**
216+
* @param {string} word
217+
* @return {string}
218+
*/
219+
var compressedString = function (word) {
220+
const ans = [];
221+
const n = word.length;
222+
for (let i = 0; i < n; ) {
223+
let j = i + 1;
224+
while (j < n && word[j] === word[i]) {
225+
++j;
226+
}
227+
let k = j - i;
228+
while (k) {
229+
const x = Math.min(k, 9);
230+
ans.push(x + word[i]);
231+
k -= x;
232+
}
233+
i = j;
234+
}
235+
return ans.join('');
236+
};
237+
```
238+
212239
<!-- tabs:end -->
213240

214241
<!-- solution:end -->

‎solution/3100-3199/3163.String Compression III/README_EN.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,33 @@ function compressedString(word: string): string {
205205
}
206206
```
207207

208+
#### JavaScript
209+
210+
```js
211+
/**
212+
* @param {string} word
213+
* @return {string}
214+
*/
215+
var compressedString = function (word) {
216+
const ans = [];
217+
const n = word.length;
218+
for (let i = 0; i < n; ) {
219+
let j = i + 1;
220+
while (j < n && word[j] === word[i]) {
221+
++j;
222+
}
223+
let k = j - i;
224+
while (k) {
225+
const x = Math.min(k, 9);
226+
ans.push(x + word[i]);
227+
k -= x;
228+
}
229+
i = j;
230+
}
231+
return ans.join('');
232+
};
233+
```
234+
208235
<!-- tabs:end -->
209236

210237
<!-- solution:end -->

‎solution/3100-3199/3163.String Compression III/Solution.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* @param {string} word
33
* @return {string}
44
*/
5-
var compressedString = function(word) {
5+
var compressedString = function(word) {
66
const ans = [];
77
const n = word.length;
8-
for (let i = 0; i < n;) {
8+
for (let i = 0; i < n;) {
99
let j = i + 1;
1010
while (j < n && word[j] === word[i]) {
1111
++j;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /