Skip to content

Commit 54e6497

Browse files
committed
feat: add solutions to lc problem: No.2445
No.2445.Number of Nodes With Value One
1 parent 2cbd68a commit 54e6497

File tree

27 files changed

+552
-62
lines changed

27 files changed

+552
-62
lines changed

solution/0000-0099/0069.Sqrt(x)/README_EN.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44

55
## Description
66

7-
<p>Given a non-negative integer <code>x</code>,&nbsp;compute and return <em>the square root of</em> <code>x</code>.</p>
7+
<p>Given a non-negative integer <code>x</code>, return <em>the square root of </em><code>x</code><em> rounded down to the nearest integer</em>. The returned integer should be <strong>non-negative</strong> as well.</p>
88

9-
<p>Since the return type&nbsp;is an integer, the decimal digits are <strong>truncated</strong>, and only <strong>the integer part</strong> of the result&nbsp;is returned.</p>
9+
<p>You <strong>must not use</strong> any built-in exponent function or operator.</p>
1010

11-
<p><strong>Note:&nbsp;</strong>You are not allowed to use any built-in exponent function or operator, such as <code>pow(x, 0.5)</code> or&nbsp;<code>x ** 0.5</code>.</p>
11+
<ul>
12+
<li>For example, do not use <code>pow(x, 0.5)</code> in c++ or <code>x ** 0.5</code> in python.</li>
13+
</ul>
1214

1315
<p>&nbsp;</p>
1416
<p><strong class="example">Example 1:</strong></p>
1517

1618
<pre>
1719
<strong>Input:</strong> x = 4
1820
<strong>Output:</strong> 2
21+
<strong>Explanation:</strong> The square root of 4 is 2, so we return 2.
1922
</pre>
2023

2124
<p><strong class="example">Example 2:</strong></p>
2225

2326
<pre>
2427
<strong>Input:</strong> x = 8
2528
<strong>Output:</strong> 2
26-
<strong>Explanation:</strong> The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.</pre>
29+
<strong>Explanation:</strong> The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
30+
</pre>
2731

2832
<p>&nbsp;</p>
2933
<p><strong>Constraints:</strong></p>

solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
</ul>
2929

3030
<p>&nbsp;</p>
31-
<p><strong class="example">Example 1:</strong></p>
31+
<p><strong>Example 1:</strong></p>
3232
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/images/node1.jpg" style="width: 400px; height: 286px;" />
3333
<pre>
3434
<strong>Input:</strong> head = [4,5,1,9], node = 5
3535
<strong>Output:</strong> [4,1,9]
3636
<strong>Explanation: </strong>You are given the second node with value 5, the linked list should become 4 -&gt; 1 -&gt; 9 after calling your function.
3737
</pre>
3838

39-
<p><strong class="example">Example 2:</strong></p>
39+
<p><strong>Example 2:</strong></p>
4040
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/images/node2.jpg" style="width: 400px; height: 315px;" />
4141
<pre>
4242
<strong>Input:</strong> head = [4,5,1,9], node = 1

solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md

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

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

9-
<p>给定一个正整数 <code>n</code>&nbsp;,返回范围在&nbsp;<code>[0, n]</code>&nbsp;都非负整数中,其二进制表示不包含&nbsp;<strong>连续的 1&nbsp;</strong>的个数。</p>
9+
<p>给定一个正整数 <code>n</code> ,请你统计在&nbsp;<code>[0, n]</code> 范围的非负整数中,有多少个整数的二进制表示中不存在 <strong>连续的 1 </strong>。</p>
1010

1111
<p>&nbsp;</p>
1212

@@ -16,14 +16,14 @@
1616
<strong>输入:</strong> n = 5
1717
<strong>输出:</strong> 5
1818
<strong>解释:</strong>
19-
下面是带有相应二进制表示的非负整数&lt;= 5
19+
下面列出范围在 [0, 5] 的非负整数与其对应的二进制表示
2020
0 : 0
2121
1 : 1
2222
2 : 10
2323
3 : 11
2424
4 : 100
2525
5 : 101
26-
其中,只有整数3违反规则(有两个连续的1),其他5个满足规则。</pre>
26+
其中,只有整数 3 违反规则(有两个连续的 1 ),其他 5 个满足规则。</pre>
2727

2828
<p><strong>示例 2:</strong></p>
2929

solution/0700-0799/0779.K-th Symbol in Grammar/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ n = 5: 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0
109109

110110
时间复杂度 $O(\log k)$,空间复杂度 $O(1)$。
111111

112-
113112
<!-- tabs:start -->
114113

115114
### **Python3**
@@ -150,7 +149,6 @@ class Solution {
150149
}
151150
```
152151

153-
154152
```java
155153
class Solution {
156154
public int kthGrammar(int n, int k) {

solution/0900-0999/0901.Online Stock Span/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class StockSpanner {
8181
public StockSpanner() {
8282

8383
}
84-
84+
8585
public int next(int price) {
8686
int cnt = 1;
8787
while (!stk.isEmpty() && stk.peek()[0] <= price) {
@@ -107,7 +107,7 @@ public:
107107
StockSpanner() {
108108

109109
}
110-
110+
111111
int next(int price) {
112112
int cnt = 1;
113113
while (!stk.empty() && stk.top().first <= price) {

solution/0900-0999/0984.String Without AAA or BBB/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<p>给定两个整数 <code>a</code>&nbsp;和 <code>b</code>&nbsp;,返回&nbsp;<strong>任意</strong>&nbsp;字符串 <code>s</code>&nbsp;,要求满足:</p>
1010

1111
<ul>
12-
<li><code>s</code>&nbsp;的长度为 <code>a + b</code>,且正好包含<code><font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">a</span></span></span></font></font></code>&nbsp;个 <code>'a'</code>&nbsp;字母与&nbsp;<code><font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">b</span></span></span></font></font></code>&nbsp;个 <code>'b'</code>&nbsp;字母;</li>
12+
<li><code>s</code>&nbsp;的长度为 <code>a + b</code>,且正好包含&nbsp;<code>a</code>&nbsp;个 <code>'a'</code>&nbsp;字母与&nbsp;<code>b</code> 个 <code>'b'</code>&nbsp;字母;</li>
1313
<li>子串&nbsp;<code>'aaa'</code>&nbsp;没有出现在 <code>s</code>&nbsp;中;</li>
1414
<li>子串&nbsp;<code>'bbb'</code> 没有出现在 <code>s</code>&nbsp;中。</li>
1515
</ul>

solution/1100-1199/1192.Critical Connections in a Network/README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# [1192. 查找集群内的「关键连接」](https://leetcode.cn/problems/critical-connections-in-a-network)
1+
# [1192. 查找集群内的关键连接](https://leetcode.cn/problems/critical-connections-in-a-network)
22

33
[English Version](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>力扣数据中心有&nbsp;<code>n</code>&nbsp;台服务器,分别按从&nbsp;<code>0</code>&nbsp;&nbsp;<code>n-1</code>&nbsp;的方式进行了编号。它们之间以服务器到服务器」点对点的形式相互连接组成了一个内部集群,其中连接&nbsp;<code>connections</code> 是无向的。从形式上讲,<code>connections[i] = [a, b]</code>&nbsp;表示服务器 <code>a</code>&nbsp;和 <code>b</code>&nbsp;之间形成连接。任何服务器都可以直接或者间接地通过网络到达任何其他服务器。</p>
9+
<p>力扣数据中心有&nbsp;<code>n</code>&nbsp;台服务器,分别按从&nbsp;<code>0</code>&nbsp;&nbsp;<code>n-1</code>&nbsp;的方式进行了编号。它们之间以 <strong>服务器到服务器</strong> 的形式相互连接组成了一个内部集群,连接是无向的。用 &nbsp;<code>connections</code> 表示集群网络,<code>connections[i] = [a, b]</code>&nbsp;表示服务器 <code>a</code>&nbsp;和 <code>b</code>&nbsp;之间形成连接。任何服务器都可以直接或者间接地通过网络到达任何其他服务器。</p>
1010

11-
<p><em>「关键连接」</em>&nbsp;是在该集群中的重要连接,也就是说,假如我们将它移除,便会导致某些服务器无法访问其他服务器。</p>
11+
<p><strong>关键连接</strong><em> </em>是在该集群中的重要连接,假如我们将它移除,便会导致某些服务器无法访问其他服务器。</p>
1212

13-
<p>请你以任意顺序返回该集群内的所有 关键连接。</p>
13+
<p>请你以任意顺序返回该集群内的所有 <strong>关键连接</strong> 。</p>
1414

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

@@ -35,9 +35,10 @@
3535
<p><strong>提示:</strong></p>
3636

3737
<ul>
38-
<li><code>1 &lt;= n &lt;= 10^5</code></li>
39-
<li><code>n-1 &lt;= connections.length &lt;= 10^5</code></li>
40-
<li><code>connections[i][0] != connections[i][1]</code></li>
38+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
39+
<li><code>n - 1 &lt;= connections.length &lt;= 10<sup>5</sup></code></li>
40+
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= n - 1</code></li>
41+
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
4142
<li>不存在重复的连接</li>
4243
</ul>
4344

solution/1400-1499/1458.Max Dot Product of Two Subsequences/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
<p><strong>点积:</strong></p>
5353

5454
<pre>
55-
定义 <code><strong>a</strong>&nbsp;= [<em>a</em><sub>1</sub>,&nbsp;<em>a</em><sub>2</sub>,&hellip;,&nbsp;<em>a</em><sub><em>n</em></sub>]</code> 和<strong> <code>b</code></strong><code>&nbsp;= [<em>b</em><sub>1</sub>,&nbsp;<em>b</em><sub>2</sub>,&hellip;,&nbsp;<em>b</em><sub><em>n</em></sub>]</code> 的点积为:
55+
定义 <code><strong>a</strong>&nbsp;= [<em>a</em><sub>1</sub>,&nbsp;<em>a</em><sub>2</sub>,,&nbsp;<em>a</em><sub><em>n</em></sub>]</code> 和<strong> <code>b</code></strong><code>&nbsp;= [<em>b</em><sub>1</sub>,&nbsp;<em>b</em><sub>2</sub>,,&nbsp;<em>b</em><sub><em>n</em></sub>]</code> 的点积为:
5656

57-
<img alt="\mathbf{a}\cdot \mathbf{b} = \sum_{i=1}^n a_ib_i = a_1b_1 + a_2b_2 + \cdots + a_nb_n " class="tex" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/images/c329bf86e747d74f55ed2e17c36fd83f.png" />
57+
<img alt="\mathbf{a}\cdot \mathbf{b} = \sum_{i=1}^n a_ib_i = a_1b_1 + a_2b_2 + \cdots + a_nb_n " class="tex" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/images/1666164309-PBJMQp-image.png" />
5858

59-
这里的 <strong>&Sigma;</strong> 指示总和符号。
59+
这里的 <strong>Σ</strong> 指示总和符号。
6060
</pre>
6161

6262
## 解法

solution/1500-1599/1509.Minimum Difference Between Largest and Smallest Value in Three Moves/README_EN.md

+26-6
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,47 @@
44

55
## Description
66

7-
<p>You are given an integer array <code>nums</code>. In one move, you can choose one element of <code>nums</code> and change it by <strong>any value</strong>.</p>
7+
<p>You are given an integer array <code>nums</code>.</p>
88

9-
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> after performing <strong>at most three moves</strong></em>.</p>
9+
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
10+
11+
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</strong></em>.</p>
1012

1113
<p>&nbsp;</p>
1214
<p><strong class="example">Example 1:</strong></p>
1315

1416
<pre>
1517
<strong>Input:</strong> nums = [5,3,2,4]
1618
<strong>Output:</strong> 0
17-
<strong>Explanation:</strong> Change the array [5,3,2,4] to [<strong>2</strong>,<strong>2</strong>,2,<strong>2</strong>].
18-
The difference between the maximum and minimum is 2-2 = 0.
19+
<strong>Explanation:</strong> We can make at most 3 moves.
20+
In the first move, change 2 to 3. nums becomes [5,3,3,4].
21+
In the second move, change 4 to 3. nums becomes [5,3,3,3].
22+
In the third move, change 5 to 3. nums becomes [3,3,3,3].
23+
After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.
1924
</pre>
2025

2126
<p><strong class="example">Example 2:</strong></p>
2227

2328
<pre>
2429
<strong>Input:</strong> nums = [1,5,0,10,14]
2530
<strong>Output:</strong> 1
26-
<strong>Explanation:</strong> Change the array [1,5,0,10,14] to [1,<strong>1</strong>,0,<strong>1</strong>,<strong>1</strong>].
27-
The difference between the maximum and minimum is 1-0 = 1.
31+
<strong>Explanation:</strong> We can make at most 3 moves.
32+
In the first move, change 5 to 0. nums becomes [1,0,0,10,14].
33+
In the second move, change 10 to 0. nums becomes [1,0,0,0,14].
34+
In the third move, change 14 to 1. nums becomes [1,0,0,0,1].
35+
After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 0.
36+
It can be shown that there is no way to make the difference 0 in 3 moves.</pre>
37+
38+
<p><strong class="example">Example 3:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> nums = [3,100,20]
42+
<strong>Output:</strong> 0
43+
<strong>Explanation:</strong> We can make at most 3 moves.
44+
In the first move, change 100 to 7. nums becomes [4,7,20].
45+
In the second move, change 20 to 7. nums becomes [4,7,7].
46+
In the third move, change 4 to 3. nums becomes [7,7,7].
47+
After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0.
2848
</pre>
2949

3050
<p>&nbsp;</p>

solution/1500-1599/1531.String Compression II/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
<p>Find the <em>minimum length of the run-length encoded&nbsp;version of </em><code>s</code><em> after deleting at most </em><code>k</code><em> characters</em>.</p>
1414

1515
<p>&nbsp;</p>
16-
<p><strong class="example">Example 1:</strong></p>
16+
<p><strong>Example 1:</strong></p>
1717

1818
<pre>
1919
<strong>Input:</strong> s = &quot;aaabcccd&quot;, k = 2
2020
<strong>Output:</strong> 4
2121
<b>Explanation: </b>Compressing s without deleting anything will give us &quot;a3bc3d&quot; of length 6. Deleting any of the characters &#39;a&#39; or &#39;c&#39; would at most decrease the length of the compressed string to 5, for instance delete 2 &#39;a&#39; then we will have s = &quot;abcccd&quot; which compressed is abc3d. Therefore, the optimal way is to delete &#39;b&#39; and &#39;d&#39;, then the compressed version of s will be &quot;a3c3&quot; of length 4.</pre>
2222

23-
<p><strong class="example">Example 2:</strong></p>
23+
<p><strong>Example 2:</strong></p>
2424

2525
<pre>
2626
<strong>Input:</strong> s = &quot;aabbaa&quot;, k = 2
2727
<strong>Output:</strong> 2
2828
<b>Explanation: </b>If we delete both &#39;b&#39; characters, the resulting compressed string would be &quot;a4&quot; of length 2.
2929
</pre>
3030

31-
<p><strong class="example">Example 3:</strong></p>
31+
<p><strong>Example 3:</strong></p>
3232

3333
<pre>
3434
<strong>Input:</strong> s = &quot;aaaaaaaaaaa&quot;, k = 0

solution/1700-1799/1707.Maximum XOR With an Element From Array/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646

4747
**方法一:前缀树**
4848

49-
50-
5149
<!-- tabs:start -->
5250

5351
### **Python3**

solution/1700-1799/1790.Check if One String Swap Can Make Strings Equal/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
<p>Return <code>true</code> <em>if it is possible to make both strings equal by performing <strong>at most one string swap </strong>on <strong>exactly one</strong> of the strings. </em>Otherwise, return <code>false</code>.</p>
1010

1111
<p>&nbsp;</p>
12-
<p><strong class="example">Example 1:</strong></p>
12+
<p><strong>Example 1:</strong></p>
1313

1414
<pre>
1515
<strong>Input:</strong> s1 = &quot;bank&quot;, s2 = &quot;kanb&quot;
1616
<strong>Output:</strong> true
1717
<strong>Explanation:</strong> For example, swap the first character with the last character of s2 to make &quot;bank&quot;.
1818
</pre>
1919

20-
<p><strong class="example">Example 2:</strong></p>
20+
<p><strong>Example 2:</strong></p>
2121

2222
<pre>
2323
<strong>Input:</strong> s1 = &quot;attack&quot;, s2 = &quot;defend&quot;
2424
<strong>Output:</strong> false
2525
<strong>Explanation:</strong> It is impossible to make them equal with one string swap.
2626
</pre>
2727

28-
<p><strong class="example">Example 3:</strong></p>
28+
<p><strong>Example 3:</strong></p>
2929

3030
<pre>
3131
<strong>Input:</strong> s1 = &quot;kelb&quot;, s2 = &quot;kelb&quot;

solution/2400-2499/2437.Number of Valid Clock Times/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func countTime(time string) int {
156156
function countTime(time: string): number {
157157
let [hh, mm] = time.split(':');
158158
return count(hh, 24) * count(mm, 60);
159-
};
159+
}
160160

161161
function count(str: string, limit: number): number {
162162
let [a, b] = str.split('').map(d => Number(d));

solution/2400-2499/2437.Number of Valid Clock Times/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func countTime(time string) int {
143143
function countTime(time: string): number {
144144
let [hh, mm] = time.split(':');
145145
return count(hh, 24) * count(mm, 60);
146-
};
146+
}
147147

148148
function count(str: string, limit: number): number {
149149
let [a, b] = str.split('').map(d => Number(d));

solution/2400-2499/2444.Count Subarrays With Fixed Bounds/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
1919

2020
<p>&nbsp;</p>
21-
<p><strong class="example">Example 1:</strong></p>
21+
<p><strong>Example 1:</strong></p>
2222

2323
<pre>
2424
<strong>Input:</strong> nums = [1,3,5,2,7,5], minK = 1, maxK = 5
2525
<strong>Output:</strong> 2
2626
<strong>Explanation:</strong> The fixed-bound subarrays are [1,3,5] and [1,3,5,2].
2727
</pre>
2828

29-
<p><strong class="example">Example 2:</strong></p>
29+
<p><strong>Example 2:</strong></p>
3030

3131
<pre>
3232
<strong>Input:</strong> nums = [1,1,1,1], minK = 1, maxK = 1

0 commit comments

Comments
 (0)