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 e315eae

Browse files
feat: add js solutions to lc problems: No.219,3163 (doocs#3716)
1 parent dbed118 commit e315eae

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} k
4+
* @return {boolean}
5+
*/
6+
var containsNearbyDuplicate = function(nums, k) {
7+
const d = new Map();
8+
for (let i = 0; i < nums.length; ++i) {
9+
if (d.has(nums[i]) && i - d.get(nums[i]) <= k) {
10+
return true;
11+
}
12+
d.set(nums[i], i);
13+
}
14+
return false;
15+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string} word
3+
* @return {string}
4+
*/
5+
var compressedString = function(word) {
6+
const ans = [];
7+
const n = word.length;
8+
for (let i = 0; i < n;) {
9+
let j = i + 1;
10+
while (j < n && word[j] === word[i]) {
11+
++j;
12+
}
13+
let k = j - i;
14+
while (k) {
15+
const x = Math.min(k, 9);
16+
ans.push(x + word[i]);
17+
k -= x;
18+
}
19+
i = j;
20+
}
21+
return ans.join('');
22+
};

0 commit comments

Comments
(0)

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