问题描述:
Given an integer array, find three numbers whose product is maximum andoutput the maximum product.
示例一:
Input: [1,2,3]
Output: 6
示例二:
Input: [1,2,3,4]
Output: 24
Note:
1.The length of the given array will be in range [3,104] and all elements are in the range [-1000, 1000].
2.Multiplication of any three numbers in the input won't exceed the range of 32-bit signed integer.
问题来源:Maximum Product of Three Numbers (详细地址:https://leetcode.com/problems/maximum-product-of-three-numbers/description/)
思路分析:这个和Maximum Product Subarray 的区别在于:这道题已经限定了只能是三个数,不能多也不能少,在这只需要排序一下,假设a=最后的三个数的乘积,b=最后一个数和最前面两个数的乘积,去它两的最大值就是我们所求的结果了啊!就是这么简单!
代码: