Skip to content

Commit 18dbf9d

Browse files
authored
feat: add new lc problems and solutions (doocs#1120)
1 parent 5f99195 commit 18dbf9d

File tree

56 files changed

+3222
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3222
-274
lines changed

Diff for: .github/workflows/clang-format-lint.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
inplace: True
2020

2121
- uses: EndBug/add-and-commit@v9
22-
with:
23-
committer_name: yanglbme
24-
committer_email: contact@yanglibin.info
25-
message: 'chore: format code with clang-format'
26-
env:
27-
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}
22+
with:
23+
committer_name: yanglbme
24+
committer_email: contact@yanglibin.info
25+
message: 'chore: format code with clang-format'
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}

Diff for: solution/0000-0099/0074.Search a 2D Matrix/README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>编写一个高效的算法来判断 <code>m x n</code> 矩阵中,是否存在一个目标值。该矩阵具有如下特性:</p>
9+
<p>给你一个满足下述两条属性的 <code>m x n</code> 整数矩阵:</p>
1010

1111
<ul>
12-
<li>每行中的整数从左到右按升序排列。</li>
12+
<li>每行中的整数从左到右按非递减顺序排列。</li>
1313
<li>每行的第一个整数大于前一行的最后一个整数。</li>
1414
</ul>
1515

16-
<p> </p>
16+
<p>给你一个整数 <code>target</code> ,如果 <code>target</code> 在矩阵中,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p>
17+
18+
<p>&nbsp;</p>
1719

1820
<p><strong>示例 1:</strong></p>
1921
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0074.Search%20a%202D%20Matrix/images/mat.jpg" style="width: 322px; height: 242px;" />
@@ -29,15 +31,15 @@
2931
<strong>输出:</strong>false
3032
</pre>
3133

32-
<p> </p>
34+
<p>&nbsp;</p>
3335

3436
<p><strong>提示:</strong></p>
3537

3638
<ul>
3739
<li><code>m == matrix.length</code></li>
3840
<li><code>n == matrix[i].length</code></li>
39-
<li><code>1 <= m, n <= 100</code></li>
40-
<li><code>-10<sup>4</sup> <= matrix[i][j], target <= 10<sup>4</sup></code></li>
41+
<li><code>1 &lt;= m, n &lt;= 100</code></li>
42+
<li><code>-10<sup>4</sup> &lt;= matrix[i][j], target &lt;= 10<sup>4</sup></code></li>
4143
</ul>
4244

4345
## 解法

Diff for: solution/0300-0399/0373.Find K Pairs with Smallest Sums/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>ascending order</strong> and an integer <code>k</code>.</p>
7+
<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing&nbsp;order</strong> and an integer <code>k</code>.</p>
88

99
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
1010

@@ -41,7 +41,7 @@
4141
<ul>
4242
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li>
4343
<li><code>-10<sup>9</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>9</sup></code></li>
44-
<li><code>nums1</code> and <code>nums2</code> both are sorted in <strong>ascending order</strong>.</li>
44+
<li><code>nums1</code> and <code>nums2</code> both are sorted in <strong>non-decreasing order</strong>.</li>
4545
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
4646
</ul>
4747

Diff for: solution/1500-1599/1511.Customer Order Frequency/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ Winston 在2020年6月花费了300(300 * 1), 在7月花费了100(10 * 1 + 45 * 2
113113
Jonathan 在2020年6月花费了600(300 * 2), 在7月花费了20(2 * 10).
114114
Moustafa 在2020年6月花费了110 (10 * 2 + 45 * 2), 在7月花费了0.</pre>
115115

116-
117116
## 解法
118117

119118
<!-- 这里可写通用的实现逻辑 -->

Diff for: solution/1500-1599/1511.Customer Order Frequency/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ Jonathan spent 600 (300 * 2) in June and 20 ( 2 * 10) in July 2020.
110110
Moustafa spent 110 (10 * 2 + 45 * 2) in June and 0 in July 2020.
111111
</pre>
112112

113-
114113
## Solutions
115114

116115
<!-- tabs:start -->

Diff for: solution/2400-2499/2448.Minimum Cost to Make Array Equal/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ It can be shown that we cannot make the array equal with a smaller cost.
4545
<li><code>n == nums.length == cost.length</code></li>
4646
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
4747
<li><code>1 &lt;= nums[i], cost[i] &lt;= 10<sup>6</sup></code></li>
48+
<li>Test cases are generated in a way that the output doesn&#39;t exceed&nbsp;2<sup>53</sup>-1</li>
4849
</ul>
4950

5051
## Solutions

Diff for: solution/2400-2499/2490.Circular Sentence/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<strong>输入:</strong>sentence = "eetcode"
4646
<strong>输出:</strong>true
4747
<strong>解释:</strong>句子中的单词是 ["eetcode"] 。
48-
- eetcod<em><strong>e</strong></em> 的最后一个字符和 eetcod<em><strong>e</strong></em> 的第一个字符相等。
48+
- eetcod<em><strong>e</strong></em> 的最后一个字符和 <em><strong>e</strong></em>etcod<em>e</em> 的第一个字符相等。
4949
这个句子是回环句。</pre>
5050

5151
<p><strong>示例 3:</strong></p>
@@ -54,7 +54,7 @@
5454
<strong>输入:</strong>sentence = "Leetcode is cool"
5555
<strong>输出:</strong>false
5656
<strong>解释:</strong>句子中的单词是 ["Leetcode", "is", "cool"] 。
57-
- Leetcod<em><strong>e</strong></em>&nbsp;的最后一个字符和 i<strong><em>s</em></strong> 的第一个字符 <strong>不</strong> 相等。
57+
- Leetcod<em><strong>e</strong></em>&nbsp;的最后一个字符和 <em><strong>i</strong></em>s 的第一个字符 <strong>不</strong> 相等。
5858
这个句子 <strong>不</strong> 是回环句。</pre>
5959

6060
<p>&nbsp;</p>

Diff for: solution/2600-2699/2627.Debounce/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<p>Given a function&nbsp;<code>fn</code> and a time in milliseconds&nbsp;<code>t</code>, return&nbsp;a&nbsp;<strong>debounced</strong>&nbsp;version of that function.</p>
88

9-
<p>A&nbsp;<strong>debounced</strong>&nbsp;function is a function whose execution is delayed by&nbsp;<code>t</code>&nbsp;milliseconds and whose&nbsp;execution is cancelled if it is called again within that window of time. The debounced function should also recieve the passed parameters.</p>
9+
<p>A&nbsp;<strong>debounced</strong>&nbsp;function is a function whose execution is delayed by&nbsp;<code>t</code>&nbsp;milliseconds and whose&nbsp;execution is cancelled if it is called again within that window of time. The debounced function should also receive the passed parameters.</p>
1010

1111
<p>For example, let&#39;s say&nbsp;<code>t = 50ms</code>, and the function was called at&nbsp;<code>30ms</code>,&nbsp;<code>60ms</code>, and <code>100ms</code>. The first 2 function calls would be cancelled, and the 3rd function call would be executed at&nbsp;<code>150ms</code>. If instead&nbsp;<code>t = 35ms</code>, The 1st call would be cancelled, the 2nd would be executed at&nbsp;<code>95ms</code>, and the 3rd would be executed at&nbsp;<code>135ms</code>.</p>
1212

Diff for: solution/2600-2699/2693.Call Function with Custom Context/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ callPolyfill sets the &quot;this&quot; context to {&quot;a&quot;: 5}. 7 is passe
4343
fn = function tax(price, taxRate) {
4444
&nbsp;return `The cost of the ${this.item} is ${price * taxRate}`;
4545
}
46-
args = [{&quot;item&quot;: &quot;burger&quot;}, 10, 1,1]
46+
args = [{&quot;item&quot;: &quot;burger&quot;}, 10, 1.1]
4747
<strong>Output:</strong> &quot;The cost of the burger is 11&quot;
4848
<strong>Explanation:</strong> callPolyfill sets the &quot;this&quot; context to {&quot;item&quot;: &quot;burger&quot;}. 10 and 1.1 are passed as additional arguments.
4949
</pre>

Diff for: solution/2600-2699/2695.Array Wrapper/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>Create a class&nbsp;<code>ArrayWrapper</code> that accepts&nbsp;an array of integers in it&#39;s constructor. This class should have two features:</p>
7+
<p>Create a class&nbsp;<code>ArrayWrapper</code> that accepts&nbsp;an array of integers in its constructor. This class should have two features:</p>
88

99
<ul>
1010
<li>When two instances of this class are added together with the&nbsp;<code>+</code>&nbsp;operator, the resulting value is the sum of all the elements in&nbsp;both arrays.</li>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [2753. 计算一个环形街道上的房屋数量 II](https://leetcode.cn/problems/count-houses-in-a-circular-street-ii)
2+
3+
[English Version](/solution/2700-2799/2753.Count%20Houses%20in%20a%20Circular%20Street%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给定一个代表 <strong>环形 </strong>街道的类 <code>Street</code> 和一个正整数 <code>k</code>,表示街道上房屋的最大数量(也就是说房屋数量不超过 <code>k</code>)。每个房屋的门初始时可以是开着的也可以是关着的(至少有一个房屋的门是开着的)。</p>
10+
11+
<p>刚开始,你站在一座房子的门前。你的任务是计算街道上的房屋数量。</p>
12+
13+
<p><code>Street</code> 类包含以下函数:</p>
14+
15+
<ul>
16+
<li><code>void closeDoor()</code>:关闭当前房屋的门。</li>
17+
<li><code>boolean isDoorOpen()</code>:如果当前房屋的门是开着的返回 <code>true</code>,否则返回 <code>false</code>。</li>
18+
<li><code>void moveRight()</code>:向右移动到下一座房屋。</li>
19+
</ul>
20+
21+
<p><strong>注意:</strong>在<strong> 环形 </strong>街道内,如果将房屋从 <code>1</code> 到 <code>n</code> 编号,则当 <code>i &lt; n</code> 时&nbsp;<code>house<sub>i</sub></code> 右边的房子是&nbsp;<code>house<sub>i+1</sub></code>,<code>house<sub>n</sub></code> 右边的房子是&nbsp;<code>house<sub>1</sub></code>。</p>
22+
23+
<p>返回 <code>ans</code>,它表示街道上的房屋数量。</p>
24+
25+
<p>&nbsp;</p>
26+
27+
<p><strong>示例 1:</strong></p>
28+
29+
<pre>
30+
<b>输入:</b>street = [1,1,1,1], k = 10
31+
<b>输出:</b>4
32+
<b>解释:</b>街道上有 4 座房屋,它们的门都是关着的。
33+
房屋数量小于 k,即 10。</pre>
34+
35+
<p><strong>示例 2:</strong></p>
36+
37+
<pre>
38+
<b>输入:</b>street = [1,0,1,1,0], k = 5
39+
<b>输出:</b>5
40+
<strong>解释:</strong>街道上有 5 座房屋,向右移动时第 1、3 和 4 座房屋的门是开着的,其余的门都是关着的。
41+
房屋数量等于 k,即 5。
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
46+
<p><strong>提示:</strong></p>
47+
48+
<ul>
49+
<li><code>n</code>&nbsp;是房屋数量</li>
50+
<li><code>1 &lt;= n &lt;= k &lt;= 10<sup>5</sup></code></li>
51+
<li><code>street</code>&nbsp;是环形的</li>
52+
<li>输入数据中至少有一扇门是开着的</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+
# [2753. Count Houses in a Circular Street II](https://leetcode.com/problems/count-houses-in-a-circular-street-ii)
2+
3+
[中文文档](/solution/2700-2799/2753.Count%20Houses%20in%20a%20Circular%20Street%20II/README.md)
4+
5+
## Description
6+
7+
<p>You are given an object <code>street</code> of class <code>Street</code> that represents a <strong>circular</strong> street and a positive integer <code>k</code> which represents a maximum bound for the number of houses in that street (in other words, the number of houses is less than or equal to <code>k</code>). Houses&#39; doors could be open or closed initially (at least one is open).</p>
8+
9+
<p>Initially, you are standing in front of a door to a house on this street. Your task is to count the number of houses in the street.</p>
10+
11+
<p>The class <code>Street</code> contains the following functions which may help you:</p>
12+
13+
<ul>
14+
<li><code>void closeDoor()</code>: Close the door of the house you are in front of.</li>
15+
<li><code>boolean isDoorOpen()</code>: Returns <code>true</code> if the door of the current house is open and <code>false</code> otherwise.</li>
16+
<li><code>void moveRight()</code>: Move to the right house.</li>
17+
</ul>
18+
19+
<p><strong>Note</strong> that by <strong>circular</strong> street, we mean if you number the houses from <code>1</code> to <code>n</code>, then the right house of <code>house<sub>i</sub></code> is <code>house<sub>i+1</sub></code> for <code>i &lt; n</code>, and the right house of <code>house<sub>n</sub></code> is <code>house<sub>1</sub></code>.</p>
20+
21+
<p>Return <code>ans</code> <em>which represents the number of houses on this street.</em></p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> street = [1,1,1,1], k = 10
28+
<strong>Output:</strong> 4
29+
<strong>Explanation:</strong> There are 4 houses, and all their doors are open.
30+
The number of houses is less than k, which is 10.</pre>
31+
32+
<p><strong class="example">Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> street = [1,0,1,1,0], k = 5
36+
<strong>Output:</strong> 5
37+
<strong>Explanation:</strong> There are 5 houses, and the doors of the 1st, 3rd, and 4th house (moving in the right direction) are open, and the rest are closed.
38+
The number of houses is equal to k, which is 5.
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>n == number of houses</code></li>
46+
<li><code>1 &lt;= n &lt;= k &lt;= 10<sup>5</sup></code></li>
47+
<li><code>street</code> is circular by definition provided in the statement.</li>
48+
<li>The input is generated such that at least one of the doors is open.</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 -->

0 commit comments

Comments
 (0)