Skip to content

Commit b4c99ed

Browse files
committed
feat: update lc problems
1 parent 1e77ff2 commit b4c99ed

16 files changed

Lines changed: 92 additions & 43 deletions

File tree

40.7 KB
Loading

solution/3800-3899/3874.Valid Subarrays With Exactly One Peak/README.md

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,92 @@
22
comments: true
33
difficulty: 中等
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3874.Valid%20Subarrays%20With%20Exactly%20One%20Peak/README.md
5+
tags:
6+
- 数组
7+
- 数学
58
---
69

710
<!-- problem:start -->
811

9-
# [3874. Valid Subarrays With Exactly One Peak 🔒](https://leetcode.cn/problems/valid-subarrays-with-exactly-one-peak)
12+
# [3874. 具有恰好一个峰值的有效子数组 🔒](https://leetcode.cn/problems/valid-subarrays-with-exactly-one-peak)
1013

1114
[English Version](/solution/3800-3899/3874.Valid%20Subarrays%20With%20Exactly%20One%20Peak/README_EN.md)
1215

1316
## 题目描述
1417

1518
<!-- description:start -->
1619

17-
<p>You are given an integer array <code>nums</code> of length <code>n</code> and an integer <code>k</code>.</p>
20+
<p>给定一个长度为&nbsp;<code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code></p>
1821

19-
<p>An index <code>i</code> is a <strong>peak</strong> if:</p>
22+
<p>下标&nbsp;<code>i</code> <strong>峰值</strong> 的条件为:</p>
2023

2124
<ul>
2225
<li><code>0 &lt; i &lt; n - 1</code></li>
23-
<li><code>nums[i] &gt; nums[i - 1]</code> and <code>nums[i] &gt; nums[i + 1]</code></li>
26+
<li><code>nums[i] &gt; nums[i - 1]</code> 且&nbsp;<code>nums[i] &gt; nums[i + 1]</code></li>
2427
</ul>
2528

26-
<p>A subarray <code>[l, r]</code> is <strong>valid</strong> if:</p>
29+
<p>一个子数组&nbsp;<code>[l, r]</code>&nbsp;<strong>有效 </strong>的条件是:</p>
2730

2831
<ul>
29-
<li>It contains <strong>exactly one</strong> peak at index <code>i</code> from <code>nums</code></li>
30-
<li><code>i - l &lt;= k</code> and <code>r - i &lt;= k</code></li>
32+
<li><strong>恰好有一个</strong>&nbsp;<code>nums</code>&nbsp;中下标&nbsp;<code>i</code> 处的峰值</li>
33+
<li><code>i - l &lt;= k</code> 且&nbsp;<code>r - i &lt;= k</code></li>
3134
</ul>
3235

33-
<p>Return an integer denoting the number of <strong>valid subarrays</strong> in <code>nums</code>.</p>
34-
A <strong>subarray</strong> is a contiguous <b>non-empty</b> sequence of elements within an array.
36+
<p>返回一个整数,表示 <code>nums</code> 中 <strong>有效子数组</strong> 的数量。</p>
37+
<strong>子数组</strong> 是数组中的连续 <strong>非空</strong> 元素序列。
38+
3539
<p>&nbsp;</p>
36-
<p><strong class="example">Example 1:</strong></p>
40+
41+
<p><strong class="example">示例 1:</strong></p>
3742

3843
<div class="example-block">
39-
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,2], k = 1</span></p>
44+
<p><span class="example-io"><b>输入:</b>nums = [1,3,2], k = 1</span></p>
4045

41-
<p><strong>Output:</strong> <span class="example-io">4</span></p>
46+
<p><span class="example-io"><b>输出:</b>4</span></p>
4247

43-
<p><strong>Explanation:</strong></p>
48+
<p><strong>解释:</strong></p>
4449

4550
<ul>
46-
<li>Index <code>i = 1</code> is a peak because <code>nums[1] = 3</code> is greater than <code>nums[0] = 1</code> and <code>nums[2] = 2</code>.</li>
47-
<li>Any valid subarray must include index 1, and the distance from the peak to both ends of the subarray must not exceed <code>k = 1</code>.</li>
48-
<li>The valid subarrays are <code>[3]</code>, <code>[1, 3]</code>, <code>[3, 2]</code>, and <code>[1, 3, 2]</code>, so the answer is 4.</li>
51+
<li>下标 <code>i = 1</code>&nbsp;是一个峰值,因为 <code>nums[1] = 3</code> 大于 <code>nums[0] = 1</code> <code>nums[2] = 2</code></li>
52+
<li>任何有效的子数组必须包含下标&nbsp;1,且子数组两端到峰值的距离不得超过 <code>k = 1</code></li>
53+
<li>有效的子数组是&nbsp;<code>[3]</code><code>[1, 3]</code><code>[3, 2]</code>&nbsp;和&nbsp;<code>[1, 3, 2]</code>,所以答案是 4。</li>
4954
</ul>
5055
</div>
5156

52-
<p><strong class="example">Example 2:</strong></p>
57+
<p><strong class="example">示例 2:</strong></p>
5358

5459
<div class="example-block">
55-
<p><strong>Input:</strong> <span class="example-io">nums = [7,8,9], k = 2</span></p>
60+
<p><span class="example-io"><b>输入:</b>nums = [7,8,9], k = 2</span></p>
5661

57-
<p><strong>Output:</strong> <span class="example-io">0</span></p>
62+
<p><span class="example-io"><b>输出:</b>0</span></p>
5863

59-
<p><strong>Explanation:</strong></p>
64+
<p><strong>解释:</strong></p>
6065

6166
<ul>
62-
<li>There is no index <code>i</code> such that <code>nums[i]</code> is greater than both <code>nums[i - 1]</code> and <code>nums[i + 1]</code>.</li>
63-
<li>Therefore, the array contains no peak. Thus, the number of valid subarrays is 0.</li>
67+
<li>没有下标&nbsp;<code>i</code> 使得&nbsp;<code>nums[i]</code>&nbsp;同时比&nbsp;<code>nums[i - 1]</code> 和&nbsp;<code>nums[i + 1]</code>&nbsp;更大。</li>
68+
<li>因此,该数组中没有峰值。所以,有效子数组的数量为 0。</li>
6469
</ul>
6570
</div>
6671

67-
<p><strong class="example">Example 3:</strong></p>
72+
<p><strong class="example">示例 3:</strong></p>
6873

6974
<div class="example-block">
70-
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,5,1], k = 2</span></p>
75+
<p><span class="example-io"><b>输入:</b>nums = [4,3,5,1], k = 2</span></p>
7176

72-
<p><strong>Output:</strong> <span class="example-io">6</span></p>
77+
<p><span class="example-io"><b>输出:</b>6</span></p>
7378

74-
<p><strong>Explanation:</strong></p>
79+
<p><strong>解释:</strong></p>
7580

7681
<ul>
77-
<li>Index <code>i = 2</code> is a peak because <code>nums[2] = 5</code> is greater than <code>nums[1] = 3</code> and <code>nums[3] = 1</code>.</li>
78-
<li>Any valid subarray must contain this peak, and the distance from the peak to both ends of the subarray must not exceed <code>k = 2</code>.</li>
79-
<li>The valid subarrays are <code>[5]</code>, <code>[3, 5]</code>, <code>[5, 1]</code>, <code>[3, 5, 1]</code>, <code>[4, 3, 5]</code>, and <code>[4, 3, 5, 1]</code>, so the answer is 6.</li>
82+
<li>下标 <code>i = 2</code>&nbsp;是一个峰值,因为 <code>nums[2] = 5</code> 大于 <code>nums[1] = 3</code>&nbsp;和 <code>nums[3] = 1</code></li>
83+
<li>任何有效的子数组都必须包含这个峰值,并且峰值到子数组两端的距离不得超过 <code>k = 2</code></li>
84+
<li>合法子数组是&nbsp;<code>[5]</code><code>[3, 5]</code><code>[5, 1]</code><code>[3, 5, 1]</code><code>[4, 3, 5]</code>&nbsp;和&nbsp;<code>[4, 3, 5, 1]</code>,所以答案是 6。</li>
8085
</ul>
8186
</div>
8287

8388
<p>&nbsp;</p>
84-
<p><strong>Constraints:</strong></p>
89+
90+
<p><strong>提示:</strong></p>
8591

8692
<ul>
8793
<li><code>1 &lt;= n == nums.length &lt;= 10<sup>5</sup></code></li>

solution/3800-3899/3874.Valid Subarrays With Exactly One Peak/README_EN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
comments: true
33
difficulty: Medium
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3874.Valid%20Subarrays%20With%20Exactly%20One%20Peak/README_EN.md
5+
tags:
6+
- Array
7+
- Math
58
---
69

710
<!-- problem:start -->

solution/3800-3899/3875.Construct Uniform Parity Array I/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
comments: true
33
difficulty: 简单
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3875.Construct%20Uniform%20Parity%20Array%20I/README.md
5+
tags:
6+
- 数组
7+
- 数学
58
---
69

710
<!-- problem:start -->

solution/3800-3899/3875.Construct Uniform Parity Array I/README_EN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
comments: true
33
difficulty: Easy
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3875.Construct%20Uniform%20Parity%20Array%20I/README_EN.md
5+
tags:
6+
- Array
7+
- Math
58
---
69

710
<!-- problem:start -->

solution/3800-3899/3876.Construct Uniform Parity Array II/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
comments: true
33
difficulty: 中等
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3876.Construct%20Uniform%20Parity%20Array%20II/README.md
5+
tags:
6+
- 数组
7+
- 数学
58
---
69

710
<!-- problem:start -->

solution/3800-3899/3876.Construct Uniform Parity Array II/README_EN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
comments: true
33
difficulty: Medium
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3876.Construct%20Uniform%20Parity%20Array%20II/README_EN.md
5+
tags:
6+
- Array
7+
- Math
58
---
69

710
<!-- problem:start -->

solution/3800-3899/3877.Minimum Removals to Achieve Target XOR/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
comments: true
33
difficulty: 中等
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3877.Minimum%20Removals%20to%20Achieve%20Target%20XOR/README.md
5+
tags:
6+
- 位运算
7+
- 数组
8+
- 动态规划
59
---
610

711
<!-- problem:start -->

solution/3800-3899/3877.Minimum Removals to Achieve Target XOR/README_EN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
comments: true
33
difficulty: Medium
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3877.Minimum%20Removals%20to%20Achieve%20Target%20XOR/README_EN.md
5+
tags:
6+
- Bit Manipulation
7+
- Array
8+
- Dynamic Programming
59
---
610

711
<!-- problem:start -->

solution/3800-3899/3878.Count Good Subarrays/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
comments: true
33
difficulty: 困难
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3878.Count%20Good%20Subarrays/README.md
5+
tags:
6+
-
7+
- 位运算
8+
- 数组
9+
- 单调栈
510
---
611

712
<!-- problem:start -->

0 commit comments

Comments
 (0)