Skip to content

Commit d96227e

Browse files
author
Shuo
committed
A: new
1 parent 8fcaa42 commit d96227e

File tree

190 files changed

+3061
-1159
lines changed

Some content is hidden

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

190 files changed

+3061
-1159
lines changed

README.md

+33-7
Large diffs are not rendered by default.

problems/1-bit-and-2-bit-characters/README.md

+27-20
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,41 @@
1111

1212
## [717. 1-bit and 2-bit Characters (Easy)](https://leetcode.com/problems/1-bit-and-2-bit-characters "1比特与2比特字符")
1313

14-
<p>We have two special characters. The first character can be represented by one bit <code>0</code>. The second character can be represented by two bits (<code>10</code> or <code>11</code>). </p>
14+
<p>We have two special characters:</p>
1515

16-
<p>Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.</p>
16+
<ul>
17+
<li>The first character can be represented by one bit <code>0</code>.</li>
18+
<li>The second character can be represented by two bits (<code>10</code> or <code>11</code>).</li>
19+
</ul>
20+
21+
<p>Given a binary array <code>bits</code> that ends with <code>0</code>, return <code>true</code> if the last character must be a one-bit character.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
1725

18-
<p><b>Example 1:</b><br />
1926
<pre>
20-
<b>Input:</b>
21-
bits = [1, 0, 0]
22-
<b>Output:</b> True
23-
<b>Explanation:</b>
24-
The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
27+
<strong>Input:</strong> bits = [1,0,0]
28+
<strong>Output:</strong> true
29+
<strong>Explanation:</strong> The only way to decode it is two-bit character and one-bit character.
30+
So the last character is one-bit character.
2531
</pre>
26-
</p>
2732

28-
<p><b>Example 2:</b><br />
33+
<p><strong>Example 2:</strong></p>
34+
2935
<pre>
30-
<b>Input:</b>
31-
bits = [1, 1, 1, 0]
32-
<b>Output:</b> False
33-
<b>Explanation:</b>
34-
The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.
36+
<strong>Input:</strong> bits = [1,1,1,0]
37+
<strong>Output:</strong> false
38+
<strong>Explanation:</strong> The only way to decode it is two-bit character and two-bit character.
39+
So the last character is not one-bit character.
3540
</pre>
36-
</p>
3741

38-
<p><b>Note:</b>
39-
<li><code>1 <= len(bits) <= 1000</code>.</li>
40-
<li><code>bits[i]</code> is always <code>0</code> or <code>1</code>.</li>
41-
</p>
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= bits.length &lt;= 1000</code></li>
47+
<li><code>bits[i]</code> is either <code>0</code> or <code>1</code>.</li>
48+
</ul>
4249

4350
### Related Topics
4451
[[Array](../../tag/array/README.md)]

problems/132-pattern/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
<p>Return <em><code>true</code> if there is a <strong>132 pattern</strong> in <code>nums</code>, otherwise, return <code>false</code>.</em></p>
1717

18-
<p><strong>Follow up: </strong>The <code>O(n^2)</code> is trivial, could you come up with the <code>O(n logn)</code> or the <code>O(n)</code> solution?</p>
19-
2018
<p>&nbsp;</p>
2119
<p><strong>Example 1:</strong></p>
2220

@@ -47,7 +45,7 @@
4745

4846
<ul>
4947
<li><code>n == nums.length</code></li>
50-
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
48+
<li><code>1 &lt;= n &lt;= 2 * 10<sup>5</sup></code></li>
5149
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
5250
</ul>
5351

problems/ad-free-sessions/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
[Next >](../minimum-path-cost-in-a-hidden-grid "Minimum Path Cost in a Hidden Grid")
1111

12-
## [1809. Ad-Free Sessions (Easy)](https://leetcode.com/problems/ad-free-sessions "")
12+
## [1809. Ad-Free Sessions (Easy)](https://leetcode.com/problems/ad-free-sessions "没有广告的剧集")
1313

1414

problems/ambiguous-coordinates/README.md

+30-23
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,57 @@
1111

1212
## [816. Ambiguous Coordinates (Medium)](https://leetcode.com/problems/ambiguous-coordinates "模糊坐标")
1313

14-
<p>We had some 2-dimensional coordinates, like <code>&quot;(1, 3)&quot;</code> or <code>&quot;(2, 0.5)&quot;</code>.&nbsp; Then, we removed&nbsp;all commas, decimal points, and spaces, and ended up with the string&nbsp;<code>s</code>.&nbsp; Return a list of strings representing&nbsp;all possibilities for what our original coordinates could have been.</p>
14+
<p>We had some 2-dimensional coordinates, like <code>&quot;(1, 3)&quot;</code> or <code>&quot;(2, 0.5)&quot;</code>. Then, we removed all commas, decimal points, and spaces and ended up with the string s.</p>
1515

16-
<p>Our original representation never had extraneous zeroes, so we never started with numbers like &quot;00&quot;, &quot;0.0&quot;, &quot;0.00&quot;, &quot;1.0&quot;, &quot;001&quot;, &quot;00.01&quot;, or any other number that can be represented with&nbsp;less digits.&nbsp; Also, a decimal point within a number never occurs without at least one digit occuring before it, so we never started with numbers like &quot;.1&quot;.</p>
16+
<ul>
17+
<li>For example, <code>&quot;(1, 3)&quot;</code> becomes <code>s = &quot;(13)&quot;</code> and <code>&quot;(2, 0.5)&quot;</code> becomes <code>s = &quot;(205)&quot;</code>.</li>
18+
</ul>
19+
20+
<p>Return <em>a list of strings representing all possibilities for what our original coordinates could have been</em>.</p>
21+
22+
<p>Our original representation never had extraneous zeroes, so we never started with numbers like <code>&quot;00&quot;</code>, <code>&quot;0.0&quot;</code>, <code>&quot;0.00&quot;</code>, <code>&quot;1.0&quot;</code>, <code>&quot;001&quot;</code>, <code>&quot;00.01&quot;</code>, or any other number that can be represented with fewer digits. Also, a decimal point within a number never occurs without at least one digit occurring before it, so we never started with numbers like <code>&quot;.1&quot;</code>.</p>
1723

18-
<p>The final answer list can be returned in any order.&nbsp; Also note that all coordinates in the final answer&nbsp;have exactly one space between them (occurring after the comma.)</p>
24+
<p>The final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
1928

2029
<pre>
21-
<strong>Example 1:</strong>
2230
<strong>Input:</strong> s = &quot;(123)&quot;
23-
<strong>Output:</strong> [&quot;(1, 23)&quot;, &quot;(12, 3)&quot;, &quot;(1.2, 3)&quot;, &quot;(1, 2.3)&quot;]
31+
<strong>Output:</strong> [&quot;(1, 2.3)&quot;,&quot;(1, 23)&quot;,&quot;(1.2, 3)&quot;,&quot;(12, 3)&quot;]
2432
</pre>
2533

34+
<p><strong>Example 2:</strong></p>
35+
2636
<pre>
27-
<strong>Example 2:</strong>
28-
<strong>Input:</strong> s = &quot;(00011)&quot;
29-
<strong>Output:</strong> &nbsp;[&quot;(0.001, 1)&quot;, &quot;(0, 0.011)&quot;]
30-
<strong>Explanation:</strong>
31-
0.0, 00, 0001 or 00.01 are not allowed.
37+
<strong>Input:</strong> s = &quot;(0123)&quot;
38+
<strong>Output:</strong> [&quot;(0, 1.23)&quot;,&quot;(0, 12.3)&quot;,&quot;(0, 123)&quot;,&quot;(0.1, 2.3)&quot;,&quot;(0.1, 23)&quot;,&quot;(0.12, 3)&quot;]
39+
<strong>Explanation:</strong> 0.0, 00, 0001 or 00.01 are not allowed.
3240
</pre>
3341

42+
<p><strong>Example 3:</strong></p>
43+
3444
<pre>
35-
<strong>Example 3:</strong>
36-
<strong>Input:</strong> s = &quot;(0123)&quot;
37-
<strong>Output:</strong> [&quot;(0, 123)&quot;, &quot;(0, 12.3)&quot;, &quot;(0, 1.23)&quot;, &quot;(0.1, 23)&quot;, &quot;(0.1, 2.3)&quot;, &quot;(0.12, 3)&quot;]
45+
<strong>Input:</strong> s = &quot;(00011)&quot;
46+
<strong>Output:</strong> [&quot;(0, 0.011)&quot;,&quot;(0.001, 1)&quot;]
3847
</pre>
3948

49+
<p><strong>Example 4:</strong></p>
50+
4051
<pre>
41-
<strong>Example 4:</strong>
4252
<strong>Input:</strong> s = &quot;(100)&quot;
43-
<strong>Output:</strong> [(10, 0)]
44-
<strong>Explanation:</strong>
45-
1.0 is not allowed.
53+
<strong>Output:</strong> [&quot;(10, 0)&quot;]
54+
<strong>Explanation:</strong> 1.0 is not allowed.
4655
</pre>
4756

4857
<p>&nbsp;</p>
49-
50-
<p><strong>Note: </strong></p>
58+
<p><strong>Constraints:</strong></p>
5159

5260
<ul>
53-
<li><code>4 &lt;= s.length &lt;= 12</code>.</li>
54-
<li><code>s[0]</code> = &quot;(&quot;, <code>s[s.length - 1]</code> = &quot;)&quot;, and the other elements in <code>s</code> are digits.</li>
61+
<li><code>4 &lt;= s.length &lt;= 12</code></li>
62+
<li><code>s[0] == &#39;(&#39;</code> and <code>s[s.length - 1] == &#39;)&#39;</code>.</li>
63+
<li>The rest of <code>s</code> are digits.</li>
5564
</ul>
5665

57-
<p>&nbsp;</p>
58-
5966
### Related Topics
6067
[[String](../../tag/string/README.md)]

problems/array-nesting/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<p>You are given an integer array <code>nums</code> of length <code>n</code> where <code>nums</code> is a permutation of the numbers in the range <code>[0, n - 1]</code>.</p>
1515

16-
<p>You should build a set <code>s[k] = {nums[k], nums[nums[i]], nums[nums[nums[k]]], ... }</code> subjected to the following rule:</p>
16+
<p>You should build a set <code>s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... }</code> subjected to the following rule:</p>
1717

1818
<ul>
1919
<li>The first element in <code>s[k]</code> starts with the selection of the element <code>nums[k]</code> of <code>index = k</code>.</li>

problems/asteroid-collision/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<p><strong>Constraints:</strong></p>
5555

5656
<ul>
57-
<li><code>2 &lt;= asteroids.length&nbsp;&lt;= 10<sup>4</sup></code></li>
57+
<li><code>2 &lt;= asteroids.length &lt;= 10<sup>4</sup></code></li>
5858
<li><code>-1000 &lt;= asteroids[i] &lt;= 1000</code></li>
5959
<li><code>asteroids[i] != 0</code></li>
6060
</ul>

problems/basic-calculator/README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
## [224. Basic Calculator (Hard)](https://leetcode.com/problems/basic-calculator "基本计算器")
1313

14-
<p>Given a string <code>s</code> representing an expression, implement a basic calculator to evaluate it.</p>
14+
<p>Given a string <code>s</code> representing a valid expression, implement a basic calculator to evaluate it, and return <em>the result of the evaluation</em>.</p>
1515

16-
<p><b data-stringify-type="bold">Note:&nbsp;</b>You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as&nbsp;<code data-stringify-type="code">eval()</code>.</p>
16+
<p><strong>Note:</strong> You are <strong>not</strong> allowed to use any built-in function which evaluates strings as mathematical expressions, such as <code>eval()</code>.</p>
1717

1818
<p>&nbsp;</p>
1919
<p><strong>Example 1:</strong></p>
@@ -37,13 +37,22 @@
3737
<strong>Output:</strong> 23
3838
</pre>
3939

40+
<p><strong>Example 4:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> s = &quot;+48 + -48&quot;
44+
<strong>Output:</strong> 0
45+
<strong>Explanation:</strong>&nbsp;Numbers can have multiple digits and start with +/-.
46+
</pre>
47+
4048
<p>&nbsp;</p>
4149
<p><strong>Constraints:</strong></p>
4250

4351
<ul>
4452
<li><code>1 &lt;= s.length &lt;= 3&nbsp;* 10<sup>5</sup></code></li>
4553
<li><code>s</code> consists of digits, <code>&#39;+&#39;</code>, <code>&#39;-&#39;</code>, <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, and <code>&#39; &#39;</code>.</li>
4654
<li><code>s</code> represents a valid expression.</li>
55+
<li>Every number and running calculation will fit in a signed 32-bit integer.</li>
4756
</ul>
4857

4958
### Related Topics

problems/binary-prefix-divisible-by-5/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
## [1018. Binary Prefix Divisible By 5 (Easy)](https://leetcode.com/problems/binary-prefix-divisible-by-5 "可被 5 整除的二进制前缀")
1313

14-
<p>Given an array <code>A</code> of <code>0</code>s and <code>1</code>s, consider <code>N_i</code>: the i-th subarray from <code>A[0]</code> to <code>A[i]</code>&nbsp;interpreted&nbsp;as a binary number (from most-significant-bit to least-significant-bit.)</p>
14+
<p>Given an array <code>nums</code> of <code>0</code>s and <code>1</code>s, consider <code>x<sub>i</sub></code>: the i-th subarray from <code>nums[0]</code> to <code>nums[i]</code>&nbsp;interpreted&nbsp;as a binary number (from most-significant-bit to least-significant-bit.)</p>
1515

16-
<p>Return a list of booleans&nbsp;<code>answer</code>, where <code>answer[i]</code> is <code>true</code>&nbsp;if and only if <code>N_i</code>&nbsp;is divisible by 5.</p>
16+
<p>Return a list of booleans&nbsp;<code>answer</code>, where <code>answer[i]</code> is <code>true</code>&nbsp;if and only if <code>x<sub>i</sub></code>&nbsp;is divisible by 5.</p>
1717

1818
<p><strong>Example 1:</strong></p>
1919

2020
<pre>
21-
<strong>Input: </strong><span id="example-input-1-1">[0,1,1]</span>
21+
<strong>Input: </strong>nums = <span id="example-input-1-1">[0,1,1]</span>
2222
<strong>Output: </strong><span id="example-output-1">[true,false,false]</span>
2323
<strong>Explanation: </strong>
2424
The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. Only the first number is divisible by 5, so answer[0] is true.
@@ -27,21 +27,21 @@ The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. O
2727
<p><strong>Example 2:</strong></p>
2828

2929
<pre>
30-
<strong>Input: </strong><span id="example-input-2-1">[1,1,1]</span>
30+
<strong>Input: </strong>nums = <span id="example-input-2-1">[1,1,1]</span>
3131
<strong>Output: </strong><span id="example-output-2">[false,false,false]</span>
3232
</pre>
3333

3434
<p><strong>Example 3:</strong></p>
3535

3636
<pre>
37-
<strong>Input: </strong><span id="example-input-3-1">[0,1,1,1,1,1]</span>
37+
<strong>Input: </strong>nums = <span id="example-input-3-1">[0,1,1,1,1,1]</span>
3838
<strong>Output: </strong><span id="example-output-3">[true,false,false,false,true,false]</span>
3939
</pre>
4040

4141
<p><strong>Example 4:</strong></p>
4242

4343
<pre>
44-
<strong>Input: </strong><span id="example-input-4-1">[1,1,1,0,1]</span>
44+
<strong>Input: </strong>nums = <span id="example-input-4-1">[1,1,1,0,1]</span>
4545
<strong>Output: </strong><span id="example-output-4">[false,false,false,false,false]</span>
4646
</pre>
4747

@@ -50,8 +50,8 @@ The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. O
5050
<p><strong>Note:</strong></p>
5151

5252
<ol>
53-
<li><code>1 &lt;= A.length &lt;= 30000</code></li>
54-
<li><code>A[i]</code> is <code>0</code> or <code>1</code></li>
53+
<li><code>1 &lt;= nums.length &lt;= 30000</code></li>
54+
<li><code>nums[i]</code> is <code>0</code> or <code>1</code></li>
5555
</ol>
5656

5757
### Related Topics

problems/binary-search/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<p>Given an array of integers <code>nums</code> which is sorted in ascending order, and an integer <code>target</code>, write a function to search <code>target</code> in <code>nums</code>. If <code>target</code> exists, then return its index. Otherwise, return <code>-1</code>.</p>
1515

16+
<p>You must&nbsp;write an algorithm with&nbsp;<code>O(log n)</code>&nbsp;runtime complexity.</p>
17+
1618
<p>&nbsp;</p>
1719
<p><strong>Example 1:</strong></p>
1820

problems/binary-string-with-substrings-representing-1-to-n/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111

1212
## [1016. Binary String With Substrings Representing 1 To N (Medium)](https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n "子串能表示从 1 到 N 数字的二进制串")
1313

14-
<p>Given a binary string <code>S</code> (a string consisting only of &#39;0&#39; and &#39;1&#39;s) and a positive integer <code>N</code>, return true if and only if for every integer X from 1 to N, the binary representation of X is a substring of S.</p>
14+
<p>Given a binary string <code>s</code> (a string consisting only of &#39;0&#39; and &#39;1&#39;s) and a positive integer <code>n</code>, return true if and only if for every integer <code>x</code> from <code>1</code> to <code>n</code>, the binary representation of <code>x</code> is a substring of <code>s</code>.</p>
1515

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

1818
<p><strong>Example 1:</strong></p>
1919

2020
<pre>
21-
<strong>Input: </strong>S = <span id="example-input-1-1">&quot;0110&quot;</span>, N = <span id="example-input-1-2">3</span>
21+
<strong>Input: </strong>s = <span id="example-input-1-1">&quot;0110&quot;</span>, n = <span id="example-input-1-2">3</span>
2222
<strong>Output: </strong><span id="example-output-1">true</span>
2323
</pre>
2424

2525
<p><strong>Example 2:</strong></p>
2626

2727
<pre>
28-
<strong>Input: </strong>S = <span id="example-input-2-1">&quot;0110&quot;</span>, N = <span id="example-input-2-2">4</span>
28+
<strong>Input: </strong>s = <span id="example-input-2-1">&quot;0110&quot;</span>, n = <span id="example-input-2-2">4</span>
2929
<strong>Output: </strong><span id="example-output-2">false</span>
3030
</pre>
3131

@@ -34,8 +34,8 @@
3434
<p><strong>Note:</strong></p>
3535

3636
<ol>
37-
<li><code>1 &lt;= S.length &lt;= 1000</code></li>
38-
<li><code>1 &lt;= N &lt;= 10^9</code></li>
37+
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
38+
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
3939
</ol>
4040

4141
### Related Topics

problems/binary-subarrays-with-sum/README.md

+22-16
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,38 @@
1111

1212
## [930. Binary Subarrays With Sum (Medium)](https://leetcode.com/problems/binary-subarrays-with-sum "和相同的二元子数组")
1313

14-
<p>In an array <code>nums</code> of <code>0</code>s and <code>1</code>s, how many <strong>non-empty</strong> subarrays have sum <code>goal</code>?</p>
14+
<p>Given a binary array <code>nums</code> and an integer <code>goal</code>, return <em>the number of non-empty <strong>subarrays</strong> with a sum</em> <code>goal</code>.</p>
1515

16-
<p>&nbsp;</p>
16+
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
1717

18+
<p>&nbsp;</p>
1819
<p><strong>Example 1:</strong></p>
1920

2021
<pre>
21-
<strong>Input: </strong>nums = <span id="example-input-1-1">[1,0,1,0,1]</span>, goal = <span id="example-input-1-2">2</span>
22-
<strong>Output: </strong><span id="example-output-1">4</span>
23-
<strong>Explanation: </strong>
24-
The 4 subarrays are bolded below:
25-
[<strong>1,0,1</strong>,0,1]
26-
[<strong>1,0,1,0</strong>,1]
27-
[1,<strong>0,1,0,1</strong>]
28-
[1,0,<strong>1,0,1</strong>]
22+
<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2
23+
<strong>Output:</strong> 4
24+
<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:
25+
[<u><strong>1,0,1</strong></u>,0,1]
26+
[<u><strong>1,0,1,0</strong></u>,1]
27+
[1,<u><strong>0,1,0,1</strong></u>]
28+
[1,0,<u><strong>1,0,1</strong></u>]
2929
</pre>
3030

31-
<p>&nbsp;</p>
31+
<p><strong>Example 2:</strong></p>
3232

33-
<p><strong>Note:</strong></p>
33+
<pre>
34+
<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0
35+
<strong>Output:</strong> 15
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
3440

35-
<ol>
36-
<li><code>nums.length &lt;= 30000</code></li>
41+
<ul>
42+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
43+
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
3744
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
38-
<li><code>nums[i]</code>&nbsp;is either <code>0</code>&nbsp;or <code>1</code>.</li>
39-
</ol>
45+
</ul>
4046

4147
### Related Topics
4248
[[Hash Table](../../tag/hash-table/README.md)]

0 commit comments

Comments
 (0)