mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
50 lines
1.7 KiB
HTML
50 lines
1.7 KiB
HTML
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of integers.</p>
|
|
|
|
<p>A triplet of indices <code>(i, j, k)</code> is a <strong>mountain</strong> if:</p>
|
|
|
|
<ul>
|
|
<li><code>i < j < k</code></li>
|
|
<li><code>nums[i] < nums[j]</code> and <code>nums[k] < nums[j]</code></li>
|
|
</ul>
|
|
|
|
<p>Return <em>the <strong>minimum possible sum</strong> of a mountain triplet of</em> <code>nums</code>. <em>If no such triplet exists, return</em> <code>-1</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [8,6,1,5,3]
|
|
<strong>Output:</strong> 9
|
|
<strong>Explanation:</strong> Triplet (2, 3, 4) is a mountain triplet of sum 9 since:
|
|
- 2 < 3 < 4
|
|
- nums[2] < nums[3] and nums[4] < nums[3]
|
|
And the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [5,4,8,7,10,2]
|
|
<strong>Output:</strong> 13
|
|
<strong>Explanation:</strong> Triplet (1, 3, 5) is a mountain triplet of sum 13 since:
|
|
- 1 < 3 < 5
|
|
- nums[1] < nums[3] and nums[5] < nums[3]
|
|
And the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [6,5,4,3,4,5]
|
|
<strong>Output:</strong> -1
|
|
<strong>Explanation:</strong> It can be shown that there are no mountain triplets in nums.
|
|
</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>8</sup></code></li>
|
|
</ul>
|