Skip to content

Commit 1e14d9e

Browse files
author
Shuo
committed
A: new
1 parent 6450a74 commit 1e14d9e

File tree

118 files changed

+2146
-872
lines changed

Some content is hidden

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

118 files changed

+2146
-872
lines changed

Diff for: README.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1681">1681</span> | [Minimum Incompatibility](https://leetcode.com/problems/minimum-incompatibility "最小不兼容性") | [Go](problems/minimum-incompatibility) | Hard |
74+
| <span id="1680">1680</span> | [Concatenation of Consecutive Binary Numbers](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers "连接连续二进制数字") | [Go](problems/concatenation-of-consecutive-binary-numbers) | Medium |
75+
| <span id="1679">1679</span> | [Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs "K 和数对的最大数目") | [Go](problems/max-number-of-k-sum-pairs) | Medium |
76+
| <span id="1678">1678</span> | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation "设计 Goal 解析器") | [Go](problems/goal-parser-interpretation) | Easy |
77+
| <span id="1677">1677</span> | [Product's Worth Over Invoices](https://leetcode.com/problems/products-worth-over-invoices) 🔒 | [MySQL](problems/products-worth-over-invoices) | Easy |
78+
| <span id="1676">1676</span> | [Lowest Common Ancestor of a Binary Tree IV](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv) 🔒 | [Go](problems/lowest-common-ancestor-of-a-binary-tree-iv) | Medium |
79+
| <span id="1675">1675</span> | [Minimize Deviation in Array](https://leetcode.com/problems/minimize-deviation-in-array "数组的最小偏移量") | [Go](problems/minimize-deviation-in-array) | Hard |
80+
| <span id="1674">1674</span> | [Minimum Moves to Make Array Complementary](https://leetcode.com/problems/minimum-moves-to-make-array-complementary "使数组互补的最少操作次数") | [Go](problems/minimum-moves-to-make-array-complementary) | Medium |
81+
| <span id="1673">1673</span> | [Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence "找出最具竞争力的子序列") | [Go](problems/find-the-most-competitive-subsequence) | Medium |
82+
| <span id="1672">1672</span> | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth "最富有客户的资产总量") | [Go](problems/richest-customer-wealth) | Easy |
83+
| <span id="1671">1671</span> | [Minimum Number of Removals to Make Mountain Array](https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array "得到山形数组的最少删除次数") | [Go](problems/minimum-number-of-removals-to-make-mountain-array) | Hard |
84+
| <span id="1670">1670</span> | [Design Front Middle Back Queue](https://leetcode.com/problems/design-front-middle-back-queue "设计前中后队列") | [Go](problems/design-front-middle-back-queue) | Medium |
85+
| <span id="1669">1669</span> | [Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists "合并两个链表") | [Go](problems/merge-in-between-linked-lists) | Medium |
86+
| <span id="1668">1668</span> | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring "最大重复子字符串") | [Go](problems/maximum-repeating-substring) | Easy |
87+
| <span id="1667">1667</span> | [Fix Names in a Table](https://leetcode.com/problems/fix-names-in-a-table) 🔒 | [MySQL](problems/fix-names-in-a-table) | Easy |
88+
| <span id="1666">1666</span> | [Change the Root of a Binary Tree](https://leetcode.com/problems/change-the-root-of-a-binary-tree) 🔒 | [Go](problems/change-the-root-of-a-binary-tree) | Medium |
89+
| <span id="1665">1665</span> | [Minimum Initial Energy to Finish Tasks](https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks "完成所有任务的最少初始能量") | [Go](problems/minimum-initial-energy-to-finish-tasks) | Hard |
90+
| <span id="1664">1664</span> | [Ways to Make a Fair Array](https://leetcode.com/problems/ways-to-make-a-fair-array "生成平衡数组的方案数") | [Go](problems/ways-to-make-a-fair-array) | Medium |
91+
| <span id="1663">1663</span> | [Smallest String With A Given Numeric Value](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value "具有给定数值的最小字符串") | [Go](problems/smallest-string-with-a-given-numeric-value) | Medium |
92+
| <span id="1662">1662</span> | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent "检查两个字符串数组是否相等") | [Go](problems/check-if-two-string-arrays-are-equivalent) | Easy |
93+
| <span id="1661">1661</span> | [Average Time of Process per Machine](https://leetcode.com/problems/average-time-of-process-per-machine) 🔒 | [MySQL](problems/average-time-of-process-per-machine) | Easy |
94+
| <span id="1660">1660</span> | [Correct a Binary Tree](https://leetcode.com/problems/correct-a-binary-tree "纠正二叉树") 🔒 | [Go](problems/correct-a-binary-tree) | Medium |
7395
| <span id="1659">1659</span> | [Maximize Grid Happiness](https://leetcode.com/problems/maximize-grid-happiness "最大化网格幸福感") | [Go](problems/maximize-grid-happiness) | Hard |
7496
| <span id="1658">1658</span> | [Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero "将 x 减到 0 的最小操作数") | [Go](problems/minimum-operations-to-reduce-x-to-zero) | Medium |
7597
| <span id="1657">1657</span> | [Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close "确定两个字符串是否接近") | [Go](problems/determine-if-two-strings-are-close) | Medium |
@@ -79,7 +101,7 @@ LeetCode Problems' Solutions
79101
| <span id="1653">1653</span> | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced "使字符串平衡的最少删除次数") | [Go](problems/minimum-deletions-to-make-string-balanced) | Medium |
80102
| <span id="1652">1652</span> | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb "拆炸弹") | [Go](problems/defuse-the-bomb) | Easy |
81103
| <span id="1651">1651</span> | [Hopper Company Queries III](https://leetcode.com/problems/hopper-company-queries-iii) 🔒 | [MySQL](problems/hopper-company-queries-iii) | Hard |
82-
| <span id="1650">1650</span> | [Lowest Common Ancestor of a Binary Tree III](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii) 🔒 | [Go](problems/lowest-common-ancestor-of-a-binary-tree-iii) | Medium |
104+
| <span id="1650">1650</span> | [Lowest Common Ancestor of a Binary Tree III](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii "二叉树的最近公共祖先 III") 🔒 | [Go](problems/lowest-common-ancestor-of-a-binary-tree-iii) | Medium |
83105
| <span id="1649">1649</span> | [Create Sorted Array through Instructions](https://leetcode.com/problems/create-sorted-array-through-instructions "通过指令创建有序数组") | [Go](problems/create-sorted-array-through-instructions) | Hard |
84106
| <span id="1648">1648</span> | [Sell Diminishing-Valued Colored Balls](https://leetcode.com/problems/sell-diminishing-valued-colored-balls "销售价值减少的颜色球") | [Go](problems/sell-diminishing-valued-colored-balls) | Medium |
85107
| <span id="1647">1647</span> | [Minimum Deletions to Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique "字符频次唯一的最小删除次数") | [Go](problems/minimum-deletions-to-make-character-frequencies-unique) | Medium |
@@ -149,7 +171,7 @@ LeetCode Problems' Solutions
149171
| <span id="1583">1583</span> | [Count Unhappy Friends](https://leetcode.com/problems/count-unhappy-friends "统计不开心的朋友") | [Go](problems/count-unhappy-friends) | Medium |
150172
| <span id="1582">1582</span> | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix "二进制矩阵中的特殊位置") | [Go](problems/special-positions-in-a-binary-matrix) | Easy |
151173
| <span id="1581">1581</span> | [Customer Who Visited but Did Not Make Any Transactions](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions "进店却未进行过交易的顾客") 🔒 | [MySQL](problems/customer-who-visited-but-did-not-make-any-transactions) | Easy |
152-
| <span id="1580">1580</span> | [Put Boxes Into the Warehouse II](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii) 🔒 | [Go](problems/put-boxes-into-the-warehouse-ii) | Medium |
174+
| <span id="1580">1580</span> | [Put Boxes Into the Warehouse II](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii "把箱子放进仓库里 II") 🔒 | [Go](problems/put-boxes-into-the-warehouse-ii) | Medium |
153175
| <span id="1579">1579</span> | [Remove Max Number of Edges to Keep Graph Fully Traversable](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable "保证图可完全遍历") | [Go](problems/remove-max-number-of-edges-to-keep-graph-fully-traversable) | Hard |
154176
| <span id="1578">1578</span> | [Minimum Deletion Cost to Avoid Repeating Letters](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters "避免重复字母的最小删除成本") | [Go](problems/minimum-deletion-cost-to-avoid-repeating-letters) | Medium |
155177
| <span id="1577">1577</span> | [Number of Ways Where Square of Number Is Equal to Product of Two Numbers](https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers "数的平方等于两数乘积的方法数") | [Go](problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers) | Medium |
@@ -392,7 +414,7 @@ LeetCode Problems' Solutions
392414
| <span id="1340">1340</span> | [Jump Game V](https://leetcode.com/problems/jump-game-v "跳跃游戏 V") | [Go](problems/jump-game-v) | Hard |
393415
| <span id="1339">1339</span> | [Maximum Product of Splitted Binary Tree](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree "分裂二叉树的最大乘积") | [Go](problems/maximum-product-of-splitted-binary-tree) | Medium |
394416
| <span id="1338">1338</span> | [Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half "数组大小减半") | [Go](problems/reduce-array-size-to-the-half) | Medium |
395-
| <span id="1337">1337</span> | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix "方阵中战斗力最弱的 K 行") | [Go](problems/the-k-weakest-rows-in-a-matrix) | Easy |
417+
| <span id="1337">1337</span> | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix "矩阵中战斗力最弱的 K 行") | [Go](problems/the-k-weakest-rows-in-a-matrix) | Easy |
396418
| <span id="1336">1336</span> | [Number of Transactions per Visit](https://leetcode.com/problems/number-of-transactions-per-visit "每次访问的交易次数") 🔒 | [MySQL](problems/number-of-transactions-per-visit) | Hard |
397419
| <span id="1335">1335</span> | [Minimum Difficulty of a Job Schedule](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule "工作计划的最低难度") | [Go](problems/minimum-difficulty-of-a-job-schedule) | Hard |
398420
| <span id="1334">1334</span> | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance "阈值距离内邻居最少的城市") | [Go](problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance) | Medium |
+14
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 <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../correct-a-binary-tree "Correct a Binary Tree")
9+
                
10+
[Next >](../check-if-two-string-arrays-are-equivalent "Check If Two String Arrays are Equivalent")
11+
12+
## [1661. Average Time of Process per Machine (Easy)](https://leetcode.com/problems/average-time-of-process-per-machine "")
13+
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float);
2+
Truncate table Activity;
3+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'start', '0.712');
4+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'end', '1.52');
5+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'start', '3.14');
6+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'end', '4.12');
7+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'start', '0.55');
8+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'end', '1.55');
9+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'start', '0.43');
10+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'end', '1.42');
11+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'start', '4.1');
12+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'end', '4.512');
13+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'start', '2.5');
14+
insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'end', '5');

Diff for: problems/bag-of-tokens/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ There is no need to play the 1<sup>st</sup> token since you cannot play it face
6464

6565
### Related Topics
6666
[[Greedy](../../tag/greedy/README.md)]
67+
[[Sort](../../tag/sort/README.md)]
68+
[[Two Pointers](../../tag/two-pointers/README.md)]

Diff for: problems/basic-calculator-ii/README.md

+17-21
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,34 @@
1111

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

14-
<p>Implement a basic calculator to evaluate a simple expression string.</p>
14+
<p>Given a string <code>s</code> which represents an expression, <em>evaluate this expression and return its value</em>.&nbsp;</p>
1515

16-
<p>The expression string contains only <b>non-negative</b> integers, <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code> operators and empty spaces <code> </code>. The integer division should truncate toward zero.</p>
16+
<p>The integer division should truncate toward zero.</p>
1717

18+
<p>&nbsp;</p>
1819
<p><strong>Example 1:</strong></p>
19-
20-
<pre>
21-
<strong>Input: </strong>&quot;3+2*2&quot;
20+
<pre><strong>Input:</strong> s = "3+2*2"
2221
<strong>Output:</strong> 7
23-
</pre>
24-
25-
<p><strong>Example 2:</strong></p>
26-
27-
<pre>
28-
<strong>Input:</strong> &quot; 3/2 &quot;
29-
<strong>Output:</strong> 1</pre>
30-
31-
<p><strong>Example 3:</strong></p>
32-
33-
<pre>
34-
<strong>Input:</strong> &quot; 3+5 / 2 &quot;
22+
</pre><p><strong>Example 2:</strong></p>
23+
<pre><strong>Input:</strong> s = " 3/2 "
24+
<strong>Output:</strong> 1
25+
</pre><p><strong>Example 3:</strong></p>
26+
<pre><strong>Input:</strong> s = " 3+5 / 2 "
3527
<strong>Output:</strong> 5
3628
</pre>
37-
38-
<p><b>Note:</b></p>
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
3931

4032
<ul>
41-
<li>You may assume that the given expression is always valid.</li>
42-
<li><b>Do not</b> use the <code>eval</code> built-in library function.</li>
33+
<li><code>1 &lt;= s.length &lt;= 3 * 10<sup>5</sup></code></li>
34+
<li><code>s</code> consists of integers and operators <code>(&#39;+&#39;, &#39;-&#39;, &#39;*&#39;, &#39;/&#39;)</code> separated by some number of spaces.</li>
35+
<li><code>s</code> represents <strong>a valid expression</strong>.</li>
36+
<li>All the integers in the expression are non-negative integers in the range <code>[0, 2<sup>31</sup> - 1]</code>.</li>
37+
<li>The answer is <strong>guaranteed</strong> to fit in a <strong>32-bit integer</strong>.</li>
4338
</ul>
4439

4540
### Related Topics
41+
[[Stack](../../tag/stack/README.md)]
4642
[[String](../../tag/string/README.md)]
4743

4844
### Similar Questions

Diff for: problems/binary-search-tree-iterator/README.md

+36-20
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,55 @@
1111

1212
## [173. Binary Search Tree Iterator (Medium)](https://leetcode.com/problems/binary-search-tree-iterator "二叉搜索树迭代器")
1313

14-
<p>Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.</p>
15-
16-
<p>Calling <code>next()</code> will return the next smallest number in the BST.</p>
17-
18-
<p>&nbsp;</p>
14+
<p>Implement the <code>BSTIterator</code> class that represents an iterator over&nbsp;the <strong><a href="https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR)">in-order traversal</a></strong>&nbsp;of&nbsp;a binary search tree (BST):</p>
1915

2016
<ul>
17+
<li><code>BSTIterator(TreeNode root)</code> Initializes an object of the <code>BSTIterator</code> class. The <code>root</code> of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.</li>
18+
<li><code>boolean hasNext()</code> Returns <code>true</code> if there exists a number in the traversal to the right of the pointer, otherwise returns <code>false</code>.</li>
19+
<li><code>int next()</code> Moves the pointer to the right, then returns the number at the pointer.</li>
2120
</ul>
2221

23-
<p><strong>Example:</strong></p>
22+
<p>Notice that by initializing the pointer to a non-existent smallest number, the first call to <code>next()</code> will return the smallest element in the BST.</p>
2423

25-
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png" style="width: 189px; height: 178px;" /></strong></p>
24+
<p>You may assume that <code>next()</code>&nbsp;calls will always be valid. That is, there will be at least a next number in the in-order traversal&nbsp;when <code>next()</code>&nbsp;is called.</p>
2625

26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png" style="width: 189px; height: 178px;" />
2729
<pre>
28-
BSTIterator iterator = new BSTIterator(root);
29-
iterator.next(); // return 3
30-
iterator.next(); // return 7
31-
iterator.hasNext(); // return true
32-
iterator.next(); // return 9
33-
iterator.hasNext(); // return true
34-
iterator.next(); // return 15
35-
iterator.hasNext(); // return true
36-
iterator.next(); // return 20
37-
iterator.hasNext(); // return false
30+
<strong>Input</strong>
31+
[&quot;BSTIterator&quot;, &quot;next&quot;, &quot;next&quot;, &quot;hasNext&quot;, &quot;next&quot;, &quot;hasNext&quot;, &quot;next&quot;, &quot;hasNext&quot;, &quot;next&quot;, &quot;hasNext&quot;]
32+
[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
33+
<strong>Output</strong>
34+
[null, 3, 7, true, 9, true, 15, true, 20, false]
35+
36+
<strong>Explanation</strong>
37+
BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);
38+
bSTIterator.next(); // return 3
39+
bSTIterator.next(); // return 7
40+
bSTIterator.hasNext(); // return True
41+
bSTIterator.next(); // return 9
42+
bSTIterator.hasNext(); // return True
43+
bSTIterator.next(); // return 15
44+
bSTIterator.hasNext(); // return True
45+
bSTIterator.next(); // return 20
46+
bSTIterator.hasNext(); // return False
3847
</pre>
3948

4049
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
4151

42-
<p><b>Note:</b></p>
52+
<ul>
53+
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
54+
<li><code>0 &lt;= Node.val &lt;= 10<sup>6</sup></code></li>
55+
<li>At most <code>10<sup>5</sup></code> calls will be made to <code>hasNext</code>, and <code>next</code>.</li>
56+
</ul>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Follow up:</strong></p>
4360

4461
<ul>
45-
<li><code>next()</code> and <code>hasNext()</code> should run in average O(1) time and uses O(<i>h</i>) memory, where <i>h</i> is the height of the tree.</li>
46-
<li>You may assume that&nbsp;<code>next()</code>&nbsp;call&nbsp;will always be valid, that is, there will be at least a next smallest number in the BST when <code>next()</code> is called.</li>
62+
<li>Could you implement <code>next()</code> and <code>hasNext()</code> to run in average <code>O(1)</code> time and use&nbsp;<code>O(h)</code> memory, where <code>h</code> is the height of the tree?</li>
4763
</ul>
4864

4965
### Related Topics

0 commit comments

Comments
 (0)