From 128e9fe13ba4bf76b906583a220f3bcc178450ef Mon Sep 17 00:00:00 2001 From: Shubham Patrick Date: Tue, 11 Jul 2023 01:51:39 +0530 Subject: [PATCH 1/2] 1822 - Sign of the Product of an Array --- javascript/1822-sign-of-the-product-of-an-array.js | 10 ++++++++++ python/1822-sign-of-the-product-of-an-array.py | 14 ++++++++++++++ typescript/1822-sign-of-the-product-of-an-array.ts | 10 ++++++++++ 3 files changed, 34 insertions(+) create mode 100644 javascript/1822-sign-of-the-product-of-an-array.js create mode 100644 python/1822-sign-of-the-product-of-an-array.py create mode 100644 typescript/1822-sign-of-the-product-of-an-array.ts diff --git a/javascript/1822-sign-of-the-product-of-an-array.js b/javascript/1822-sign-of-the-product-of-an-array.js new file mode 100644 index 000000000..e2cfe9eea --- /dev/null +++ b/javascript/1822-sign-of-the-product-of-an-array.js @@ -0,0 +1,10 @@ +const arraySign = function (nums) { + let sign = 1; + + for (const num of nums) { + if (num == 0) return 0; + else if (num < 0) sign = -1 * sign; + } + + return sign; +}; diff --git a/python/1822-sign-of-the-product-of-an-array.py b/python/1822-sign-of-the-product-of-an-array.py new file mode 100644 index 000000000..1c059573a --- /dev/null +++ b/python/1822-sign-of-the-product-of-an-array.py @@ -0,0 +1,14 @@ +from typing import List + + +class Solution: + def arraySign(self, nums: List[int]) -> int: + sign = 1 + + for num in nums: + if num == 0: + return 0 + elif num < 0: + sign = -1 * sign + + return sign diff --git a/typescript/1822-sign-of-the-product-of-an-array.ts b/typescript/1822-sign-of-the-product-of-an-array.ts new file mode 100644 index 000000000..8a0146d8c --- /dev/null +++ b/typescript/1822-sign-of-the-product-of-an-array.ts @@ -0,0 +1,10 @@ +function arraySign(nums: number[]): number { + let sign = 1; + + for (const num of nums) { + if (num == 0) return 0; + else if (num < 0) sign = -1 * sign; + } + + return sign; +} From c35127b230452c9dd62248b8d9587d9087dbcf21 Mon Sep 17 00:00:00 2001 From: Shubham Patrick Date: Tue, 11 Jul 2023 02:08:01 +0530 Subject: [PATCH 2/2] Update: 1822 - Sign of the Product of an Array --- javascript/1822-sign-of-the-product-of-an-array.js | 2 +- python/1822-sign-of-the-product-of-an-array.py | 2 +- typescript/1822-sign-of-the-product-of-an-array.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/javascript/1822-sign-of-the-product-of-an-array.js b/javascript/1822-sign-of-the-product-of-an-array.js index e2cfe9eea..95607d3bd 100644 --- a/javascript/1822-sign-of-the-product-of-an-array.js +++ b/javascript/1822-sign-of-the-product-of-an-array.js @@ -3,7 +3,7 @@ const arraySign = function (nums) { for (const num of nums) { if (num == 0) return 0; - else if (num < 0) sign = -1 * sign; + if (num < 0) sign = -1 * sign; } return sign; diff --git a/python/1822-sign-of-the-product-of-an-array.py b/python/1822-sign-of-the-product-of-an-array.py index 1c059573a..4ec193faa 100644 --- a/python/1822-sign-of-the-product-of-an-array.py +++ b/python/1822-sign-of-the-product-of-an-array.py @@ -8,7 +8,7 @@ def arraySign(self, nums: List[int]) -> int: for num in nums: if num == 0: return 0 - elif num < 0: + if num < 0: sign = -1 * sign return sign diff --git a/typescript/1822-sign-of-the-product-of-an-array.ts b/typescript/1822-sign-of-the-product-of-an-array.ts index 8a0146d8c..3ed7fd6cb 100644 --- a/typescript/1822-sign-of-the-product-of-an-array.ts +++ b/typescript/1822-sign-of-the-product-of-an-array.ts @@ -3,7 +3,7 @@ function arraySign(nums: number[]): number { for (const num of nums) { if (num == 0) return 0; - else if (num < 0) sign = -1 * sign; + if (num < 0) sign = -1 * sign; } return sign;