题解 | #三个数的最大乘积#
三个数的最大乘积
http://www.nowcoder.com/practice/8ae05c2913fe438b8b14f3968f64fc0b
#
# 最大乘积
# @param A int整型一维数组
# @return long长整型
#
class Solution:
def solve(self , A ):
# write code here
A = sorted(A)
max1 = A[-1]*A[-2]*A[-3]
max2 = A[0]*A[1]*A[-1]
return max(max1,max2)
两种情况:
- 三个最大的数都是正数
- 两个负数,一个正数