diff --git a/05- May/02- Sign of the Product of an Array/02- Sign of the Product of an Array (Noura Algohary).cpp b/05- May/02- Sign of the Product of an Array/02- Sign of the Product of an Array (Noura Algohary).cpp new file mode 100644 index 000000000..a7ebcfdb8 --- /dev/null +++ b/05- May/02- Sign of the Product of an Array/02- Sign of the Product of an Array (Noura Algohary).cpp @@ -0,0 +1,22 @@ +// Author: Noura Algohary +class Solution { +public: + int arraySign(vector& nums) { + int signCounter = 0; + + for(int num : nums) + { + // if one zero appears, the result is zero + if(num==0) + return 0; + else if(num<0) + signCounter++; + } + + // if negative numbers are of odd count, the result is negative + if (signCounter%2==0) + return 1; + else + return -1; + } +}; \ No newline at end of file diff --git a/05- May/02- Sign of the Product of an Array/02- Sign of the Product of an Array (Noura Algohary).py b/05- May/02- Sign of the Product of an Array/02- Sign of the Product of an Array (Noura Algohary).py new file mode 100644 index 000000000..7e83fd589 --- /dev/null +++ b/05- May/02- Sign of the Product of an Array/02- Sign of the Product of an Array (Noura Algohary).py @@ -0,0 +1,14 @@ +# Author: Noura Algohary +class Solution: + def arraySign(self, nums: List[int]) -> int: + signCounter = 0 + + for num in nums: + # if one zero appears, the result is zero + if num == 0: + return 0 + elif num < 0: + signCounter += 1 + + # if negative numbers are of odd count, the result is negative + return 1 if signCounter % 2 == 0 else -1 \ No newline at end of file