Skip to content

Commit 32b287a

Browse files
committed
feat: add new lc problems
1 parent 240c757 commit 32b287a

File tree

14 files changed

+947
-2
lines changed

14 files changed

+947
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [2833. 距离原点最远的点](https://leetcode.cn/problems/furthest-point-from-origin)
2+
3+
[English Version](/solution/2800-2899/2833.Furthest%20Point%20From%20Origin/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个长度为 <code>n</code> 的字符串 <code>moves</code> ,该字符串仅由字符 <code>'L'</code>、<code>'R'</code> 和 <code>'_'</code> 组成。字符串表示你在一条原点为 <code>0</code> 的数轴上的若干次移动。</p>
10+
11+
<p>你的初始位置就在原点(<code>0</code>),第 <code>i</code> 次移动过程中,你可以根据对应字符选择移动方向:</p>
12+
13+
<ul>
14+
<li>如果 <code>moves[i] = 'L'</code> 或 <code>moves[i] = '_'</code> ,可以选择向左移动一个单位距离</li>
15+
<li>如果 <code>moves[i] = 'R'</code> 或 <code>moves[i] = '_'</code> ,可以选择向右移动一个单位距离</li>
16+
</ul>
17+
18+
<p>移动 <code>n</code> 次之后,请你找出可以到达的距离原点 <strong>最远</strong> 的点,并返回 <strong>从原点到这一点的距离</strong> 。</p>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong>示例 1:</strong></p>
23+
24+
<pre>
25+
<strong>输入:</strong>moves = "L_RL__R"
26+
<strong>输出:</strong>3
27+
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 -3 ,移动的序列为 "LLRLLLR" 。
28+
</pre>
29+
30+
<p><strong>示例 2:</strong></p>
31+
32+
<pre>
33+
<strong>输入:</strong>moves = "_R__LL_"
34+
<strong>输出:</strong>5
35+
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 -5 ,移动的序列为 "LRLLLLL" 。
36+
</pre>
37+
38+
<p><strong>示例 3:</strong></p>
39+
40+
<pre>
41+
<strong>输入:</strong>moves = "_______"
42+
<strong>输出:</strong>7
43+
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 7 ,移动的序列为 "RRRRRRR" 。
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
48+
<p><strong>提示:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= moves.length == n &lt;= 50</code></li>
52+
<li><code>moves</code> 仅由字符 <code>'L'</code>、<code>'R'</code> 和 <code>'_'</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+
# [2833. Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin)
2+
3+
[中文文档](/solution/2800-2899/2833.Furthest%20Point%20From%20Origin/README.md)
4+
5+
## Description
6+
7+
<p>You are given a string <code>moves</code> of length <code>n</code> consisting only of characters <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and <code>&#39;_&#39;</code>. The string represents your movement on a number line starting from the origin <code>0</code>.</p>
8+
9+
<p>In the <code>i<sup>th</sup></code> move, you can choose one of the following directions:</p>
10+
11+
<ul>
12+
<li>move to the left if <code>moves[i] = &#39;L&#39;</code> or <code>moves[i] = &#39;_&#39;</code></li>
13+
<li>move to the right if <code>moves[i] = &#39;R&#39;</code> or <code>moves[i] = &#39;_&#39;</code></li>
14+
</ul>
15+
16+
<p>Return <em>the <strong>distance from the origin</strong> of the <strong>furthest</strong> point you can get to after </em><code>n</code><em> moves</em>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> moves = &quot;L_RL__R&quot;
23+
<strong>Output:</strong> 3
24+
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves &quot;LLRLLLR&quot;.
25+
</pre>
26+
27+
<p><strong class="example">Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> moves = &quot;_R__LL_&quot;
31+
<strong>Output:</strong> 5
32+
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves &quot;LRLLLLL&quot;.
33+
</pre>
34+
35+
<p><strong class="example">Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> moves = &quot;_______&quot;
39+
<strong>Output:</strong> 7
40+
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves &quot;RRRRRRR&quot;.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= moves.length == n &lt;= 50</code></li>
48+
<li><code>moves</code> consists only of characters <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code> and <code>&#39;_&#39;</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,103 @@
1+
# [2834. 找出美丽数组的最小和](https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array)
2+
3+
[English Version](/solution/2800-2899/2834.Find%20the%20Minimum%20Possible%20Sum%20of%20a%20Beautiful%20Array/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你两个正整数:<code>n</code> 和 <code>target</code> 。</p>
10+
11+
<p>如果数组 <code>nums</code> 满足下述条件,则称其为 <strong>美丽数组</strong> 。</p>
12+
13+
<ul>
14+
<li><code>nums.length == n</code>.</li>
15+
<li><code>nums</code> 由两两互不相同的正整数组成。</li>
16+
<li>在范围 <code>[0, n-1]</code> 内,<strong>不存在 </strong>两个 <strong>不同</strong> 下标 <code>i</code> 和 <code>j</code> ,使得 <code>nums[i] + nums[j] == target</code> 。</li>
17+
</ul>
18+
19+
<p>返回符合条件的美丽数组所可能具备的 <strong>最小</strong> 和。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong>示例 1:</strong></p>
24+
25+
<pre>
26+
<strong>输入:</strong>n = 2, target = 3
27+
<strong>输出:</strong>4
28+
<strong>解释:</strong>nums = [1,3] 是美丽数组。
29+
- nums 的长度为 n = 2 。
30+
- nums 由两两互不相同的正整数组成。
31+
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
32+
可以证明 4 是符合条件的美丽数组所可能具备的最小和。</pre>
33+
34+
<p><strong>示例 2:</strong></p>
35+
36+
<pre>
37+
<strong>输入:</strong>n = 3, target = 3
38+
<strong>输出:</strong>8
39+
<strong>解释:</strong>
40+
nums = [1,3,4] 是美丽数组。
41+
- nums 的长度为 n = 3 。
42+
- nums 由两两互不相同的正整数组成。
43+
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
44+
可以证明 8 是符合条件的美丽数组所可能具备的最小和。</pre>
45+
46+
<p><strong>示例 3:</strong></p>
47+
48+
<pre>
49+
<strong>输入:</strong>n = 1, target = 1
50+
<strong>输出:</strong>1
51+
<strong>解释:</strong>nums = [1] 是美丽数组。
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
56+
<p><strong>提示:</strong></p>
57+
58+
<ul>
59+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
60+
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
61+
</ul>
62+
63+
## 解法
64+
65+
<!-- 这里可写通用的实现逻辑 -->
66+
67+
<!-- tabs:start -->
68+
69+
### **Python3**
70+
71+
<!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+
```python
74+
75+
```
76+
77+
### **Java**
78+
79+
<!-- 这里可写当前语言的特殊实现逻辑 -->
80+
81+
```java
82+
83+
```
84+
85+
### **C++**
86+
87+
```cpp
88+
89+
```
90+
91+
### **Go**
92+
93+
```go
94+
95+
```
96+
97+
### **...**
98+
99+
```
100+
101+
```
102+
103+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# [2834. Find the Minimum Possible Sum of a Beautiful Array](https://leetcode.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array)
2+
3+
[中文文档](/solution/2800-2899/2834.Find%20the%20Minimum%20Possible%20Sum%20of%20a%20Beautiful%20Array/README.md)
4+
5+
## Description
6+
7+
<p>You are given positive integers <code>n</code> and <code>target</code>.</p>
8+
9+
<p>An array <code>nums</code> is <strong>beautiful</strong> if it meets the following conditions:</p>
10+
11+
<ul>
12+
<li><code>nums.length == n</code>.</li>
13+
<li><code>nums</code> consists of pairwise <strong>distinct</strong> <strong>positive</strong> integers.</li>
14+
<li>There doesn&#39;t exist two <strong>distinct</strong> indices, <code>i</code> and <code>j</code>, in the range <code>[0, n - 1]</code>, such that <code>nums[i] + nums[j] == target</code>.</li>
15+
</ul>
16+
17+
<p>Return <em>the <strong>minimum</strong> possible sum that a beautiful array could have</em>.</p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> n = 2, target = 3
24+
<strong>Output:</strong> 4
25+
<strong>Explanation:</strong> We can see that nums = [1,3] is beautiful.
26+
- The array nums has length n = 2.
27+
- The array nums consists of pairwise distinct positive integers.
28+
- There doesn&#39;t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
29+
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
30+
</pre>
31+
32+
<p><strong class="example">Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> n = 3, target = 3
36+
<strong>Output:</strong> 8
37+
<strong>Explanation:</strong> We can see that nums = [1,3,4] is beautiful.
38+
- The array nums has length n = 3.
39+
- The array nums consists of pairwise distinct positive integers.
40+
- There doesn&#39;t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
41+
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
42+
</pre>
43+
44+
<p><strong class="example">Example 3:</strong></p>
45+
46+
<pre>
47+
<strong>Input:</strong> n = 1, target = 1
48+
<strong>Output:</strong> 1
49+
<strong>Explanation:</strong> We can see, that nums = [1] is beautiful.
50+
</pre>
51+
52+
<p>&nbsp;</p>
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
57+
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
58+
</ul>
59+
60+
## Solutions
61+
62+
<!-- tabs:start -->
63+
64+
### **Python3**
65+
66+
```python
67+
68+
```
69+
70+
### **Java**
71+
72+
```java
73+
74+
```
75+
76+
### **C++**
77+
78+
```cpp
79+
80+
```
81+
82+
### **Go**
83+
84+
```go
85+
86+
```
87+
88+
### **...**
89+
90+
```
91+
92+
```
93+
94+
<!-- tabs:end -->

0 commit comments

Comments
 (0)