Skip to content

Commit 507a952

Browse files
committed
feat: update lc problems
1 parent ba2b770 commit 507a952

File tree

36 files changed

+1141
-669
lines changed

36 files changed

+1141
-669
lines changed

solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
## Description
66

7-
<p>Evaluate the value of an arithmetic expression in <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p>
7+
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p>
88

9-
<p>Valid operators are <code>+</code>, <code>-</code>, <code>*</code>, and <code>/</code>. Each operand may be an integer or another expression.</p>
9+
<p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p>
1010

11-
<p><strong>Note</strong> that division between two integers should truncate toward zero.</p>
11+
<p><strong>Note</strong> that:</p>
1212

13-
<p>It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation.</p>
13+
<ul>
14+
<li>The valid operators are <code>&#39;+&#39;</code>, <code>&#39;-&#39;</code>, <code>&#39;*&#39;</code>, and <code>&#39;/&#39;</code>.</li>
15+
<li>Each operand may be an integer or another expression.</li>
16+
<li>The division between two integers always <strong>truncates toward zero</strong>.</li>
17+
<li>There will not be any division by zero.</li>
18+
<li>The input represents a valid arithmetic expression in a reverse polish notation.</li>
19+
<li>The answer and all the intermediate calculations can be represented in a <strong>32-bit</strong> integer.</li>
20+
</ul>
1421

1522
<p>&nbsp;</p>
1623
<p><strong class="example">Example 1:</strong></p>

solution/0300-0399/0335.Self Crossing/README_EN.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,33 @@
66

77
<p>You are given an array of integers <code>distance</code>.</p>
88

9-
<p>You start at point <code>(0,0)</code> on an <strong>X-Y</strong> plane and you move <code>distance[0]</code> meters to the north, then <code>distance[1]</code> meters to the west, <code>distance[2]</code> meters to the south, <code>distance[3]</code> meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.</p>
9+
<p>You start at the point <code>(0, 0)</code> on an <strong>X-Y plane,</strong> and you move <code>distance[0]</code> meters to the north, then <code>distance[1]</code> meters to the west, <code>distance[2]</code> meters to the south, <code>distance[3]</code> meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.</p>
1010

11-
<p>Return <code>true</code> if your path crosses itself, and <code>false</code> if it does not.</p>
11+
<p>Return <code>true</code> <em>if your path crosses itself or </em><code>false</code><em> if it does not</em>.</p>
1212

1313
<p>&nbsp;</p>
1414
<p><strong class="example">Example 1:</strong></p>
15-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0335.Self%20Crossing/images/selfcross1-plane.jpg" style="width: 400px; height: 435px;" />
15+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0335.Self%20Crossing/images/11.jpg" style="width: 400px; height: 413px;" />
1616
<pre>
1717
<strong>Input:</strong> distance = [2,1,1,2]
1818
<strong>Output:</strong> true
19+
<strong>Explanation:</strong> The path crosses itself at the point (0, 1).
1920
</pre>
2021

2122
<p><strong class="example">Example 2:</strong></p>
22-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0335.Self%20Crossing/images/selfcross2-plane.jpg" style="width: 400px; height: 435px;" />
23+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0335.Self%20Crossing/images/22.jpg" style="width: 400px; height: 413px;" />
2324
<pre>
2425
<strong>Input:</strong> distance = [1,2,3,4]
2526
<strong>Output:</strong> false
27+
<strong>Explanation:</strong> The path does not cross itself at any point.
2628
</pre>
2729

2830
<p><strong class="example">Example 3:</strong></p>
29-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0335.Self%20Crossing/images/selfcross3-plane.jpg" style="width: 400px; height: 435px;" />
31+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0335.Self%20Crossing/images/33.jpg" style="width: 400px; height: 413px;" />
3032
<pre>
31-
<strong>Input:</strong> distance = [1,1,1,1]
33+
<strong>Input:</strong> distance = [1,1,1,2,1]
3234
<strong>Output:</strong> true
35+
<strong>Explanation:</strong> The path crosses itself at the point (0, 0).
3336
</pre>
3437

3538
<p>&nbsp;</p>

solution/0400-0499/0491.Increasing Subsequences/README.md renamed to solution/0400-0499/0491.Non-decreasing Subsequences/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# [491. 递增子序列](https://leetcode.cn/problems/increasing-subsequences)
1+
# [491. 递增子序列](https://leetcode.cn/problems/non-decreasing-subsequences)
22

3-
[English Version](/solution/0400-0499/0491.Increasing%20Subsequences/README_EN.md)
3+
[English Version](/solution/0400-0499/0491.Non-decreasing%20Subsequences/README_EN.md)
44

55
## 题目描述
66

solution/0400-0499/0491.Increasing Subsequences/README_EN.md renamed to solution/0400-0499/0491.Non-decreasing Subsequences/README_EN.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# [491. Increasing Subsequences](https://leetcode.com/problems/increasing-subsequences)
1+
# [491. Non-decreasing Subsequences](https://leetcode.com/problems/non-decreasing-subsequences)
22

3-
[中文文档](/solution/0400-0499/0491.Increasing%20Subsequences/README.md)
3+
[中文文档](/solution/0400-0499/0491.Non-decreasing%20Subsequences/README.md)
44

55
## Description
66

7-
<p>Given an integer array <code>nums</code>, return all the different possible increasing subsequences of the given array with <strong>at least two elements</strong>. You may return the answer in <strong>any order</strong>.</p>
8-
9-
<p>The given array may contain duplicates, and two equal integers should also be considered a special case of increasing sequence.</p>
7+
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p>
108

119
<p>&nbsp;</p>
1210
<p><strong class="example">Example 1:</strong></p>
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
class Solution {
2-
public:
3-
vector<vector<int>> findSubsequences(vector<int>& nums) {
4-
vector<vector<int>> ans;
5-
vector<int> t;
6-
dfs(0, -1000, t, nums, ans);
7-
return ans;
8-
}
9-
10-
void dfs(int u, int last, vector<int>& t, vector<int>& nums, vector<vector<int>>& ans) {
11-
if (u == nums.size()) {
12-
if (t.size() > 1) ans.push_back(t);
13-
return;
14-
}
15-
if (nums[u] >= last) {
16-
t.push_back(nums[u]);
17-
dfs(u + 1, nums[u], t, nums, ans);
18-
t.pop_back();
19-
}
20-
if (nums[u] != last) dfs(u + 1, last, t, nums, ans);
21-
}
1+
class Solution {
2+
public:
3+
vector<vector<int>> findSubsequences(vector<int>& nums) {
4+
vector<vector<int>> ans;
5+
vector<int> t;
6+
dfs(0, -1000, t, nums, ans);
7+
return ans;
8+
}
9+
10+
void dfs(int u, int last, vector<int>& t, vector<int>& nums, vector<vector<int>>& ans) {
11+
if (u == nums.size()) {
12+
if (t.size() > 1) ans.push_back(t);
13+
return;
14+
}
15+
if (nums[u] >= last) {
16+
t.push_back(nums[u]);
17+
dfs(u + 1, nums[u], t, nums, ans);
18+
t.pop_back();
19+
}
20+
if (nums[u] != last) dfs(u + 1, last, t, nums, ans);
21+
}
2222
};
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
func findSubsequences(nums []int) [][]int {
2-
var ans [][]int
3-
var dfs func(u, last int, t []int)
4-
dfs = func(u, last int, t []int) {
5-
if u == len(nums) {
6-
if len(t) > 1 {
7-
cp := make([]int, len(t))
8-
copy(cp, t)
9-
ans = append(ans, cp)
10-
}
11-
return
12-
}
13-
if nums[u] >= last {
14-
t = append(t, nums[u])
15-
dfs(u+1, nums[u], t)
16-
t = t[:len(t)-1]
17-
}
18-
if nums[u] != last {
19-
dfs(u+1, last, t)
20-
}
21-
}
22-
var t []int
23-
dfs(0, -1000, t)
24-
return ans
1+
func findSubsequences(nums []int) [][]int {
2+
var ans [][]int
3+
var dfs func(u, last int, t []int)
4+
dfs = func(u, last int, t []int) {
5+
if u == len(nums) {
6+
if len(t) > 1 {
7+
cp := make([]int, len(t))
8+
copy(cp, t)
9+
ans = append(ans, cp)
10+
}
11+
return
12+
}
13+
if nums[u] >= last {
14+
t = append(t, nums[u])
15+
dfs(u+1, nums[u], t)
16+
t = t[:len(t)-1]
17+
}
18+
if nums[u] != last {
19+
dfs(u+1, last, t)
20+
}
21+
}
22+
var t []int
23+
dfs(0, -1000, t)
24+
return ans
2525
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
class Solution {
2-
private int[] nums;
3-
private List<List<Integer>> ans;
4-
5-
public List<List<Integer>> findSubsequences(int[] nums) {
6-
this.nums = nums;
7-
ans = new ArrayList<>();
8-
dfs(0, -1000, new ArrayList<>());
9-
return ans;
10-
}
11-
12-
private void dfs(int u, int last, List<Integer> t) {
13-
if (u == nums.length) {
14-
if (t.size() > 1) {
15-
ans.add(new ArrayList<>(t));
16-
}
17-
return;
18-
}
19-
if (nums[u] >= last) {
20-
t.add(nums[u]);
21-
dfs(u + 1, nums[u], t);
22-
t.remove(t.size() - 1);
23-
}
24-
if (nums[u] != last) {
25-
dfs(u + 1, last, t);
26-
}
27-
}
1+
class Solution {
2+
private int[] nums;
3+
private List<List<Integer>> ans;
4+
5+
public List<List<Integer>> findSubsequences(int[] nums) {
6+
this.nums = nums;
7+
ans = new ArrayList<>();
8+
dfs(0, -1000, new ArrayList<>());
9+
return ans;
10+
}
11+
12+
private void dfs(int u, int last, List<Integer> t) {
13+
if (u == nums.length) {
14+
if (t.size() > 1) {
15+
ans.add(new ArrayList<>(t));
16+
}
17+
return;
18+
}
19+
if (nums[u] >= last) {
20+
t.add(nums[u]);
21+
dfs(u + 1, nums[u], t);
22+
t.remove(t.size() - 1);
23+
}
24+
if (nums[u] != last) {
25+
dfs(u + 1, last, t);
26+
}
27+
}
2828
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
class Solution:
2-
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
3-
def dfs(u, last, t):
4-
if u == len(nums):
5-
if len(t) > 1:
6-
ans.append(t[:])
7-
return
8-
if nums[u] >= last:
9-
t.append(nums[u])
10-
dfs(u + 1, nums[u], t)
11-
t.pop()
12-
if nums[u] != last:
13-
dfs(u + 1, last, t)
14-
15-
ans = []
16-
dfs(0, -1000, [])
17-
return ans
1+
class Solution:
2+
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
3+
def dfs(u, last, t):
4+
if u == len(nums):
5+
if len(t) > 1:
6+
ans.append(t[:])
7+
return
8+
if nums[u] >= last:
9+
t.append(nums[u])
10+
dfs(u + 1, nums[u], t)
11+
t.pop()
12+
if nums[u] != last:
13+
dfs(u + 1, last, t)
14+
15+
ans = []
16+
dfs(0, -1000, [])
17+
return ans

solution/1200-1299/1222.Queens That Can Attack the King/README_EN.md

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,37 @@
44

55
## Description
66

7-
<p>On an <strong>8x8</strong> chessboard, there can be multiple Black Queens and one White King.</p>
7+
<p>On a <strong>0-indexed</strong> <code>8 x 8</code> chessboard, there can be multiple black queens ad one white king.</p>
88

9-
<p>Given an array of integer coordinates <code>queens</code> that represents the positions of the Black Queens, and a pair of coordinates <code>king</code> that represent the position of the White King, return the coordinates of all the queens (in any order) that can attack the King.</p>
10-
<p>&nbsp;</p>
11-
<p><strong class="example">Example 1:</strong></p>
9+
<p>You are given a 2D integer array <code>queens</code> where <code>queens[i] = [xQueen<sub>i</sub>, yQueen<sub>i</sub>]</code> represents the position of the <code>i<sup>th</sup></code> black queen on the chessboard. You are also given an integer array <code>king</code> of length <code>2</code> where <code>king = [xKing, yKing]</code> represents the position of the white king.</p>
1210

13-
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/images/untitled-diagram.jpg" style="width: 321px; height: 321px;" /></p>
11+
<p>Return <em>the coordinates of the black queens that can directly attack the king</em>. You may return the answer in <strong>any order</strong>.</p>
1412

13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/images/chess1.jpg" style="width: 400px; height: 400px;" />
1516
<pre>
16-
1717
<strong>Input:</strong> queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]
18-
1918
<strong>Output:</strong> [[0,1],[1,0],[3,3]]
20-
21-
<strong>Explanation:</strong>&nbsp;
22-
23-
The queen at [0,1] can attack the king cause they&#39;re in the same row.
24-
25-
The queen at [1,0] can attack the king cause they&#39;re in the same column.
26-
27-
The queen at [3,3] can attack the king cause they&#39;re in the same diagnal.
28-
29-
The queen at [0,4] can&#39;t attack the king cause it&#39;s blocked by the queen at [0,1].
30-
31-
The queen at [4,0] can&#39;t attack the king cause it&#39;s blocked by the queen at [1,0].
32-
33-
The queen at [2,4] can&#39;t attack the king cause it&#39;s not in the same row/column/diagnal as the king.
34-
19+
<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).
3520
</pre>
3621

3722
<p><strong class="example">Example 2:</strong></p>
38-
39-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/images/untitled-diagram-1.jpg" style="width: 321px; height: 321px;" /></strong></p>
40-
23+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/images/chess2.jpg" style="width: 400px; height: 400px;" />
4124
<pre>
42-
4325
<strong>Input:</strong> queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]
44-
4526
<strong>Output:</strong> [[2,2],[3,4],[4,4]]
46-
27+
<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).
4728
</pre>
4829

49-
<p><strong class="example">Example 3:</strong></p>
50-
51-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/images/untitled-diagram-2.jpg" style="width: 321px; height: 321px;" /></strong></p>
52-
53-
<pre>
54-
55-
<strong>Input:</strong> queens = [[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[4,5],[5,2],[1,4],[7,5],[2,3],[0,5],[4,2],[1,0],[2,7],[0,1],[4,6],[6,1],[0,6],[4,3],[1,7]], king = [3,4]
56-
57-
<strong>Output:</strong> [[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]
58-
59-
</pre>
6030
<p>&nbsp;</p>
6131
<p><strong>Constraints:</strong></p>
6232

6333
<ul>
64-
<li><code>1 &lt;= queens.length&nbsp;&lt;= 63</code></li>
65-
<li><code>queens[i].length == 2</code></li>
66-
<li><code>0 &lt;= queens[i][j] &lt;&nbsp;8</code></li>
67-
<li><code>king.length == 2</code></li>
68-
<li><code>0 &lt;= king[0], king[1] &lt; 8</code></li>
69-
<li>At most one piece is allowed in a cell.</li>
34+
<li><code>1 &lt;= queens.length &lt; 64</code></li>
35+
<li><code>queens[i].length == king.length == 2</code></li>
36+
<li><code>0 &lt;= xQueen<sub>i</sub>, yQueen<sub>i</sub>, xKing, yKing &lt; 8</code></li>
37+
<li>All the given positions are <strong>unique</strong>.</li>
7038
</ul>
7139

7240
## Solutions

solution/1700-1799/1765.Map of Highest Peak/README_EN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Solution {
168168
}
169169
}
170170
}
171-
171+
172172
}
173173
return ans;
174174
}
@@ -181,7 +181,7 @@ class Solution {
181181
class Solution {
182182
public:
183183
const int dirs[5] = {-1, 0, 1, 0, -1};
184-
184+
185185
vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
186186
int m = isWater.size(), n = isWater[0].size();
187187
vector<vector<int>> ans(m, vector<int>(n));
@@ -214,7 +214,7 @@ public:
214214
class Solution {
215215
public:
216216
const int dirs[5] = {-1, 0, 1, 0, -1};
217-
217+
218218
vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
219219
int m = isWater.size(), n = isWater[0].size();
220220
vector<vector<int>> ans(m, vector<int>(n));
@@ -239,7 +239,7 @@ public:
239239
}
240240
}
241241
}
242-
242+
243243
}
244244
return ans;
245245
}

0 commit comments

Comments
 (0)