Skip to content

Commit

Permalink
Merge pull request 7oSkaaa#1026 from NouraAlgohary/main
Browse files Browse the repository at this point in the history
add day 2 modified
  • Loading branch information
aboelsooud committed May 2, 2023
2 parents 38bd39e + fa8dc17 commit 9b3f3f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Author: Noura Algohary
class Solution {
public:
int arraySign(vector<int>& 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;
}
};
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9b3f3f5

Please sign in to comment.