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 new lc problem (doocs#2416)
- Loading branch information
Showing
4 changed files
with
201 additions
and
48 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
solution/3000-3099/3073.Maximum Increasing Triplet Value/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,74 @@ | ||
# [3073. 最大递增三元组](https://leetcode.cn/problems/maximum-increasing-triplet-value) | ||
|
||
[English Version](/solution/3000-3099/3073.Maximum%20Increasing%20Triplet%20Value/README_EN.md) | ||
|
||
<!-- tags: --> | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给定一个数组 <code>nums</code>,返回满足 <code>i < j < k</code> 且 <code>nums[i] < nums[j] < nums[k]</code> 的三元组 <code>(i, j, k)</code> <em> </em>的 <strong>最大值</strong><i>。</i></p> | ||
|
||
<p>三元组 <code>(i, j, k)</code> 的 <strong>值 </strong>为 <code>nums[i] - nums[j] + nums[k]</code>。</p> | ||
|
||
<div id="gtx-trans" style="position: absolute; left: 274px; top: 102px;"> | ||
<div class="gtx-trans-icon"> </div> | ||
</div> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1: </strong></p> | ||
|
||
<pre> | ||
输入:nums = [5,6,9] | ||
输出:8 | ||
解释:对于一个递增的三元组,我们只有一个选择,那就是选择所有三个元素。三元组的值为 5 - 6 + 9 = 8。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 2: </strong></p> | ||
|
||
<pre> | ||
输入:nums = [1,5,3,6] | ||
输出:4 | ||
解释:只有两个递增三元组: | ||
(0, 1, 3):这个三元组的值为 nums[0] - nums[1] + nums[3] = 1 - 5 + 6 = 2。 | ||
(0, 2, 3):这个三元组的值为 nums[0] - nums[2] + nums[3] = 1 - 3 + 6 = 4。 | ||
因此答案是 4。 | ||
</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>9</sup></code></li> | ||
<li>输入数据保证至少一个三元组满足给定条件。</li> | ||
</ul> | ||
|
||
## 解法 | ||
|
||
### 方法一 | ||
|
||
<!-- tabs:start --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
```java | ||
|
||
``` | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
```go | ||
|
||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- end --> |
77 changes: 77 additions & 0 deletions
77
solution/3000-3099/3073.Maximum Increasing Triplet Value/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,77 @@ | ||
# [3073. Maximum Increasing Triplet Value](https://leetcode.com/problems/maximum-increasing-triplet-value) | ||
|
||
[中文文档](/solution/3000-3099/3073.Maximum%20Increasing%20Triplet%20Value/README.md) | ||
|
||
<!-- tags: --> | ||
|
||
## Description | ||
|
||
<p>Given an array <code>nums</code>, return <em>the <strong>maximum value</strong> of a triplet</em> <code>(i, j, k)</code> <em>such that</em> <code>i < j < k</code> <em>and</em> <code>nums[i] < nums[j] < nums[k]</code>.</p> | ||
|
||
<p>The <strong>value</strong> of a triplet <code>(i, j, k)</code> is <code>nums[i] - nums[j] + nums[k]</code>.</p> | ||
|
||
<div id="gtx-trans" style="position: absolute; left: 274px; top: 102px;"> | ||
<div class="gtx-trans-icon"> </div> | ||
</div> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1: </strong></p> | ||
|
||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;"> | ||
<p><strong>Input: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">nums = [5,6,9] </span></p> | ||
|
||
<p><strong>Output: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">8 </span></p> | ||
|
||
<p><strong>Explanation: </strong> We only have one choice for an increasing triplet and that is choosing all three elements. The value of this triplet would be <code>5 - 6 + 9 = 8</code>.</p> | ||
</div> | ||
|
||
<p><strong class="example">Example 2: </strong></p> | ||
|
||
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;"> | ||
<p><strong>Input:</strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> nums = [1,5,3,6] </span></p> | ||
|
||
<p><strong>Output:</strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> 4 </span></p> | ||
|
||
<p><strong>Explanation: </strong> There are only two increasing triplets:</p> | ||
|
||
<p><code>(0, 1, 3)</code>: The value of this triplet is <code>nums[0] - nums[1] + nums[3] = 1 - 5 + 6 = 2</code>.</p> | ||
|
||
<p><code>(0, 2, 3)</code>: The value of this triplet is <code>nums[0] - nums[2] + nums[3] = 1 - 3 + 6 = 4</code>.</p> | ||
|
||
<p>Thus the answer would be <code>4</code>.</p> | ||
</div> | ||
|
||
<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>9</sup></code></li> | ||
<li>The input is generated such that at least one triplet meets the given condition.</li> | ||
</ul> | ||
|
||
## Solutions | ||
|
||
### Solution 1 | ||
|
||
<!-- tabs:start --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
```java | ||
|
||
``` | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
```go | ||
|
||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- end --> |
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
Oops, something went wrong.