TreeviewCopyright © aleen42 all right reserved, powered by aleen42

1464. 数组中两元素的最大乘积

https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array/

Java

/*
 * @Author: Goog Tech
 * @Date: 2020-08-15 14:44:31
 * @LastEditTime: 2020-08-15 14:45:04
 * @Description: https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array/
 * @FilePath: \leetcode-googtech\#1464. Maximum Product of Two Elements in an Array\Solution.java
 * @WebSite: https://algorithm.show/
 */

class Solution {
    public int maxProduct(int[] nums) {
        Arrays.sort(nums);
        return (nums[nums.length - 1] - 1) * (nums[nums.length - 2] - 1);
    }
}

Python

'''
Author: Goog Tech
Date: 2020-08-15 14:44:38
LastEditTime: 2020-08-15 14:45:11
Description: https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array/
FilePath: \leetcode-googtech\#1464. Maximum Product of Two Elements in an Array\Solution.py
WebSite: https://algorithm.show/
'''

class Solution(object):
    def maxProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        nums.sort()
        return (nums[len(nums) - 1] - 1) * (nums[len(nums) - 2] - 1)
Copyright © GoogTech 2021 all right reserved,powered by GitbookLast update time : 2021-09-15 01:55:05

results matching ""

    No results matching ""