Skip to content

Commit 1ee91b6

Browse files
Create 1822. Sign of the Product of an Array
1 parent 7f47daa commit 1ee91b6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1822. Sign of the Product of an Array

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int arraySign(vector<int>& nums) {
4+
int cnt=0;
5+
for(int i=0; i<nums.size(); i++)
6+
7+
{
8+
if(nums[i]<0)
9+
cnt++;
10+
if(nums[i]==0)
11+
return 0;
12+
}
13+
if(cnt%2!=0) return -1;
14+
return 1;
15+
}
16+
};

0 commit comments

Comments
 (0)