From 0128f9cf320e0f32923e79c993899e87a709aca6 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Fri, 17 Mar 2023 22:20:41 +0800 Subject: [PATCH] feat: add solutions to lc problem: No.2269, No.0219 --- .../0219.Contains Duplicate II/README.md | 16 ++++++++++++++++ .../0219.Contains Duplicate II/README_EN.md | 16 ++++++++++++++++ .../0219.Contains Duplicate II/Solution.ts | 11 +++++++++++ .../2269.Find the K-Beauty of a Number/README.md | 12 +++++++++++- .../README_EN.md | 12 +++++++++++- .../Solution.ts | 11 +++++++++++ 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 solution/0200-0299/0219.Contains Duplicate II/Solution.ts create mode 100644 solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.ts diff --git a/solution/0200-0299/0219.Contains Duplicate II/README.md b/solution/0200-0299/0219.Contains Duplicate II/README.md index e8fad061947bb..e1c4d1da2e013 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/README.md +++ b/solution/0200-0299/0219.Contains Duplicate II/README.md @@ -142,6 +142,22 @@ public class Solution { } ``` +### **TypeScript** + +```ts +function containsNearbyDuplicate(nums: number[], k: number): boolean { + const map = new Map(); + for (let i = 0; i < nums.length; i++) { + const t = nums[i]; + if (map.has(t) && i - map.get(t) <= k) { + return true; + } + map.set(t, i); + } + return false; +} +``` + ### **...** ``` diff --git a/solution/0200-0299/0219.Contains Duplicate II/README_EN.md b/solution/0200-0299/0219.Contains Duplicate II/README_EN.md index 549b54f61041c..da7f1917466fb 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/README_EN.md +++ b/solution/0200-0299/0219.Contains Duplicate II/README_EN.md @@ -123,6 +123,22 @@ public class Solution { } ``` +### **TypeScript** + +```ts +function containsNearbyDuplicate(nums: number[], k: number): boolean { + const map = new Map(); + for (let i = 0; i < nums.length; i++) { + const t = nums[i]; + if (map.has(t) && i - map.get(t) <= k) { + return true; + } + map.set(t, i); + } + return false; +} +``` + ### **...** ``` diff --git a/solution/0200-0299/0219.Contains Duplicate II/Solution.ts b/solution/0200-0299/0219.Contains Duplicate II/Solution.ts new file mode 100644 index 0000000000000..bb08783ce1a17 --- /dev/null +++ b/solution/0200-0299/0219.Contains Duplicate II/Solution.ts @@ -0,0 +1,11 @@ +function containsNearbyDuplicate(nums: number[], k: number): boolean { + const map = new Map(); + for (let i = 0; i < nums.length; i++) { + const t = nums[i]; + if (map.has(t) && i - map.get(t) <= k) { + return true; + } + map.set(t, i); + } + return false; +} diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md b/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md index f3654e84a0080..ce749d02af392 100644 --- a/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/README.md @@ -138,7 +138,17 @@ func divisorSubstrings(num int, k int) int { ### **TypeScript** ```ts - +function divisorSubstrings(num: number, k: number): number { + let ans = 0; + const s = num.toString(); + for (let i = 0; i < s.length - k + 1; ++i) { + const t = parseInt(s.substring(i, i + k)); + if (t !== 0 && num % t === 0) { + ++ans; + } + } + return ans; +} ``` ### **...** diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md b/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md index 24bc37e56b14d..4a28a4b998347 100644 --- a/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/README_EN.md @@ -128,7 +128,17 @@ func divisorSubstrings(num int, k int) int { ### **TypeScript** ```ts - +function divisorSubstrings(num: number, k: number): number { + let ans = 0; + const s = num.toString(); + for (let i = 0; i < s.length - k + 1; ++i) { + const t = parseInt(s.substring(i, i + k)); + if (t !== 0 && num % t === 0) { + ++ans; + } + } + return ans; +} ``` ### **...** diff --git a/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.ts b/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.ts new file mode 100644 index 0000000000000..a33ac5f044726 --- /dev/null +++ b/solution/2200-2299/2269.Find the K-Beauty of a Number/Solution.ts @@ -0,0 +1,11 @@ +function divisorSubstrings(num: number, k: number): number { + let ans = 0; + const s = num.toString(); + for (let i = 0; i < s.length - k + 1; ++i) { + const t = parseInt(s.substring(i, i + k)); + if (t !== 0 && num % t === 0) { + ++ans; + } + } + return ans; +}