Skip to content

Commit 128e9fe

Browse files
committed
1822 - Sign of the Product of an Array
1 parent aea3459 commit 128e9fe

3 files changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const arraySign = function (nums) {
2+
let sign = 1;
3+
4+
for (const num of nums) {
5+
if (num == 0) return 0;
6+
else if (num < 0) sign = -1 * sign;
7+
}
8+
9+
return sign;
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def arraySign(self, nums: List[int]) -> int:
6+
sign = 1
7+
8+
for num in nums:
9+
if num == 0:
10+
return 0
11+
elif num < 0:
12+
sign = -1 * sign
13+
14+
return sign
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function arraySign(nums: number[]): number {
2+
let sign = 1;
3+
4+
for (const num of nums) {
5+
if (num == 0) return 0;
6+
else if (num < 0) sign = -1 * sign;
7+
}
8+
9+
return sign;
10+
}

0 commit comments

Comments
 (0)