Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions solution/0200-0299/0219.Contains Duplicate II/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @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;
};
22 changes: 22 additions & 0 deletions solution/3100-3199/3163.String Compression III/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @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('');
};
Loading