mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
41 lines
1.6 KiB
HTML
41 lines
1.6 KiB
HTML
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>
|
||
|
|
||
|
<p>Return <em><strong>the maximum value over all triplets of indices</strong></em> <code>(i, j, k)</code> <em>such that</em> <code>i < j < k</code><em>. </em>If all such triplets have a negative value, return <code>0</code>.</p>
|
||
|
|
||
|
<p>The <strong>value of a triplet of indices</strong> <code>(i, j, k)</code> is equal to <code>(nums[i] - nums[j]) * nums[k]</code>.</p>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong class="example">Example 1:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> nums = [12,6,1,2,7]
|
||
|
<strong>Output:</strong> 77
|
||
|
<strong>Explanation:</strong> The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
|
||
|
It can be shown that there are no ordered triplets of indices with a value greater than 77.
|
||
|
</pre>
|
||
|
|
||
|
<p><strong class="example">Example 2:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> nums = [1,10,3,4,19]
|
||
|
<strong>Output:</strong> 133
|
||
|
<strong>Explanation:</strong> The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
|
||
|
It can be shown that there are no ordered triplets of indices with a value greater than 133.
|
||
|
</pre>
|
||
|
|
||
|
<p><strong class="example">Example 3:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> nums = [1,2,3]
|
||
|
<strong>Output:</strong> 0
|
||
|
<strong>Explanation:</strong> The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Constraints:</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li><code>3 <= nums.length <= 10<sup>5</sup></code></li>
|
||
|
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
||
|
</ul>
|