#三个正数相乘,一正两负数 2种情况
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 最大乘积
# @param A int整型一维数组
# @return long长整型
#
class Solution:
def solve(self , A: List[int]) -> int:
# write code here
zs=[]
fs=[]
for item in A:
if item>0:
zs.append(item)
if item<0:
fs.append(item)
max_value=A[0]*A[1]*A[2]
if len(zs)>2:
zs=sorted(zs)
value=zs[-1]*zs[-2]*zs[-3]
if value>max_value:
max_value=value
fs=sorted(fs)
if len(zs)>0 and len(fs)>1:
value=zs[-1]*fs[0]*fs[1]
if value>max_value:
max_value=value
return max_value

京公网安备 11010502036488号