Skip to content

A: new #839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions README.md

Large diffs are not rendered by default.

47 changes: 27 additions & 20 deletions problems/1-bit-and-2-bit-characters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,41 @@

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

<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>
<p>We have two special characters:</p>

<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>
<ul>
<li>The first character can be represented by one bit <code>0</code>.</li>
<li>The second character can be represented by two bits (<code>10</code> or <code>11</code>).</li>
</ul>

<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>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b>
bits = [1, 0, 0]
<b>Output:</b> True
<b>Explanation:</b>
The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
<strong>Input:</strong> bits = [1,0,0]
<strong>Output:</strong> true
<strong>Explanation:</strong> The only way to decode it is two-bit character and one-bit character.
So the last character is one-bit character.
</pre>
</p>

<p><b>Example 2:</b><br />
<p><strong>Example 2:</strong></p>

<pre>
<b>Input:</b>
bits = [1, 1, 1, 0]
<b>Output:</b> False
<b>Explanation:</b>
The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.
<strong>Input:</strong> bits = [1,1,1,0]
<strong>Output:</strong> false
<strong>Explanation:</strong> The only way to decode it is two-bit character and two-bit character.
So the last character is not one-bit character.
</pre>
</p>

<p><b>Note:</b>
<li><code>1 <= len(bits) <= 1000</code>.</li>
<li><code>bits[i]</code> is always <code>0</code> or <code>1</code>.</li>
</p>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= bits.length &lt;= 1000</code></li>
<li><code>bits[i]</code> is either <code>0</code> or <code>1</code>.</li>
</ul>

### Related Topics
[[Array](../../tag/array/README.md)]
Expand Down
4 changes: 1 addition & 3 deletions problems/132-pattern/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<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>

<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>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

Expand Down Expand Up @@ -47,7 +45,7 @@

<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= n &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion problems/ad-free-sessions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

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

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


53 changes: 30 additions & 23 deletions problems/ambiguous-coordinates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,57 @@

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

<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>
<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>

<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>
<ul>
<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>
</ul>

<p>Return <em>a list of strings representing all possibilities for what our original coordinates could have been</em>.</p>

<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>

<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>
<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>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Example 1:</strong>
<strong>Input:</strong> s = &quot;(123)&quot;
<strong>Output:</strong> [&quot;(1, 23)&quot;, &quot;(12, 3)&quot;, &quot;(1.2, 3)&quot;, &quot;(1, 2.3)&quot;]
<strong>Output:</strong> [&quot;(1, 2.3)&quot;,&quot;(1, 23)&quot;,&quot;(1.2, 3)&quot;,&quot;(12, 3)&quot;]
</pre>

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

<pre>
<strong>Example 2:</strong>
<strong>Input:</strong> s = &quot;(00011)&quot;
<strong>Output:</strong> &nbsp;[&quot;(0.001, 1)&quot;, &quot;(0, 0.011)&quot;]
<strong>Explanation:</strong>
0.0, 00, 0001 or 00.01 are not allowed.
<strong>Input:</strong> s = &quot;(0123)&quot;
<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;]
<strong>Explanation:</strong> 0.0, 00, 0001 or 00.01 are not allowed.
</pre>

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

<pre>
<strong>Example 3:</strong>
<strong>Input:</strong> s = &quot;(0123)&quot;
<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;]
<strong>Input:</strong> s = &quot;(00011)&quot;
<strong>Output:</strong> [&quot;(0, 0.011)&quot;,&quot;(0.001, 1)&quot;]
</pre>

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

<pre>
<strong>Example 4:</strong>
<strong>Input:</strong> s = &quot;(100)&quot;
<strong>Output:</strong> [(10, 0)]
<strong>Explanation:</strong>
1.0 is not allowed.
<strong>Output:</strong> [&quot;(10, 0)&quot;]
<strong>Explanation:</strong> 1.0 is not allowed.
</pre>

<p>&nbsp;</p>

<p><strong>Note: </strong></p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>4 &lt;= s.length &lt;= 12</code>.</li>
<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>
<li><code>4 &lt;= s.length &lt;= 12</code></li>
<li><code>s[0] == &#39;(&#39;</code> and <code>s[s.length - 1] == &#39;)&#39;</code>.</li>
<li>The rest of <code>s</code> are digits.</li>
</ul>

<p>&nbsp;</p>

### Related Topics
[[String](../../tag/string/README.md)]
2 changes: 1 addition & 1 deletion problems/array-nesting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<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>

<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>
<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>

<ul>
<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>
Expand Down
2 changes: 1 addition & 1 deletion problems/asteroid-collision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= asteroids.length&nbsp;&lt;= 10<sup>4</sup></code></li>
<li><code>2 &lt;= asteroids.length &lt;= 10<sup>4</sup></code></li>
<li><code>-1000 &lt;= asteroids[i] &lt;= 1000</code></li>
<li><code>asteroids[i] != 0</code></li>
</ul>
Expand Down
13 changes: 11 additions & 2 deletions problems/basic-calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

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

<p>Given a string <code>s</code> representing an expression, implement a basic calculator to evaluate it.</p>
<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>

<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>
<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>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
Expand All @@ -37,13 +37,22 @@
<strong>Output:</strong> 23
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;+48 + -48&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong>&nbsp;Numbers can have multiple digits and start with +/-.
</pre>

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

<ul>
<li><code>1 &lt;= s.length &lt;= 3&nbsp;* 10<sup>5</sup></code></li>
<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>
<li><code>s</code> represents a valid expression.</li>
<li>Every number and running calculation will fit in a signed 32-bit integer.</li>
</ul>

### Related Topics
Expand Down
16 changes: 8 additions & 8 deletions problems/binary-prefix-divisible-by-5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

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

<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>
<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>

<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>
<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>

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

<pre>
<strong>Input: </strong><span id="example-input-1-1">[0,1,1]</span>
<strong>Input: </strong>nums = <span id="example-input-1-1">[0,1,1]</span>
<strong>Output: </strong><span id="example-output-1">[true,false,false]</span>
<strong>Explanation: </strong>
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.
Expand All @@ -27,21 +27,21 @@ The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. O
<p><strong>Example 2:</strong></p>

<pre>
<strong>Input: </strong><span id="example-input-2-1">[1,1,1]</span>
<strong>Input: </strong>nums = <span id="example-input-2-1">[1,1,1]</span>
<strong>Output: </strong><span id="example-output-2">[false,false,false]</span>
</pre>

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

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

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

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

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

<ol>
<li><code>1 &lt;= A.length &lt;= 30000</code></li>
<li><code>A[i]</code> is <code>0</code> or <code>1</code></li>
<li><code>1 &lt;= nums.length &lt;= 30000</code></li>
<li><code>nums[i]</code> is <code>0</code> or <code>1</code></li>
</ol>

### Related Topics
Expand Down
2 changes: 2 additions & 0 deletions problems/binary-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

<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>

<p>You must&nbsp;write an algorithm with&nbsp;<code>O(log n)</code>&nbsp;runtime complexity.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@

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

<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>
<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>

<p>&nbsp;</p>

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

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

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

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

Expand All @@ -34,8 +34,8 @@
<p><strong>Note:</strong></p>

<ol>
<li><code>1 &lt;= S.length &lt;= 1000</code></li>
<li><code>1 &lt;= N &lt;= 10^9</code></li>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ol>

### Related Topics
Expand Down
38 changes: 22 additions & 16 deletions problems/binary-subarrays-with-sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,38 @@

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

<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>
<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>

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

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<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>
<strong>Output: </strong><span id="example-output-1">4</span>
<strong>Explanation: </strong>
The 4 subarrays are bolded below:
[<strong>1,0,1</strong>,0,1]
[<strong>1,0,1,0</strong>,1]
[1,<strong>0,1,0,1</strong>]
[1,0,<strong>1,0,1</strong>]
<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2
<strong>Output:</strong> 4
<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:
[<u><strong>1,0,1</strong></u>,0,1]
[<u><strong>1,0,1,0</strong></u>,1]
[1,<u><strong>0,1,0,1</strong></u>]
[1,0,<u><strong>1,0,1</strong></u>]
</pre>

<p>&nbsp;</p>
<p><strong>Example 2:</strong></p>

<p><strong>Note:</strong></p>
<pre>
<strong>Input:</strong> nums = [0,0,0,0,0], goal = 0
<strong>Output:</strong> 15
</pre>

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

<ol>
<li><code>nums.length &lt;= 30000</code></li>
<ul>
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
<li><code>0 &lt;= goal &lt;= nums.length</code></li>
<li><code>nums[i]</code>&nbsp;is either <code>0</code>&nbsp;or <code>1</code>.</li>
</ol>
</ul>

### Related Topics
[[Hash Table](../../tag/hash-table/README.md)]
Expand Down
Loading