Skip to content

Commit 6b3553e

Browse files
acbinidoocs
andauthored
feat: add biweekly contest 120 (doocs#2147)
--------- Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent 8dedc33 commit 6b3553e

File tree

18 files changed

+785
-1
lines changed

18 files changed

+785
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [10031. 统计移除递增子数组的数目 I](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-i)
2+
3+
[English Version](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的 <b>正</b>&nbsp;整数数组&nbsp;<code>nums</code>&nbsp;。</p>
10+
11+
<p>如果 <code>nums</code>&nbsp;的一个子数组满足:移除这个子数组后剩余元素 <strong>严格递增</strong>&nbsp;,那么我们称这个子数组为 <strong>移除递增</strong>&nbsp;子数组。比方说,<code>[5, 3, 4, 6, 7]</code>&nbsp;中的 <code>[3, 4]</code>&nbsp;是一个移除递增子数组,因为移除该子数组后,<code>[5, 3, 4, 6, 7]</code>&nbsp;变为&nbsp;<code>[5, 6, 7]</code>&nbsp;,是严格递增的。</p>
12+
13+
<p>请你返回 <code>nums</code>&nbsp;中 <b>移除递增</b>&nbsp;子数组的总数目。</p>
14+
15+
<p><b>注意</b>&nbsp;,剩余元素为空的数组也视为是递增的。</p>
16+
17+
<p><strong>子数组</strong> 指的是一个数组中一段连续的元素序列。</p>
18+
19+
<p>&nbsp;</p>
20+
21+
<p><strong class="example">示例 1:</strong></p>
22+
23+
<pre>
24+
<b>输入:</b>nums = [1,2,3,4]
25+
<b>输出:</b>10
26+
<b>解释:</b>10 个移除递增子数组分别为:[1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4] 和 [1,2,3,4]。移除任意一个子数组后,剩余元素都是递增的。注意,空数组不是移除递增子数组。
27+
</pre>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<pre>
32+
<b>输入:</b>nums = [6,5,7,8]
33+
<b>输出:</b>7
34+
<b>解释:</b>7<strong>&nbsp;</strong>个移除递增子数组分别为:[5], [6], [5,7], [6,5], [5,7,8], [6,5,7] 和 [6,5,7,8] 。
35+
nums 中只有这 7 个移除递增子数组。
36+
</pre>
37+
38+
<p><strong class="example">示例 3:</strong></p>
39+
40+
<pre>
41+
<b>输入:</b>nums = [8,7,6,6]
42+
<b>输出:</b>3
43+
<b>解释:</b>3 个移除递增子数组分别为:[8,7,6], [7,6,6] 和 [8,7,6,6] 。注意 [8,7] 不是移除递增子数组因为移除 [8,7] 后 nums 变为 [6,6] ,它不是严格递增的。
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
48+
<p><strong>提示:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
52+
<li><code>1 &lt;= nums[i] &lt;= 50</code></li>
53+
</ul>
54+
55+
## 解法
56+
57+
<!-- 这里可写通用的实现逻辑 -->
58+
59+
<!-- tabs:start -->
60+
61+
### **Python3**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```python
66+
67+
```
68+
69+
### **Java**
70+
71+
<!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+
```java
74+
75+
```
76+
77+
### **C++**
78+
79+
```cpp
80+
81+
```
82+
83+
### **Go**
84+
85+
```go
86+
87+
```
88+
89+
### **...**
90+
91+
```
92+
93+
```
94+
95+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# [10031. Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i)
2+
3+
[中文文档](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code>.</p>
8+
9+
<p>A subarray of <code>nums</code> is called <strong>incremovable</strong> if <code>nums</code> becomes <strong>strictly increasing</strong> on removing the subarray. For example, the subarray <code>[3, 4]</code> is an incremovable subarray of <code>[5, 3, 4, 6, 7]</code> because removing this subarray changes the array <code>[5, 3, 4, 6, 7]</code> to <code>[5, 6, 7]</code> which is strictly increasing.</p>
10+
11+
<p>Return <em>the total number of <strong>incremovable</strong> subarrays of</em> <code>nums</code>.</p>
12+
13+
<p><strong>Note</strong> that an empty array is considered strictly increasing.</p>
14+
15+
<p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
16+
17+
<p>&nbsp;</p>
18+
<p><strong class="example">Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> nums = [1,2,3,4]
22+
<strong>Output:</strong> 10
23+
<strong>Explanation:</strong> The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.
24+
</pre>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> nums = [6,5,7,8]
30+
<strong>Output:</strong> 7
31+
<strong>Explanation:</strong> The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
32+
It can be shown that there are only 7 incremovable subarrays in nums.
33+
</pre>
34+
35+
<p><strong class="example">Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> nums = [8,7,6,6]
39+
<strong>Output:</strong> 3
40+
<strong>Explanation:</strong> The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
48+
<li><code>1 &lt;= nums[i] &lt;= 50</code></li>
49+
</ul>
50+
51+
## Solutions
52+
53+
<!-- tabs:start -->
54+
55+
### **Python3**
56+
57+
```python
58+
59+
```
60+
61+
### **Java**
62+
63+
```java
64+
65+
```
66+
67+
### **C++**
68+
69+
```cpp
70+
71+
```
72+
73+
### **Go**
74+
75+
```go
76+
77+
```
78+
79+
### **...**
80+
81+
```
82+
83+
```
84+
85+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# [10032. 找到最大周长的多边形](https://leetcode.cn/problems/find-polygon-with-the-largest-perimeter)
2+
3+
[English Version](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个长度为&nbsp;<code>n</code>&nbsp;&nbsp;<strong>正</strong>&nbsp;整数数组&nbsp;<code>nums</code>&nbsp;。</p>
10+
11+
<p><strong>多边形</strong>&nbsp;指的是一个至少有 <code>3</code>&nbsp;条边的封闭二维图形。多边形的 <strong>最长边</strong>&nbsp;一定 <strong>小于</strong>&nbsp;所有其他边长度之和。</p>
12+
13+
<p>如果你有&nbsp;<code>k</code>&nbsp;(<code>k &gt;= 3</code>)个&nbsp;<strong>正</strong>&nbsp;&nbsp;<code>a<sub>1</sub></code>,<code>a<sub>2</sub></code>,<code>a<sub>3</sub></code>, ...,<code>a<sub>k</sub></code> 满足&nbsp;<code>a<sub>1</sub> &lt;= a<sub>2</sub> &lt;= a<sub>3</sub> &lt;= ... &lt;= a<sub>k</sub></code> <strong>且</strong> <code>a<sub>1</sub> + a<sub>2</sub> + a<sub>3</sub> + ... + a<sub>k-1</sub> &gt; a<sub>k</sub></code><sub>&nbsp;</sub>,那么 <strong>一定</strong>&nbsp;存在一个&nbsp;<code>k</code>&nbsp;条边的多边形,每条边的长度分别为&nbsp;<code>a<sub>1</sub></code>&nbsp;,<code>a<sub>2</sub></code>&nbsp;,<code>a<sub>3</sub></code>&nbsp;&nbsp;...,<code>a<sub>k</sub></code>&nbsp;。</p>
14+
15+
<p>一个多边形的 <strong>周长</strong>&nbsp;指的是它所有边之和。</p>
16+
17+
<p>请你返回从 <code>nums</code>&nbsp;中可以构造的 <strong>多边形&nbsp;</strong>的 <strong>最大周长</strong>&nbsp;。如果不能构造出任何多边形,请你返回 <code>-1</code>&nbsp;。</p>
18+
19+
<p>&nbsp;</p>
20+
21+
<p><strong class="example">示例 1:</strong></p>
22+
23+
<pre>
24+
<b>输入:</b>nums = [5,5,5]
25+
<b>输出:</b>15
26+
<b>解释:</b>nums 中唯一可以构造的多边形为三角形,每条边的长度分别为 5 ,5 和 5 ,周长为 5 + 5 + 5 = 15 。
27+
</pre>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<pre>
32+
<b>输入:</b>nums = [1,12,1,2,5,50,3]
33+
<b>输出:</b>12
34+
<b>解释:</b>最大周长多边形为五边形,每条边的长度分别为 1 ,1 ,2 ,3 和 5 ,周长为 1 + 1 + 2 + 3 + 5 = 12 。
35+
我们无法构造一个包含变长为 12 或者 50 的多边形,因为其他边之和没法大于两者中的任何一个。
36+
所以最大周长为 12 。
37+
</pre>
38+
39+
<p><strong class="example">示例 3:</strong></p>
40+
41+
<pre>
42+
<b>输入:</b>nums = [5,5,50]
43+
<b>输出:</b>-1
44+
<b>解释:</b>无法构造任何多边形,因为多边形至少要有 3 条边且 50 &gt; 5 + 5 。
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
49+
<p><strong>提示:</strong></p>
50+
51+
<ul>
52+
<li><code>3 &lt;= n &lt;= 10<sup>5</sup></code></li>
53+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
54+
</ul>
55+
56+
## 解法
57+
58+
<!-- 这里可写通用的实现逻辑 -->
59+
60+
<!-- tabs:start -->
61+
62+
### **Python3**
63+
64+
<!-- 这里可写当前语言的特殊实现逻辑 -->
65+
66+
```python
67+
68+
```
69+
70+
### **Java**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```java
75+
76+
```
77+
78+
### **C++**
79+
80+
```cpp
81+
82+
```
83+
84+
### **Go**
85+
86+
```go
87+
88+
```
89+
90+
### **...**
91+
92+
```
93+
94+
```
95+
96+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [10032. Find Polygon With the Largest Perimeter](https://leetcode.com/problems/find-polygon-with-the-largest-perimeter)
2+
3+
[中文文档](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md)
4+
5+
## Description
6+
7+
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p>
8+
9+
<p>A <strong>polygon</strong> is a closed plane figure that has at least <code>3</code> sides. The <strong>longest side</strong> of a polygon is <strong>smaller</strong> than the sum of its other sides.</p>
10+
11+
<p>Conversely, if you have <code>k</code> (<code>k &gt;= 3</code>) <strong>positive</strong> real numbers <code>a<sub>1</sub></code>, <code>a<sub>2</sub></code>, <code>a<sub>3</sub></code>, ..., <code>a<sub>k</sub></code> where <code>a<sub>1</sub> &lt;= a<sub>2</sub> &lt;= a<sub>3</sub> &lt;= ... &lt;= a<sub>k</sub></code> <strong>and</strong> <code>a<sub>1</sub> + a<sub>2</sub> + a<sub>3</sub> + ... + a<sub>k-1</sub> &gt; a<sub>k</sub></code>, then there <strong>always</strong> exists a polygon with <code>k</code> sides whose lengths are <code>a<sub>1</sub></code>, <code>a<sub>2</sub></code>, <code>a<sub>3</sub></code>, ..., <code>a<sub>k</sub></code>.</p>
12+
13+
<p>The <strong>perimeter</strong> of a polygon is the sum of lengths of its sides.</p>
14+
15+
<p>Return <em>the <strong>largest</strong> possible <strong>perimeter</strong> of a <strong>polygon</strong> whose sides can be formed from</em> <code>nums</code>, <em>or</em> <code>-1</code> <em>if it is not possible to create a polygon</em>.</p>
16+
17+
<p>&nbsp;</p>
18+
<p><strong class="example">Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> nums = [5,5,5]
22+
<strong>Output:</strong> 15
23+
<strong>Explanation:</strong> The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.
24+
</pre>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> nums = [1,12,1,2,5,50,3]
30+
<strong>Output:</strong> 12
31+
<strong>Explanation:</strong> The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12.
32+
We cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them.
33+
It can be shown that the largest possible perimeter is 12.
34+
</pre>
35+
36+
<p><strong class="example">Example 3:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> nums = [5,5,50]
40+
<strong>Output:</strong> -1
41+
<strong>Explanation:</strong> There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 &gt; 5 + 5.
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>3 &lt;= n &lt;= 10<sup>5</sup></code></li>
49+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
50+
</ul>
51+
52+
## Solutions
53+
54+
<!-- tabs:start -->
55+
56+
### **Python3**
57+
58+
```python
59+
60+
```
61+
62+
### **Java**
63+
64+
```java
65+
66+
```
67+
68+
### **C++**
69+
70+
```cpp
71+
72+
```
73+
74+
### **Go**
75+
76+
```go
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->

0 commit comments

Comments
 (0)