File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77# If there are odd number of negative numbers and no zeros,
88# the result is simply the product of all
99
10- # If there is a zero and al other are positive, then the result is zero
10+ # If there is a zero and all other are positive, then the result is zero
1111
1212# If there are only positive numbers, the the result is
1313# the smallest positive number
1414
15+
1516def find (arr ):
1617 if len (arr ) == 1 :
1718 return arr [0 ]
18-
19+
1920 count_negative = 0
20- count_positive = 0
2121 count_zero = 0
2222 max_neg = float ('-inf' )
2323 min_pos = float ('inf' )
24-
24+
2525 prod = 1
26-
26+
2727 for num in arr :
2828 if num == 0 :
2929 count_zero += 1
3030 continue
3131
3232 if num < 0 :
33- count_neg += 1
33+ count_negative += 1
3434 max_neg = max (max_neg , num )
3535
3636 if num > 0 :
3737 min_pos = min (min_pos , num )
3838
39- prod = prod * num
39+ prod *= num
4040
41- if count_zero == len (arr ) or (count_neg == 0 and count_zero > 0 ):
41+ if count_zero == len (arr ) or (count_negative == 0 and count_zero > 0 ):
4242 return 0
43-
44- if count_neg == 0 :
43+
44+ if count_negative == 0 :
4545 return min_pos
4646
47- if count_neg & 1 == 0 and count_neg != 0 :
47+ if count_negative & 1 == 0 and count_negative != 0 :
4848 prod = int (prod / max_neg )
49-
50- return prod
5149
50+ return prod
You can’t perform that action at this time.
0 commit comments