forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add weekly contest 368 (doocs#1862)
- Loading branch information
Showing
19 changed files
with
853 additions
and
57 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# [2908. 元素和最小的山形三元组 I](https://leetcode.cn/problems/minimum-sum-of-mountain-triplets-i) | ||
|
||
[English Version](/solution/2900-2999/2908.Minimum%20Sum%20of%20Mountain%20Triplets%20I/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。</p> | ||
|
||
<p>如果下标三元组 <code>(i, j, k)</code> 满足下述全部条件,则认为它是一个 <strong>山形三元组</strong> :</p> | ||
|
||
<ul> | ||
<li><code>i < j < k</code></li> | ||
<li><code>nums[i] < nums[j]</code> 且 <code>nums[k] < nums[j]</code></li> | ||
</ul> | ||
|
||
<p>请你找出 <code>nums</code> 中 <strong>元素和最小</strong> 的山形三元组,并返回其 <strong>元素和</strong> 。如果不存在满足条件的三元组,返回 <code>-1</code> 。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [8,6,1,5,3] | ||
<strong>输出:</strong>9 | ||
<strong>解释:</strong>三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为: | ||
- 2 < 3 < 4 | ||
- nums[2] < nums[3] 且 nums[4] < nums[3] | ||
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [5,4,8,7,10,2] | ||
<strong>输出:</strong>13 | ||
<strong>解释:</strong>三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为: | ||
- 1 < 3 < 5 | ||
- nums[1] < nums[3] 且 nums[5] < nums[3] | ||
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 3:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [6,5,4,3,4,5] | ||
<strong>输出:</strong>-1 | ||
<strong>解释:</strong>可以证明 nums 中不存在山形三元组。 | ||
</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>3 <= nums.length <= 50</code></li> | ||
<li><code>1 <= nums[i] <= 50</code></li> | ||
</ul> | ||
|
||
## 解法 | ||
|
||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
91 changes: 91 additions & 0 deletions
91
solution/2900-2999/2908.Minimum Sum of Mountain Triplets I/README_EN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# [2908. Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | ||
|
||
[中文文档](/solution/2900-2999/2908.Minimum%20Sum%20of%20Mountain%20Triplets%20I/README.md) | ||
|
||
## Description | ||
|
||
<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 <= 50</code></li> | ||
<li><code>1 <= nums[i] <= 50</code></li> | ||
</ul> | ||
|
||
## Solutions | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
101 changes: 101 additions & 0 deletions
101
solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# [2909. 元素和最小的山形三元组 II](https://leetcode.cn/problems/minimum-sum-of-mountain-triplets-ii) | ||
|
||
[English Version](/solution/2900-2999/2909.Minimum%20Sum%20of%20Mountain%20Triplets%20II/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。</p> | ||
|
||
<p>如果下标三元组 <code>(i, j, k)</code> 满足下述全部条件,则认为它是一个 <strong>山形三元组</strong> :</p> | ||
|
||
<ul> | ||
<li><code>i < j < k</code></li> | ||
<li><code>nums[i] < nums[j]</code> 且 <code>nums[k] < nums[j]</code></li> | ||
</ul> | ||
|
||
<p>请你找出 <code>nums</code> 中 <strong>元素和最小</strong> 的山形三元组,并返回其 <strong>元素和</strong> 。如果不存在满足条件的三元组,返回 <code>-1</code> 。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [8,6,1,5,3] | ||
<strong>输出:</strong>9 | ||
<strong>解释:</strong>三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为: | ||
- 2 < 3 < 4 | ||
- nums[2] < nums[3] 且 nums[4] < nums[3] | ||
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [5,4,8,7,10,2] | ||
<strong>输出:</strong>13 | ||
<strong>解释:</strong>三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为: | ||
- 1 < 3 < 5 | ||
- nums[1] < nums[3] 且 nums[5] < nums[3] | ||
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 3:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [6,5,4,3,4,5] | ||
<strong>输出:</strong>-1 | ||
<strong>解释:</strong>可以证明 nums 中不存在山形三元组。 | ||
</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</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> | ||
|
||
## 解法 | ||
|
||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
91 changes: 91 additions & 0 deletions
91
solution/2900-2999/2909.Minimum Sum of Mountain Triplets II/README_EN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# [2909. Minimum Sum of Mountain Triplets II](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-ii) | ||
|
||
[中文文档](/solution/2900-2999/2909.Minimum%20Sum%20of%20Mountain%20Triplets%20II/README.md) | ||
|
||
## Description | ||
|
||
<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> | ||
|
||
## Solutions | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
Oops, something went wrong.