Skip to content

Commit 35d4f2f

Browse files
authored
Added Sign of the Product of an Array.java
1 parent d4ba403 commit 35d4f2f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public int arraySign(int[] nums) {
3+
return Arrays.stream(nums).filter(num -> num == 0).map(e -> 0).findAny()
4+
.orElse(Arrays.stream(nums).filter(num -> num < 0).count() % 2 == 0 ? 1 : -1);
5+
}
6+
}

0 commit comments

Comments
 (0)