LeetCode #1464. Maximum Product of Two Elements in an Array
时间:2020-12-01 18:14:12
收藏:0
阅读:40
题目
1464. Maximum Product of Two Elements in an Array
解题方法
先降序排序,然后选择前两个数相乘。
时间复杂度:O(nlogn)
空间复杂度:O(1)
代码
class Solution:
def maxProduct(self, nums: List[int]) -> int:
nums.sort(reverse=True)
return (nums[0] - 1) * (nums[1] - 1)
原文:https://www.cnblogs.com/RatsCommander/p/14069319.html
评论(0)