Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2688 from AHTHneeuhl/1822
Browse files Browse the repository at this point in the history
  • Loading branch information
aakhtar3 authored Jul 11, 2023
2 parents 0c0fdff + c35127b commit c7ce625
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions javascript/1822-sign-of-the-product-of-an-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const arraySign = function (nums) {
let sign = 1;

for (const num of nums) {
if (num == 0) return 0;
if (num < 0) sign = -1 * sign;
}

return sign;
};
14 changes: 14 additions & 0 deletions python/1822-sign-of-the-product-of-an-array.py
Original file line number Diff line number Diff line change
@@ -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
if num < 0:
sign = -1 * sign

return sign
10 changes: 10 additions & 0 deletions typescript/1822-sign-of-the-product-of-an-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function arraySign(nums: number[]): number {
let sign = 1;

for (const num of nums) {
if (num == 0) return 0;
if (num < 0) sign = -1 * sign;
}

return sign;
}

0 comments on commit c7ce625

Please sign in to comment.