Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef2bad3

Browse files
author
Shuo
authored
Merge pull request #788 from openset/develop
A: new
2 parents d51c69e + d45a97b commit ef2bad3

File tree

26 files changed

+444
-163
lines changed

26 files changed

+444
-163
lines changed

‎README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <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 |
66+
| <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 |
67+
| <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 |
68+
| <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 |
69+
| <span id="1440">1440</span> | [Evaluate Boolean Expression](https://leetcode.com/problems/evaluate-boolean-expression) 🔒 | [MySQL](problems/evaluate-boolean-expression) | Medium |
6570
| <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 |
6671
| <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 |
6772
| <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 |
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../evaluate-boolean-expression "Evaluate Boolean Expression")
9+
10+
[Next >](../count-triplets-that-can-form-two-arrays-of-equal-xor "Count Triplets That Can Form Two Arrays of Equal XOR")
11+
12+
## [1441. Build an Array With Stack Operations (Easy)](https://leetcode.com/problems/build-an-array-with-stack-operations "用栈操作构建数组")
13+
14+
<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>
15+
16+
<p>Build the <code>target</code>&nbsp;array&nbsp;using the following operations:</p>
17+
18+
<ul>
19+
<li><strong>Push</strong>: Read a new element from the beginning&nbsp;<code>list</code>, and push it in the array.</li>
20+
<li><strong>Pop</strong>: delete the last element of&nbsp;the array.</li>
21+
<li>If the target array is already&nbsp;built, stop reading more elements.</li>
22+
</ul>
23+
24+
<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>
25+
26+
<p>Return the operations to build the target array.</p>
27+
28+
<p>You are guaranteed that the answer is unique.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong>Example 1:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> target = [1,3], n = 3
35+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;,&quot;Pop&quot;,&quot;Push&quot;]
36+
<strong>Explanation:
37+
</strong>Read number 1 and automatically push in the array -&gt; [1]
38+
Read number 2 and automatically push in the array then Pop it -&gt; [1]
39+
Read number 3 and automatically push in the array -&gt; [1,3]
40+
</pre>
41+
42+
<p><strong>Example 2:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> target = [1,2,3], n = 3
46+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;,&quot;Push&quot;]
47+
</pre>
48+
49+
<p><strong>Example 3:</strong></p>
50+
51+
<pre>
52+
<strong>Input:</strong> target = [1,2], n = 4
53+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Push&quot;]
54+
<strong>Explanation: </strong>You only need to read the first 2 numbers and stop.
55+
</pre>
56+
57+
<p><strong>Example 4:</strong></p>
58+
59+
<pre>
60+
<strong>Input:</strong> target = [2,3,4], n = 4
61+
<strong>Output:</strong> [&quot;Push&quot;,&quot;Pop&quot;,&quot;Push&quot;,&quot;Push&quot;,&quot;Push&quot;]
62+
</pre>
63+
64+
<p>&nbsp;</p>
65+
<p><strong>Constraints:</strong></p>
66+
67+
<ul>
68+
<li><code>1 &lt;= target.length &lt;= 100</code></li>
69+
<li><code>1 &lt;= target[i]&nbsp;&lt;= 100</code></li>
70+
<li><code>1 &lt;= n &lt;= 100</code></li>
71+
<li><code>target</code> is strictly&nbsp;increasing.</li>
72+
</ul>
73+
74+
### Related Topics
75+
[[Stack](../../tag/stack/README.md)]
76+
77+
### Hints
78+
<details>
79+
<summary>Hint 1</summary>
80+
Use "Push" for numbers to be kept in target array and ["Push", "Pop"] for numbers to be discarded.
81+
</details>

‎problems/constrained-subset-sum/README.md

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../build-an-array-with-stack-operations "Build an Array With Stack Operations")
9+
10+
[Next >](../minimum-time-to-collect-all-apples-in-a-tree "Minimum Time to Collect All Apples in a Tree")
11+
12+
## [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 "形成两个异或相等数组的三元组数目")
13+
14+
<p>Given an array of&nbsp;integers <code>arr</code>.</p>
15+
16+
<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>
17+
18+
<p>Let&#39;s define <code>a</code> and <code>b</code> as follows:</p>
19+
20+
<ul>
21+
<li><code>a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]</code></li>
22+
<li><code>b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]</code></li>
23+
</ul>
24+
25+
<p>Note that <strong>^</strong> denotes the <strong>bitwise-xor</strong> operation.</p>
26+
27+
<p>Return <em>the number of triplets</em> (<code>i</code>, <code>j</code> and <code>k</code>) Where <code>a == b</code>.</p>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Example 1:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> arr = [2,3,1,6,7]
34+
<strong>Output:</strong> 4
35+
<strong>Explanation:</strong> The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)
36+
</pre>
37+
38+
<p><strong>Example 2:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> arr = [1,1,1,1,1]
42+
<strong>Output:</strong> 10
43+
</pre>
44+
45+
<p><strong>Example 3:</strong></p>
46+
47+
<pre>
48+
<strong>Input:</strong> arr = [2,3]
49+
<strong>Output:</strong> 0
50+
</pre>
51+
52+
<p><strong>Example 4:</strong></p>
53+
54+
<pre>
55+
<strong>Input:</strong> arr = [1,3,5,7,9]
56+
<strong>Output:</strong> 3
57+
</pre>
58+
59+
<p><strong>Example 5:</strong></p>
60+
61+
<pre>
62+
<strong>Input:</strong> arr = [7,11,12,9,5,2,7,17,22]
63+
<strong>Output:</strong> 8
64+
</pre>
65+
66+
<p>&nbsp;</p>
67+
<p><strong>Constraints:</strong></p>
68+
69+
<ul>
70+
<li><code>1 &lt;= arr.length &lt;= 300</code></li>
71+
<li><code>1 &lt;= arr[i] &lt;= 10^8</code></li>
72+
</ul>
73+
74+
### Related Topics
75+
[[Bit Manipulation](../../tag/bit-manipulation/README.md)]
76+
[[Array](../../tag/array/README.md)]
77+
[[Math](../../tag/math/README.md)]
78+
79+
### Hints
80+
<details>
81+
<summary>Hint 1</summary>
82+
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.
83+
</details>
84+
85+
<details>
86+
<summary>Hint 2</summary>
87+
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.
88+
</details>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows "Find the Kth Smallest Sum of a Matrix With Sorted Rows")
9+
10+
[Next >](../build-an-array-with-stack-operations "Build an Array With Stack Operations")
11+
12+
## [1440. Evaluate Boolean Expression (Medium)](https://leetcode.com/problems/evaluate-boolean-expression "")
13+
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Create Table If Not Exists Variables (name varchar(3), value int);
2+
Create Table If Not Exists Expressions (left_operand varchar(3), operator ENUM('>', '<', '='), right_operand varchar(3));
3+
Truncate table Variables;
4+
insert into Variables (name, value) values ('x', '66');
5+
insert into Variables (name, value) values ('y', '77');
6+
Truncate table Expressions;
7+
insert into Expressions (left_operand, operator, right_operand) values ('x', '>', 'y');
8+
insert into Expressions (left_operand, operator, right_operand) values ('x', '<', 'y');
9+
insert into Expressions (left_operand, operator, right_operand) values ('x', '=', 'y');
10+
insert into Expressions (left_operand, operator, right_operand) values ('y', '>', 'x');
11+
insert into Expressions (left_operand, operator, right_operand) values ('y', '<', 'x');
12+
insert into Expressions (left_operand, operator, right_operand) values ('x', '=', 'x');

‎problems/find-k-closest-elements/README.md

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,24 @@
1111

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

14-
<p>
15-
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.
16-
If there is a tie, the smaller elements are always preferred.
17-
</p>
18-
19-
<p><b>Example 1:</b><br />
20-
<pre>
21-
<b>Input:</b> [1,2,3,4,5], k=4, x=3
22-
<b>Output:</b> [1,2,3,4]
23-
</pre>
24-
</p>
25-
26-
27-
<p><b>Example 2:</b><br />
28-
<pre>
29-
<b>Input:</b> [1,2,3,4,5], k=4, x=-1
30-
<b>Output:</b> [1,2,3,4]
14+
<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>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
<pre><strong>Input:</strong> arr = [1,2,3,4,5], k = 4, x = 3
19+
<strong>Output:</strong> [1,2,3,4]
20+
</pre><p><strong>Example 2:</strong></p>
21+
<pre><strong>Input:</strong> arr = [1,2,3,4,5], k = 4, x = -1
22+
<strong>Output:</strong> [1,2,3,4]
3123
</pre>
32-
</p>
33-
34-
<p><b>Note:</b><br>
35-
<ol>
36-
<li>The value k is positive and will always be smaller than the length of the sorted array.</li>
37-
<li> Length of the given array is positive and will not exceed 10<sup>4</sup></li>
38-
<li> Absolute value of elements in the array and x will not exceed 10<sup>4</sup></li>
39-
</ol>
40-
</p>
41-
42-
<hr />
43-
44-
<p>
45-
<b><font color="red">UPDATE (2017年9月19日):</font></b><br />
46-
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>.
47-
</p>
24+
<p>&nbsp;</p>
25+
<p><strong>Constraints:</strong></p>
26+
27+
<ul>
28+
<li><code>1 &lt;= k &lt;= arr.length</code></li>
29+
<li><code>1 &lt;= arr.length&nbsp;&lt;= 10^4</code></li>
30+
<li>Absolute value of elements in the array and <code>x</code> will not exceed 10<sup>4</sup></li>
31+
</ul>
4832

4933
### Related Topics
5034
[[Binary Search](../../tag/binary-search/README.md)]

‎problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows/README.md

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

88
[< 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")
99

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

1212
## [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 个最小数组和")
1313

‎problems/insert-into-a-binary-search-tree/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ And the value to insert: 5
4949
4
5050
</pre>
5151

52+
<p>&nbsp;</p>
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li>The number of nodes in the given tree will be between <code>0</code> and <code>10^4</code>.</li>
57+
<li>Each node will have a unique integer value from <code>0</code>&nbsp;to -<code>10^8</code>, inclusive.</li>
58+
<li><code>-10^8 &lt;= val &lt;= 10^8</code></li>
59+
<li>It&#39;s guaranteed that <code>val</code> does not exist in the original BST.</li>
60+
</ul>
61+
5262
### Related Topics
5363
[[Tree](../../tag/tree/README.md)]
5464

‎problems/median-of-two-sorted-arrays/README.md

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

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

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

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /