Skip to content

Commit a87f495

Browse files
committed
Merge branch 'main' of https://github.com/nrhitik/leetcode
2 parents 49bf92b + d0411cd commit a87f495

File tree

29 files changed

+667
-141
lines changed

29 files changed

+667
-141
lines changed

solution/0100-0199/0101.Symmetric Tree/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
<p>&nbsp;</p>
1212

1313
<p><strong>示例 1:</strong></p>
14-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/symtree1.jpg" style="width: 354px; height: 291px;" />
14+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/1698026966-JDYPDU-image.png" style="width: 354px; height: 291px;" />
1515
<pre>
1616
<strong>输入:</strong>root = [1,2,2,3,4,4,3]
1717
<strong>输出:</strong>true
1818
</pre>
1919

2020
<p><strong>示例 2:</strong></p>
21-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/symtree2.jpg" style="width: 308px; height: 258px;" />
21+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/1698027008-nPFLbM-image.png" style="width: 308px; height: 258px;" />
2222
<pre>
2323
<strong>输入:</strong>root = [1,2,2,null,3,null,3]
2424
<strong>输出:</strong>false
Loading
Loading

solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [158. 用 Read4 读取 N 个字符 II](https://leetcode.cn/problems/read-n-characters-given-read4-ii-call-multiple-times)
1+
# [158. 用 Read4 读取 N 个字符 II - 多次调用](https://leetcode.cn/problems/read-n-characters-given-read4-ii-call-multiple-times)
22

33
[English Version](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20read4%20II%20-%20Call%20Multiple%20Times/README_EN.md)
44

solution/0500-0599/0560.Subarray Sum Equals K/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
<p>给你一个整数数组 <code>nums</code> 和一个整数&nbsp;<code>k</code> ,请你统计并返回 <em>该数组中和为&nbsp;<code>k</code><strong>&nbsp;</strong>的连续子数组的个数&nbsp;</em>。</p>
9+
<p>给你一个整数数组 <code>nums</code> 和一个整数&nbsp;<code>k</code> ,请你统计并返回 <em>该数组中和为&nbsp;<code>k</code><strong>&nbsp;</strong>的子数组的个数&nbsp;</em>。</p>
1010

1111
<p>子数组是数组中元素的连续非空序列。</p>
1212

solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ passenger_id 是该表的主键。
3838

3939
<p>公交车和乘客到达 LeetCode 站。如果一辆公交车在时间 <code>t<sub>bus</sub></code> 到站,乘客在时间 <code>t<sub>passenger</sub></code> 到站,其中 <code>t<sub>passenger</sub> &lt;= t<sub>bus</sub></code>,该乘客之前没有赶上任何公交车,则该乘客将搭乘该公交车。</p>
4040

41-
<p>编写一个 SQL 来查询使用每条总线的用户数量。</p>
41+
<p>编写一个 SQL 来查询使用每辆公交车的用户数量。</p>
4242

4343
<p>返回按 <code>bus_id</code> <strong>升序排序&nbsp;</strong>的结果表。</p>
4444

solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,42 @@
66

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

9-
<p>给你一个 <strong></strong>&nbsp;整数数组&nbsp;<code>beans</code>&nbsp;,其中每个整数表示一个袋子里装的魔法豆的数目。</p>
9+
<p>给定一个 <strong>正整数&nbsp;</strong>数组&nbsp;<code>beans</code>&nbsp;,其中每个整数表示一个袋子里装的魔法豆的数目。</p>
1010

11-
<p>请你从每个袋子中&nbsp;<strong>拿出</strong>&nbsp;一些豆子(也可以<strong>&nbsp;不拿出</strong>),使得剩下的 <strong>非空</strong> 袋子中(即 <strong>至少</strong>&nbsp;还有 <strong>一颗</strong>&nbsp;魔法豆的袋子)魔法豆的数目&nbsp;<strong>相等</strong>&nbsp;。一旦魔法豆从袋子中取出,你不能将它放到任何其他的袋子中。</p>
11+
<p>请你从每个袋子中&nbsp;<strong>拿出</strong>&nbsp;一些豆子(也可以<strong>&nbsp;不拿出</strong>),使得剩下的 <strong>非空</strong> 袋子中(即 <strong>至少还有一颗</strong>&nbsp;魔法豆的袋子)魔法豆的数目&nbsp;<strong>相等</strong>。一旦把魔法豆从袋子中取出,你不能再将它放到任何袋子中。</p>
1212

13-
<p>请你返回你需要拿出魔法豆的 <strong>最少数目</strong>。</p>
13+
<p>请返回你需要拿出魔法豆的 <strong>最少数目</strong>。</p>
1414

1515
<p>&nbsp;</p>
1616

1717
<p><strong>示例 1:</strong></p>
1818

19-
<pre><b>输入:</b>beans = [4,<em><strong>1</strong></em>,6,5]
19+
<pre>
20+
<b>输入:</b>beans = [4,<u><strong>1</strong></u>,6,5]
2021
<b>输出:</b>4
2122
<b>解释:</b>
2223
- 我们从有 1 个魔法豆的袋子中拿出 1 颗魔法豆。
23-
剩下袋子中魔法豆的数目为:[4,<em><b>0</b></em>,6,5]
24+
剩下袋子中魔法豆的数目为:[4,<u><strong>0</strong></u>,6,5]
2425
- 然后我们从有 6 个魔法豆的袋子中拿出 2 个魔法豆。
25-
剩下袋子中魔法豆的数目为:[4,0,<em><strong>4</strong></em>,5]
26+
剩下袋子中魔法豆的数目为:[4,0,<u><strong>4</strong></u>,5]
2627
- 然后我们从有 5 个魔法豆的袋子中拿出 1 个魔法豆。
27-
剩下袋子中魔法豆的数目为:[4,0,4,<em><b>4</b></em>]
28+
剩下袋子中魔法豆的数目为:[4,0,4,<u><strong>4</strong></u>]
2829
总共拿出了 1 + 2 + 1 = 4 个魔法豆,剩下非空袋子中魔法豆的数目相等。
2930
没有比取出 4 个魔法豆更少的方案。
3031
</pre>
3132

3233
<p><strong>示例 2:</strong></p>
3334

34-
<pre><b>输入:</b>beans = [<em><strong>2</strong></em>,10,<em><strong>3</strong></em>,<em><strong>2</strong></em>]
35+
<pre>
36+
<b>输入:</b>beans = [<u><strong>2</strong></u>,10,<u><strong>3</strong></u>,<u><strong>2</strong></u>]
3537
<b>输出:</b>7
3638
<strong>解释:</strong>
3739
- 我们从有 2 个魔法豆的其中一个袋子中拿出 2 个魔法豆。
38-
剩下袋子中魔法豆的数目为:[<em><strong>0</strong></em>,10,3,2]
40+
剩下袋子中魔法豆的数目为:[<u><strong>0</strong></u>,10,3,2]
3941
- 然后我们从另一个有 2 个魔法豆的袋子中拿出 2 个魔法豆。
40-
剩下袋子中魔法豆的数目为:[0,10,3,<em><strong>0</strong></em>]
42+
剩下袋子中魔法豆的数目为:[0,10,3,<u><strong>0</strong></u>]
4143
- 然后我们从有 3 个魔法豆的袋子中拿出 3 个魔法豆。
42-
剩下袋子中魔法豆的数目为:[0,10,<em><strong>0</strong></em>,0]
44+
剩下袋子中魔法豆的数目为:[0,10,<u><strong>0</strong></u>,0]
4345
总共拿出了 2 + 2 + 3 = 7 个魔法豆,剩下非空袋子中魔法豆的数目相等。
4446
没有比取出 7 个魔法豆更少的方案。
4547
</pre>

solution/2500-2599/2519.Count the Number of K-Big Indices/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151

5252
**方法一:树状数组**
5353

54-
维护两个树状数组,一个记录当前位置左边小于当前位置的数的个数,另一个记录当前位置右边小于当前位置的数的个数。
54+
我们维护两个树状数组,一个记录当前位置左边小于当前位置的数的个数,另一个记录当前位置右边小于当前位置的数的个数。
5555

5656
遍历数组,对于当前位置,如果左边小于当前位置的数的个数大于等于 $k$,且右边小于当前位置的数的个数大于等于 $k$,则当前位置是 $k-big$,答案加一。
5757

58-
时间复杂度 $O(n\log n)$,空间复杂度 $O(n)$。其中 $n$ 为数组长度。
58+
时间复杂度 $O(n \times \log n)$,空间复杂度 $O(n)$。其中 $n$ 为数组长度。
5959

6060
<!-- tabs:start -->
6161

solution/2500-2599/2519.Count the Number of K-Big Indices/README_EN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444

4545
## Solutions
4646

47+
**Solution 1: Binary Indexed Tree**
48+
49+
We maintain two binary indexed trees, one records the number of elements smaller than the current position on the left, and the other records the number of elements smaller than the current position on the right.
50+
51+
We traverse the array, and for the current position, if the number of elements smaller than the current position on the left is greater than or equal to $k$, and the number of elements smaller than the current position on the right is greater than or equal to $k$, then the current position is a `k-big`, and we increment the answer by one.
52+
53+
The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$, where $n$ is the length of the array.
54+
4755
<!-- tabs:start -->
4856

4957
### **Python3**

solution/2500-2599/2520.Count the Digits That Divide a Number/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848

4949
**方法一:枚举**
5050

51-
我们直接枚举整数 `num` 的每一位上的数 `val`,若 `val` 能够整除 `num`,那么答案加一。
51+
我们直接枚举整数 $num$ 的每一位上的数 $val$,若 $val$ 能够整除 $num$,那么答案加一。
52+
53+
枚举结束后,返回答案即可。
5254

5355
时间复杂度 $O(\log num)$,空间复杂度 $O(1)$。
5456

@@ -121,12 +123,10 @@ func countDigits(num int) (ans int) {
121123
```ts
122124
function countDigits(num: number): number {
123125
let ans = 0;
124-
let cur = num;
125-
while (cur !== 0) {
126-
if (num % (cur % 10) === 0) {
127-
ans++;
126+
for (let x = num; x; x = (x / 10) | 0) {
127+
if (num % (x % 10) === 0) {
128+
++ans;
128129
}
129-
cur = Math.floor(cur / 10);
130130
}
131131
return ans;
132132
}

0 commit comments

Comments
 (0)