Skip to content

A: new #788

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 2 commits into from
May 11, 2020
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1444">1444</span> | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza "切披萨的方案数") | [Go](problems/number-of-ways-of-cutting-a-pizza) | Hard |
| <span id="1443">1443</span> | [Minimum Time to Collect All Apples in a Tree](https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree "收集树上所有苹果的最少时间") | [Go](problems/minimum-time-to-collect-all-apples-in-a-tree) | Medium |
| <span id="1442">1442</span> | [Count Triplets That Can Form Two Arrays of Equal XOR](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor "形成两个异或相等数组的三元组数目") | [Go](problems/count-triplets-that-can-form-two-arrays-of-equal-xor) | Medium |
| <span id="1441">1441</span> | [Build an Array With Stack Operations](https://leetcode.com/problems/build-an-array-with-stack-operations "用栈操作构建数组") | [Go](problems/build-an-array-with-stack-operations) | Easy |
| <span id="1440">1440</span> | [Evaluate Boolean Expression](https://leetcode.com/problems/evaluate-boolean-expression) 🔒 | [MySQL](problems/evaluate-boolean-expression) | Medium |
| <span id="1439">1439</span> | [Find the Kth Smallest Sum of a Matrix With Sorted Rows](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows "有序矩阵中的第 k 个最小数组和") | [Go](problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows) | Hard |
| <span id="1438">1438</span> | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit "绝对差不超过限制的最长连续子数组") | [Go](problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) | Medium |
| <span id="1437">1437</span> | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素") | [Go](problems/check-if-all-1s-are-at-least-length-k-places-away) | Medium |
Expand Down
81 changes: 81 additions & 0 deletions problems/build-an-array-with-stack-operations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../evaluate-boolean-expression "Evaluate Boolean Expression")

[Next >](../count-triplets-that-can-form-two-arrays-of-equal-xor "Count Triplets That Can Form Two Arrays of Equal XOR")

## [1441. Build an Array With Stack Operations (Easy)](https://leetcode.com/problems/build-an-array-with-stack-operations "用栈操作构建数组")

<p>Given an array <code>target</code> and&nbsp;an integer <code>n</code>. In each iteration, you will read a number from &nbsp;<code>list = {1,2,3..., n}</code>.</p>

<p>Build the <code>target</code>&nbsp;array&nbsp;using the following operations:</p>

<ul>
<li><strong>Push</strong>: Read a new element from the beginning&nbsp;<code>list</code>, and push it in the array.</li>
<li><strong>Pop</strong>: delete the last element of&nbsp;the array.</li>
<li>If the target array is already&nbsp;built, stop reading more elements.</li>
</ul>

<p>You are guaranteed that the target array is strictly&nbsp;increasing, only containing&nbsp;numbers between 1 to <code>n</code>&nbsp;inclusive.</p>

<p>Return the operations to build the target array.</p>

<p>You are guaranteed that the answer is unique.</p>

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

<pre>
<strong>Input:</strong> target = [1,3], n = 3
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;,&quot;Pop&quot;,&quot;Push&quot;]
<strong>Explanation:
</strong>Read number 1 and automatically push in the array -&gt; [1]
Read number 2 and automatically push in the array then Pop it -&gt; [1]
Read number 3 and automatically push in the array -&gt; [1,3]
</pre>

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

<pre>
<strong>Input:</strong> target = [1,2,3], n = 3
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;,&quot;Push&quot;]
</pre>

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

<pre>
<strong>Input:</strong> target = [1,2], n = 4
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;]
<strong>Explanation: </strong>You only need to read the first 2 numbers and stop.
</pre>

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

<pre>
<strong>Input:</strong> target = [2,3,4], n = 4
<strong>Output:</strong> [&quot;Push&quot;,&quot;Pop&quot;,&quot;Push&quot;,&quot;Push&quot;,&quot;Push&quot;]
</pre>

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

<ul>
<li><code>1 &lt;= target.length &lt;= 100</code></li>
<li><code>1 &lt;= target[i]&nbsp;&lt;= 100</code></li>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>target</code> is strictly&nbsp;increasing.</li>
</ul>

### Related Topics
[[Stack](../../tag/stack/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Use “Push” for numbers to be kept in target array and [“Push”, “Pop”] for numbers to be discarded.
</details>
73 changes: 0 additions & 73 deletions problems/constrained-subset-sum/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../build-an-array-with-stack-operations "Build an Array With Stack Operations")

[Next >](../minimum-time-to-collect-all-apples-in-a-tree "Minimum Time to Collect All Apples in a Tree")

## [1442. Count Triplets That Can Form Two Arrays of Equal XOR (Medium)](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor "形成两个异或相等数组的三元组数目")

<p>Given an array of&nbsp;integers <code>arr</code>.</p>

<p>We want to select three indices <code>i</code>, <code>j</code> and <code>k</code> where <code>(0 &lt;= i &lt; j &lt;= k &lt; arr.length)</code>.</p>

<p>Let&#39;s define <code>a</code> and <code>b</code> as follows:</p>

<ul>
<li><code>a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]</code></li>
<li><code>b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]</code></li>
</ul>

<p>Note that <strong>^</strong> denotes the <strong>bitwise-xor</strong> operation.</p>

<p>Return <em>the number of triplets</em> (<code>i</code>, <code>j</code> and <code>k</code>) Where <code>a == b</code>.</p>

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

<pre>
<strong>Input:</strong> arr = [2,3,1,6,7]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)
</pre>

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

<pre>
<strong>Input:</strong> arr = [1,1,1,1,1]
<strong>Output:</strong> 10
</pre>

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

<pre>
<strong>Input:</strong> arr = [2,3]
<strong>Output:</strong> 0
</pre>

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

<pre>
<strong>Input:</strong> arr = [1,3,5,7,9]
<strong>Output:</strong> 3
</pre>

<p><strong>Example 5:</strong></p>

<pre>
<strong>Input:</strong> arr = [7,11,12,9,5,2,7,17,22]
<strong>Output:</strong> 8
</pre>

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

<ul>
<li><code>1 &lt;= arr.length &lt;= 300</code></li>
<li><code>1 &lt;= arr[i] &lt;= 10^8</code></li>
</ul>

### Related Topics
[[Bit Manipulation](../../tag/bit-manipulation/README.md)]
[[Array](../../tag/array/README.md)]
[[Math](../../tag/math/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
We are searching for sub-array of length ≥ 2 and we need to split it to 2 non-empty arrays so that the xor of the first array is equal to the xor of the second array. This is equivalent to searching for sub-array with xor = 0.
</details>

<details>
<summary>Hint 2</summary>
Keep the prefix xor of arr in another array, check the xor of all sub-arrays in O(n^2), if the xor of sub-array of length x is 0 add x-1 to the answer.
</details>
14 changes: 14 additions & 0 deletions problems/evaluate-boolean-expression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows "Find the Kth Smallest Sum of a Matrix With Sorted Rows")

[Next >](../build-an-array-with-stack-operations "Build an Array With Stack Operations")

## [1440. Evaluate Boolean Expression (Medium)](https://leetcode.com/problems/evaluate-boolean-expression "")


12 changes: 12 additions & 0 deletions problems/evaluate-boolean-expression/mysql_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Create Table If Not Exists Variables (name varchar(3), value int);
Create Table If Not Exists Expressions (left_operand varchar(3), operator ENUM('>', '<', '='), right_operand varchar(3));
Truncate table Variables;
insert into Variables (name, value) values ('x', '66');
insert into Variables (name, value) values ('y', '77');
Truncate table Expressions;
insert into Expressions (left_operand, operator, right_operand) values ('x', '>', 'y');
insert into Expressions (left_operand, operator, right_operand) values ('x', '<', 'y');
insert into Expressions (left_operand, operator, right_operand) values ('x', '=', 'y');
insert into Expressions (left_operand, operator, right_operand) values ('y', '>', 'x');
insert into Expressions (left_operand, operator, right_operand) values ('y', '<', 'x');
insert into Expressions (left_operand, operator, right_operand) values ('x', '=', 'x');
50 changes: 17 additions & 33 deletions problems/find-k-closest-elements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,24 @@

## [658. Find K Closest Elements (Medium)](https://leetcode.com/problems/find-k-closest-elements "找到 K 个最接近的元素")

<p>
Given a sorted array, two integers <code>k</code> and <code>x</code>, find the <code>k</code> closest elements to <code>x</code> in the array. The result should also be sorted in ascending order.
If there is a tie, the smaller elements are always preferred.
</p>

<p><b>Example 1:</b><br />
<pre>
<b>Input:</b> [1,2,3,4,5], k=4, x=3
<b>Output:</b> [1,2,3,4]
</pre>
</p>


<p><b>Example 2:</b><br />
<pre>
<b>Input:</b> [1,2,3,4,5], k=4, x=-1
<b>Output:</b> [1,2,3,4]
<p>Given a sorted array <code>arr</code>, two integers <code>k</code> and <code>x</code>, find the <code>k</code> closest elements to <code>x</code> in the array. The result should also be sorted in ascending order. If there is a tie, the smaller elements are always preferred.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre><strong>Input:</strong> arr = [1,2,3,4,5], k = 4, x = 3
<strong>Output:</strong> [1,2,3,4]
</pre><p><strong>Example 2:</strong></p>
<pre><strong>Input:</strong> arr = [1,2,3,4,5], k = 4, x = -1
<strong>Output:</strong> [1,2,3,4]
</pre>
</p>

<p><b>Note:</b><br>
<ol>
<li>The value k is positive and will always be smaller than the length of the sorted array.</li>
<li> Length of the given array is positive and will not exceed 10<sup>4</sup></li>
<li> Absolute value of elements in the array and x will not exceed 10<sup>4</sup></li>
</ol>
</p>

<hr />

<p>
<b><font color="red">UPDATE (2017/9/19):</font></b><br />
The <i>arr</i> parameter had been changed to an <b>array of integers</b> (instead of a list of integers). <b><i>Please reload the code definition to get the latest changes</i></b>.
</p>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= k &lt;= arr.length</code></li>
<li><code>1 &lt;= arr.length&nbsp;&lt;= 10^4</code></li>
<li>Absolute value of elements in the array and <code>x</code> will not exceed 10<sup>4</sup></li>
</ul>

### Related Topics
[[Binary Search](../../tag/binary-search/README.md)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< Previous](../longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit")

Next >
[Next >](../evaluate-boolean-expression "Evaluate Boolean Expression")

## [1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows (Hard)](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows "有序矩阵中的第 k 个最小数组和")

Expand Down
10 changes: 10 additions & 0 deletions problems/insert-into-a-binary-search-tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ And the value to insert: 5
4
</pre>

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

<ul>
<li>The number of nodes in the given tree will be between <code>0</code> and <code>10^4</code>.</li>
<li>Each node will have a unique integer value from <code>0</code>&nbsp;to -<code>10^8</code>, inclusive.</li>
<li><code>-10^8 &lt;= val &lt;= 10^8</code></li>
<li>It&#39;s guaranteed that <code>val</code> does not exist in the original BST.</li>
</ul>

### Related Topics
[[Tree](../../tag/tree/README.md)]

Expand Down
2 changes: 1 addition & 1 deletion problems/median-of-two-sorted-arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Next >](../longest-palindromic-substring "Longest Palindromic Substring")

## [4. Median of Two Sorted Arrays (Hard)](https://leetcode.com/problems/median-of-two-sorted-arrays "寻找两个有序数组的中位数")
## [4. Median of Two Sorted Arrays (Hard)](https://leetcode.com/problems/median-of-two-sorted-arrays "寻找两个正序数组的中位数")

<p>There are two sorted arrays <b>nums1</b> and <b>nums2</b> of size m and n respectively.</p>

Expand Down
Loading