1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数组中两元素的最大乘积 [maximum-product-of-two-elements-in-an-array].html
2022-03-29 12:43:11 +08:00

35 lines
1.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code>,请你选择数组的两个不同下标 <code>i</code><code>j</code><em></em>使 <code>(nums[i]-1)*(nums[j]-1)</code> 取得最大值。</p>
<p>请你计算并返回该式的最大值。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [3,4,5,2]
<strong>输出:</strong>12
<strong>解释:</strong>如果选择下标 i=1 和 j=2下标从 0 开始),则可以获得最大值,(nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12 。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [1,5,4,5]
<strong>输出:</strong>16
<strong>解释:</strong>选择下标 i=1 和 j=3下标从 0 开始),则可以获得最大值 (5-1)*(5-1) = 16 。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>nums = [3,7]
<strong>输出:</strong>12
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 500</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10^3</code></li>
</ul>