Skip to content

Commit e1cda29

Browse files
committed
feat: update lc problems
1 parent d4ed399 commit e1cda29

File tree

24 files changed

+473
-81
lines changed

24 files changed

+473
-81
lines changed

solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Solution:
8282
ans.append(node.val)
8383
dfs(node.right, depth + 1)
8484
dfs(node.left, depth + 1)
85-
85+
8686
ans = []
8787
dfs(root, 0)
8888
return ans

solution/0200-0299/0202.Happy Number/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Solution:
7272
x, v = divmod(x, 10)
7373
y += v * v
7474
return y
75-
75+
7676
slow, fast = n, next(n)
7777
while slow != fast:
7878
slow, fast = next(slow), next(next(fast))

solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md

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

55
## Description
66

7-
<p><code>RandomizedCollection</code> is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also removing a random element.</p>
7+
<p><code>RandomizedCollection</code> is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also reporting a random element.</p>
88

99
<p>Implement the <code>RandomizedCollection</code> class:</p>
1010

1111
<ul>
1212
<li><code>RandomizedCollection()</code> Initializes the empty <code>RandomizedCollection</code> object.</li>
1313
<li><code>bool insert(int val)</code> Inserts an item <code>val</code> into the multiset, even if the item is already present. Returns <code>true</code> if the item is not present, <code>false</code> otherwise.</li>
1414
<li><code>bool remove(int val)</code> Removes an item <code>val</code> from the multiset if present. Returns <code>true</code> if the item is present, <code>false</code> otherwise. Note that if <code>val</code> has multiple occurrences in the multiset, we only remove one of them.</li>
15-
<li><code>int getRandom()</code> Returns a random element from the current multiset of elements. The probability of each element being returned is <strong>linearly related</strong> to the number of same values the multiset contains.</li>
15+
<li><code>int getRandom()</code> Returns a random element from the current multiset of elements. The probability of each element being returned is <strong>linearly related</strong> to the number of the same values the multiset contains.</li>
1616
</ul>
1717

1818
<p>You must implement the functions of the class such that each function works on <strong>average</strong> <code>O(1)</code> time complexity.</p>

solution/0900-0999/0909.Snakes and Ladders/README_EN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
<ul>
1212
<li>Choose a destination square <code>next</code> with a label in the range <code>[curr + 1, min(curr + 6, n<sup>2</sup>)]</code>.
13-
1413
<ul>
1514
<li>This choice simulates the result of a standard <strong>6-sided die roll</strong>: i.e., there are always at most 6 destinations, regardless of the size of the board.</li>
1615
</ul>
1716
</li>
1817
<li>If <code>next</code> has a snake or ladder, you <strong>must</strong> move to the destination of that snake or ladder. Otherwise, you move to <code>next</code>.</li>
1918
<li>The game ends when you reach the square <code>n<sup>2</sup></code>.</li>
20-
2119
</ul>
2220

2321
<p>A board square on row <code>r</code> and column <code>c</code> has a snake or ladder if <code>board[r][c] != -1</code>. The destination of that snake or ladder is <code>board[r][c]</code>. Squares <code>1</code> and <code>n<sup>2</sup></code> do not have a snake or ladder.</p>
@@ -58,7 +56,7 @@ This is the lowest possible number of moves to reach the last square, so return
5856
<ul>
5957
<li><code>n == board.length == board[i].length</code></li>
6058
<li><code>2 &lt;= n &lt;= 20</code></li>
61-
<li><code>grid[i][j]</code> is either <code>-1</code> or in the range <code>[1, n<sup>2</sup>]</code>.</li>
59+
<li><code>board[i][j]</code> is either <code>-1</code> or in the range <code>[1, n<sup>2</sup>]</code>.</li>
6260
<li>The squares labeled <code>1</code> and <code>n<sup>2</sup></code> do not have any ladders or snakes.</li>
6361
</ul>
6462

solution/0900-0999/0997.Find the Town Judge/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<li>There is exactly one person that satisfies properties <strong>1</strong> and <strong>2</strong>.</li>
1515
</ol>
1616

17-
<p>You are given an array <code>trust</code> where <code>trust[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> representing that the person labeled <code>a<sub>i</sub></code> trusts the person labeled <code>b<sub>i</sub></code>.</p>
17+
<p>You are given an array <code>trust</code> where <code>trust[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> representing that the person labeled <code>a<sub>i</sub></code> trusts the person labeled <code>b<sub>i</sub></code>. If a trust relationship does not exist in <code>trust</code> array, then such a trust relationship does not exist.</p>
1818

1919
<p>Return <em>the label of the town judge if the town judge exists and can be identified, or return </em><code>-1</code><em> otherwise</em>.</p>
2020

solution/1200-1299/1236.Web Crawler/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ interface HtmlParser {
3131

3232
<p>Below&nbsp;are two examples explaining the functionality of the problem, for custom testing purposes you&#39;ll have three&nbsp;variables&nbsp;<code data-stringify-type="code">urls</code>,&nbsp;<code data-stringify-type="code">edges</code>&nbsp;and&nbsp;<code data-stringify-type="code">startUrl</code>. Notice that you will only have access to&nbsp;<code data-stringify-type="code">startUrl</code>&nbsp;in your code, while&nbsp;<code data-stringify-type="code">urls</code>&nbsp;and&nbsp;<code data-stringify-type="code">edges</code>&nbsp;are not directly accessible to you in code.</p>
3333

34+
<p>Note: Consider the same URL with the trailing slash &quot;/&quot; as a different URL. For example, &quot;http://news.yahoo.com&quot;, and &quot;http://news.yahoo.com/&quot; are different urls.</p>
35+
3436
<p>&nbsp;</p>
3537
<p><strong class="example">Example 1:</strong></p>
3638

solution/1600-1699/1616.Split Two Strings to Make Palindrome/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ b<sub>prefix</sub> = "jiz", b<sub>suffix</sub> = "alu"
6060

6161
**方法一:双指针**
6262

63-
- 首先,一个指针从 `a` 的头开始,另一个指针从 `b` 的尾开始,如果字符相等,两个指针就往中间移动,遇到不同的字符或双指针交叉后停止
64-
- 双指针交叉说明 `prefix``suffix` 已经可以得到回文串
65-
- 否则还需要判断 `a[i:j+1]``b[i:j+1]` 是否是回文(通过 `prefix + palindrome + suffix` 得到回文串)
66-
- 如果还得不到回文串,尝试交换 `a`, `b` 重复同样的判断
63+
- 首先,一个指针从 `a` 的头开始,另一个指针从 `b` 的尾开始,如果字符相等,两个指针就往中间移动,遇到不同的字符或双指针交叉后停止
64+
- 双指针交叉说明 `prefix``suffix` 已经可以得到回文串
65+
- 否则还需要判断 `a[i:j+1]``b[i:j+1]` 是否是回文(通过 `prefix + palindrome + suffix` 得到回文串)
66+
- 如果还得不到回文串,尝试交换 `a`, `b` 重复同样的判断
6767

6868
<!-- tabs:start -->
6969

solution/1600-1699/1634.Add Two Polynomials Represented as Linked Lists/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Solution:
123123
* class PolyNode {
124124
* int coefficient, power;
125125
* PolyNode next = null;
126-
126+
127127
* PolyNode() {}
128128
* PolyNode(int x, int y) { this.coefficient = x; this.power = y; }
129129
* PolyNode(int x, int y, PolyNode next) { this.coefficient = x; this.power = y; this.next = next; }

solution/2500-2599/2533.Number of Good Binary Strings/README.md

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
# [2533. Number of Good Binary Strings](https://leetcode.cn/problems/number-of-good-binary-strings)
1+
# [2533. 好二进制字符串的数量](https://leetcode.cn/problems/number-of-good-binary-strings)
22

33
[English Version](/solution/2500-2599/2533.Number%20of%20Good%20Binary%20Strings/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>You are given four integers <code>minLenght</code>, <code>maxLength</code>, <code>oneGroup</code> and <code>zeroGroup</code>.</p>
9+
<p><span style="">给你四个整数 </span><code>minLenght</code><code>maxLength</code><code>oneGroup</code><span style=""> 和 </span><code>zeroGroup</code><span style=""> 。</span></p>
1010

11-
<p>A binary string is <strong>good</strong> if it satisfies the following conditions:</p>
11+
<p><strong></strong>二进制字符串满足下述条件:</p>
1212

1313
<ul>
14-
<li>The length of the string is in the range <code>[minLength, maxLength]</code>.</li>
15-
<li>The size of each block of consecutive <code>1</code>&#39;s is a multiple of <code>oneGroup</code>.
14+
<li>字符串的长度在 <code>[minLength, maxLength]</code> 之间。</li>
15+
<li>每块连续 <code>1</code> 的个数是 <code>oneGroup</code> 的整数倍
1616
<ul>
17-
<li>For example in a binary string <code>00<u>11</u>0<u>1111</u>00</code> sizes of each block of consecutive ones are <code>[2,4]</code>.</li>
17+
<li>例如在二进制字符串 <code>00<em><strong>11</strong></em>0<em><strong>1111</strong></em>00</code> 中,每块连续 <code>1</code> 的个数分别是<code>[2,4]</code></li>
1818
</ul>
1919
</li>
20-
<li>The size of each block of consecutive <code>0</code>&#39;s is a multiple of <code>zeroGroup</code>.
20+
<li>每块连续 <code>0</code> 的个数是 <code>zeroGroup</code> 的整数倍
2121
<ul>
22-
<li>For example, in a binary string <code><u>00</u>11<u>0</u>1111<u>00</u></code> sizes of each block of consecutive ones are <code>[2,1,2]</code>.</li>
22+
<li>例如在二进制字符串 <code><em><strong>00</strong></em>11<em><strong>0</strong></em>1111<em><strong>00</strong></em></code> 中,每块连续 <code>0</code> 的个数分别是 <code>[2,1,2]</code></li>
2323
</ul>
2424
</li>
2525
</ul>
2626

27-
<p>Return <em>the number of <strong>good</strong> binary strings</em>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
27+
<p>请返回好二进制字符串的个数。答案可能很大<strong></strong>请返回对 <code>10<sup>9</sup> + 7</code> 取余后的结果。</p>
2828

29-
<p><strong>Note</strong> that <code>0</code> is considered a multiple of all the numbers.</p>
29+
<p><strong>注意:</strong><code>0</code> 可以被认为是所有数字的倍数。</p>
3030

3131
<p>&nbsp;</p>
32-
<p><strong class="example">Example 1:</strong></p>
32+
33+
<p><strong>示例 1:</strong></p>
3334

3435
<pre>
35-
<strong>Input:</strong> minLength = 2, maxLength = 3, oneGroup = 1, zeroGroup = 2
36-
<strong>Output:</strong> 5
37-
<strong>Explanation:</strong> There are 5 good binary strings in this example: &quot;00&quot;, &quot;11&quot;, &quot;001&quot;, &quot;100&quot;, and &quot;111&quot;.
38-
It can be proven that there are only 5 good strings satisfying all conditions.
39-
</pre>
36+
<strong>输入:</strong>minLength = 2, maxLength = 3, oneGroup = 1, zeroGroup = 2
37+
<strong>输出:</strong>5
38+
<strong>解释:</strong>在本示例中有 5 个好二进制字符串: "00", "11", "001", "100", 和 "111" 。
39+
可以证明只有 5 个好二进制字符串满足所有的条件。</pre>
4040

41-
<p><strong class="example">Example 2:</strong></p>
41+
<p><strong>示例 2:</strong></p>
4242

4343
<pre>
44-
<strong>Input:</strong> minLength = 4, maxLength = 4, oneGroup = 4, zeroGroup = 3
45-
<strong>Output:</strong> 1
46-
<strong>Explanation:</strong> There is only 1 good binary string in this example: &quot;1111&quot;.
47-
It can be proven that there is only 1 good string satisfying all conditions.
44+
<strong>输入:</strong>minLength = 4, maxLength = 4, oneGroup = 4, zeroGroup = 3
45+
<strong>输出:</strong>1
46+
<strong>解释:</strong>在本示例中有 1 个好二进制字符串: "1111" 。
47+
可以证明只有 1 个好字符串满足所有的条件。
4848
</pre>
4949

5050
<p>&nbsp;</p>
51-
<p><strong>Constraints:</strong></p>
51+
52+
<p><strong>提示:</strong></p>
5253

5354
<ul>
5455
<li><code>1 &lt;= minLength &lt;= maxLength &lt;= 10<sup>5</sup></code></li>

solution/2500-2599/2539.Count the Number of Good Subsequences/README.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
# [2539. Count the Number of Good Subsequences](https://leetcode.cn/problems/count-the-number-of-good-subsequences)
1+
# [2539. 好子序列的个数](https://leetcode.cn/problems/count-the-number-of-good-subsequences)
22

33
[English Version](/solution/2500-2599/2539.Count%20the%20Number%20of%20Good%20Subsequences/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>A <strong>subsequence</strong> of a string is&nbsp;good if it is not empty and the frequency of each one of its characters is the same.</p>
9+
<p>如果字符串的某个 <strong>子序列</strong> 不为空,且其中每一个字符出现的频率都相同,就认为该子序列是一个好子序列。</p>
1010

11-
<p>Given a string <code>s</code>, return <em>the number of good subsequences of</em> <code>s</code>. Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
11+
<p>给你一个字符串&nbsp;<code>s</code> ,请你统计并返回它的好子序列的个数。由于答案的值可能非常大,请返回对 <code>10<sup>9</sup> + 7</code> 取余的结果作为答案。</p>
1212

13-
<p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p>
13+
<p>字符串的 <strong>子序列</strong> 是指,通过删除一些(也可以不删除)字符且不改变剩余字符相对位置所组成的新字符串。</p>
1414

1515
<p>&nbsp;</p>
16-
<p><strong class="example">Example 1:</strong></p>
16+
17+
<p><strong>示例 1:</strong></p>
1718

1819
<pre>
19-
<strong>Input:</strong> s = &quot;aabb&quot;
20-
<strong>Output:</strong> 11
21-
<strong>Explanation:</strong> The total number of subsequences is <code>2<sup>4</sup>. </code>There are five subsequences which are not good: &quot;<strong><u>aab</u></strong>b&quot;, &quot;a<u><strong>abb</strong></u>&quot;, &quot;<strong><u>a</u></strong>a<u><strong>bb</strong></u>&quot;, &quot;<u><strong>aa</strong></u>b<strong><u>b</u></strong>&quot;, and the empty subsequence. Hence, the number of good subsequences is <code>2<sup>4</sup>-5 = 11</code>.</pre>
20+
<strong>输入:</strong>s = "aabb"
21+
<strong>输出:</strong>11
22+
<strong>解释:</strong>s 的子序列的总数为 <code>2<sup>4 </sup>= 16 。其中,有 5 个子序列不是好子序列,分别是 </code>"<em><strong>aab</strong></em>b","a<em><strong>abb</strong></em>","<strong><em>a</em></strong>a<em><strong>bb</strong></em>","<em><strong>aa</strong></em>b<em><strong>b</strong></em>" 以及空字符串。因此,好子序列的个数为 16 <code>- 5 = 11</code></pre>
2223

23-
<p><strong class="example">Example 2:</strong></p>
24+
<p><strong>示例 2:</strong></p>
2425

2526
<pre>
26-
<strong>Input:</strong> s = &quot;leet&quot;
27-
<strong>Output:</strong> 12
28-
<strong>Explanation:</strong> There are four subsequences which are not good: &quot;<strong><u>l</u><em>ee</em></strong>t&quot;, &quot;l<u><strong>eet</strong></u>&quot;, &quot;<strong><u>leet</u></strong>&quot;, and the empty subsequence. Hence, the number of good subsequences is <code>2<sup>4</sup>-4 = 12</code>.
27+
<strong>输入:</strong>s = "leet"
28+
<strong>输出:</strong>12
29+
<strong>解释:</strong>s 的子序列的总数为 <code>2<sup>4 </sup>= 16 。</code>其中,<code>有 4 个子序列不是好子序列,分别是 </code>"<em><strong>lee</strong></em>t","l<em><strong>eet</strong></em>","<em><strong>leet</strong></em>" 以及空字符串。因此,好子序列的个数为 16 <code>- 4 = 12</code>
2930
</pre>
3031

31-
<p><strong class="example">Example 3:</strong></p>
32+
<p><strong>示例 3:</strong></p>
3233

3334
<pre>
34-
<strong>Input:</strong> s = &quot;abcd&quot;
35-
<strong>Output:</strong> 15
36-
<strong>Explanation:</strong> All of the non-empty subsequences are good subsequences. Hence, the number of good subsequences is <code>2<sup>4</sup>-1 = 15</code>.
35+
<strong>输入:</strong>s = "abcd"
36+
<strong>输出:</strong>15
37+
<strong>解释:</strong>s 所有非空子序列均为好子序列。因此,好子序列的个数为 16<code> - 1 = 15</code>
3738
</pre>
3839

3940
<p>&nbsp;</p>
40-
<p><strong>Constraints:</strong></p>
41+
42+
<p><strong>提示:</strong></p>
4143

4244
<ul>
4345
<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>
44-
<li><code>s</code> consists of only lowercase English letters.</li>
46+
<li><code>s</code> 仅由小写英文字母组成</li>
4547
</ul>
4648

4749
## 解法

solution/2500-2599/2543.Check if Point Is Reachable/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Solution {
6262
int x = gcd(targetX, targetY);
6363
return (x & (x - 1)) == 0;
6464
}
65-
65+
6666
private int gcd(int a, int b) {
6767
return b == 0 ? a : gcd(b, a % b);
6868
}

0 commit comments

Comments
 (0)