Skip to content

Commit 0824ec9

Browse files
committed
chore: update
1 parent 7c0a52b commit 0824ec9

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
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/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 -->

0 commit comments

Comments
 (0)