From 01da5d1376ea8b4c7fa70693573b2e25302e04a9 Mon Sep 17 00:00:00 2001 From: Subhadip Hensh <91666506+07subhadip@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:04:32 +0530 Subject: [PATCH 1/2] Create Solution.js --- .../3163.String Compression III/Solution.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 solution/3100-3199/3163.String Compression III/Solution.js diff --git a/solution/3100-3199/3163.String Compression III/Solution.js b/solution/3100-3199/3163.String Compression III/Solution.js new file mode 100644 index 0000000000000..9b08e0d39f6fd --- /dev/null +++ b/solution/3100-3199/3163.String Compression III/Solution.js @@ -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(''); +}; From d07ffafab86bdb29e8753dd569fba2f10a0357a1 Mon Sep 17 00:00:00 2001 From: Subhadip Hensh <91666506+07subhadip@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:23:02 +0530 Subject: [PATCH 2/2] Create Solution.js --- .../0219.Contains Duplicate II/Solution.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 solution/0200-0299/0219.Contains Duplicate II/Solution.js diff --git a/solution/0200-0299/0219.Contains Duplicate II/Solution.js b/solution/0200-0299/0219.Contains Duplicate II/Solution.js new file mode 100644 index 0000000000000..bf68ed04ea3ec --- /dev/null +++ b/solution/0200-0299/0219.Contains Duplicate II/Solution.js @@ -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; +};