1464. Maximum Product of Two Elements in an Array

Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).

很简单,就是找出最大值和次大值相乘。

class Solution(object):
    def maxProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        max_value = 0
        next_max_value = 0
        for num in nums:
            if num > max_value:
                next_max_value = max_value
                max_value = num
            else:
                if num > next_max_value:
                    next_max_value = num
        return (max_value - 1) * (next_max_value - 1)
原文地址:https://www.cnblogs.com/whatyouthink/p/13205582.html