From 959ae9525690171d92aaec0aad6102f2a535c6ec Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Thu, 17 Aug 2023 00:42:12 +0800 Subject: [PATCH] feat: add ts solution to lc problem: No.1433 --- .../README.md | 20 +++++++++++++++++++ .../README_EN.md | 20 +++++++++++++++++++ .../Solution.ts | 15 ++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 solution/1400-1499/1433.Check If a String Can Break Another String/Solution.ts diff --git a/solution/1400-1499/1433.Check If a String Can Break Another String/README.md b/solution/1400-1499/1433.Check If a String Can Break Another String/README.md index d99a15e7b2c7f..f7d5573907f0e 100644 --- a/solution/1400-1499/1433.Check If a String Can Break Another String/README.md +++ b/solution/1400-1499/1433.Check If a String Can Break Another String/README.md @@ -136,6 +136,26 @@ func checkIfCanBreak(s1 string, s2 string) bool { } ``` +### **TypeScript** + +```ts +function checkIfCanBreak(s1: string, s2: string): boolean { + const cs1: string[] = Array.from(s1); + const cs2: string[] = Array.from(s2); + cs1.sort(); + cs2.sort(); + const check = (cs1: string[], cs2: string[]) => { + for (let i = 0; i < cs1.length; i++) { + if (cs1[i] < cs2[i]) { + return false; + } + } + return true; + }; + return check(cs1, cs2) || check(cs2, cs1); +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md b/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md index 515a3704ecc9f..b18559d26567e 100644 --- a/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md +++ b/solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md @@ -123,6 +123,26 @@ func checkIfCanBreak(s1 string, s2 string) bool { } ``` +### **TypeScript** + +```ts +function checkIfCanBreak(s1: string, s2: string): boolean { + const cs1: string[] = Array.from(s1); + const cs2: string[] = Array.from(s2); + cs1.sort(); + cs2.sort(); + const check = (cs1: string[], cs2: string[]) => { + for (let i = 0; i < cs1.length; i++) { + if (cs1[i] < cs2[i]) { + return false; + } + } + return true; + }; + return check(cs1, cs2) || check(cs2, cs1); +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1433.Check If a String Can Break Another String/Solution.ts b/solution/1400-1499/1433.Check If a String Can Break Another String/Solution.ts new file mode 100644 index 0000000000000..888725ac34ab3 --- /dev/null +++ b/solution/1400-1499/1433.Check If a String Can Break Another String/Solution.ts @@ -0,0 +1,15 @@ +function checkIfCanBreak(s1: string, s2: string): boolean { + const cs1: string[] = Array.from(s1); + const cs2: string[] = Array.from(s2); + cs1.sort(); + cs2.sort(); + const check = (cs1: string[], cs2: string[]) => { + for (let i = 0; i < cs1.length; i++) { + if (cs1[i] < cs2[i]) { + return false; + } + } + return true; + }; + return check(cs1, cs2) || check(cs2, cs1); +}