Class Solution
java.lang.Object
g1401_1500.s1464_maximum_product_of_two_elements_in_an_array.Solution
1464 - Maximum Product of Two Elements in an Array.<p>Easy</p>
<p>Given the array of integers <code>nums</code>, you will choose two different indices <code>i</code> and <code>j</code> of that array. <em>Return the maximum value of</em> <code>(nums[i]-1)*(nums[j]-1)</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [3,4,5,2]</p>
<p><strong>Output:</strong> 12</p>
<p><strong>Explanation:</strong> If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,5,4,5]</p>
<p><strong>Output:</strong> 16</p>
<p><strong>Explanation:</strong> Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [3,7]</p>
<p><strong>Output:</strong> 12</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= nums.length <= 500</code></li>
<li><code>1 <= nums[i] <= 10^3</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxProduct
public int maxProduct(int[] nums)
-