Sign of the Product of an Array
There is a function signFunc(x)
that returns:
1
ifx
is positive.-1
ifx
is negative.0
ifx
is equal to0
.
You are given an integer array nums
. Let product
be the product of all values in the array nums
.
Return signFunc(product)
.

The problem description is taken from :- Leetcode Problem
Solution:-
Flow Diagram:-

Code Block:-
public static int arraySign(int [] nums) { int sign = 1; for (int n=0; n< nums.length; n++ ) { if (nums[n] == 0) { System.out.println("The value of n " + n); return 0; } else if (nums[n] < 0) { //System.out.println("The value of n222 " + nums [n]); sign = -sign; } } return sign; }
For more problem and solution please visit:- Algorithms and Datastructure