找出三个数的最大乘积
作者:互联网
代码实现:
from typing import List class Solution: def maximunProduct(self, nums: List[int]) -> int: # 默认是升序 nums.sort() length = len(nums) if length == 3: return nums[0] * nums[1] * nums[2] else: return max(nums[0] * nums[1] * nums[-1], nums[-1] * nums[-2] * nums[-3])
测试:
if __name__ == '__main__': s = Solution() nums = [-1, 2, 4, -6, 3, 5] res = s.maximunProduct(nums) print(res)
结果:
60
标签:__,找出,return,乘积,nums,int,res,List,三个 来源: https://www.cnblogs.com/Durant0420/p/16184033.html