From beac4eb5b192a5bc1ea5f43e532b926b694f565d Mon Sep 17 00:00:00 2001 From: rain84 Date: Mon, 17 Jun 2024 19:18:12 +0300 Subject: [PATCH] feat: add 2nd ts solution to lc problem: No.0633 --- .../0633.Sum of Square Numbers/README.md | 23 +++++++++++++++++++ .../0633.Sum of Square Numbers/README_EN.md | 23 +++++++++++++++++++ .../0633.Sum of Square Numbers/Solution2.ts | 8 +++++++ 3 files changed, 54 insertions(+) create mode 100644 solution/0600-0699/0633.Sum of Square Numbers/Solution2.ts diff --git a/solution/0600-0699/0633.Sum of Square Numbers/README.md b/solution/0600-0699/0633.Sum of Square Numbers/README.md index 83336bc2d3ce8..82a94564c56c3 100644 --- a/solution/0600-0699/0633.Sum of Square Numbers/README.md +++ b/solution/0600-0699/0633.Sum of Square Numbers/README.md @@ -193,4 +193,27 @@ impl Solution { + + +### Solution 2: Mathematics, "b" should always be an integer, if b = Root(c - a^2) + + + +#### TypeScript + +```ts +function judgeSquareSum(c: number): boolean { + for (let a = 0, inc = -1; a <= c; inc += 2, a += inc) { + const b = Math.sqrt(c - a); + if (b === (b | 0)) return true; + } + + return false; +} +``` + + + + + diff --git a/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md b/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md index 2fa651879c40f..90e98a9ba13f9 100644 --- a/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md +++ b/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md @@ -191,4 +191,27 @@ impl Solution { + + +### Solution 2: Mathematics, b should always be an integer, if b = Root(c - a^2) + + + +#### TypeScript + +```ts +function judgeSquareSum(c: number): boolean { + for (let a = 0, inc = -1; a <= c; inc += 2, a += inc) { + const b = Math.sqrt(c - a); + if (b === (b | 0)) return true; + } + + return false; +} +``` + + + + + diff --git a/solution/0600-0699/0633.Sum of Square Numbers/Solution2.ts b/solution/0600-0699/0633.Sum of Square Numbers/Solution2.ts new file mode 100644 index 0000000000000..b4f9e67cb01a6 --- /dev/null +++ b/solution/0600-0699/0633.Sum of Square Numbers/Solution2.ts @@ -0,0 +1,8 @@ +function judgeSquareSum(c: number): boolean { + for (let a = 0, inc = -1; a <= c; inc += 2, a += inc) { + const b = Math.sqrt(c - a); + if (b === (b | 0)) return true; + } + + return false; +}