From 46d953ba4e3ef7e184d4601d7e6e5de315e58a15 Mon Sep 17 00:00:00 2001 From: zhaocchen Date: Wed, 2 Jun 2021 14:50:32 +0800 Subject: [PATCH] feat: add typescript solution to lc problem: No.1876.Substrings of Size Three with Distinct Characters --- .../README.md | 17 +++++++++++++++++ .../README_EN.md | 16 ++++++++++++++++ .../Solution.ts | 11 +++++++++++ 3 files changed, 44 insertions(+) create mode 100644 solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.ts diff --git a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md index 40f2b65feae5c..6b46ec99b4ae5 100644 --- a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md +++ b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README.md @@ -81,6 +81,23 @@ class Solution { } ``` +### **TypeScript** + +```ts +function countGoodSubstrings(s: string): number { + const n: number = s.length; + let count: number = 0; + for (let i: number = 0; i < n - 2; ++i) { + let a: string = s.charAt(i), b: string = s.charAt(i + 1), c: string = s.charAt(i + 2); + if (a != b && a != c && b != c) { + ++count; + } + } + return count; +}; + +``` + ### **...** ``` diff --git a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md index 09b3615aa561f..767b1cdc09a36 100644 --- a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md +++ b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/README_EN.md @@ -71,6 +71,22 @@ class Solution { } ``` +### **TypeScript** + +```ts +function countGoodSubstrings(s: string): number { + const n: number = s.length; + let count: number = 0; + for (let i: number = 0; i < n - 2; ++i) { + let a: string = s.charAt(i), b: string = s.charAt(i + 1), c: string = s.charAt(i + 2); + if (a != b && a != c && b != c) { + ++count; + } + } + return count; +}; +``` + ### **...** ``` diff --git a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.ts b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.ts new file mode 100644 index 0000000000000..3d1d29fdc10fa --- /dev/null +++ b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.ts @@ -0,0 +1,11 @@ +function countGoodSubstrings(s: string): number { + const n: number = s.length; + let count: number = 0; + for (let i: number = 0; i < n - 2; ++i) { + let a: string = s.charAt(i), b: string = s.charAt(i + 1), c: string = s.charAt(i + 2); + if (a != b && a != c && b != c) { + ++count; + } + } + return count; +}; \ No newline at end of file