Skip to content

Commit a7c50eb

Browse files
author
Shuo
committed
A: new
1 parent 6cc9b8e commit a7c50eb

File tree

160 files changed

+2232
-1077
lines changed

Some content is hidden

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

160 files changed

+2232
-1077
lines changed

README.md

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

problems/array-of-doubled-pairs/README.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,45 @@
1111

1212
## [954. Array of Doubled Pairs (Medium)](https://leetcode.com/problems/array-of-doubled-pairs "二倍数对数组")
1313

14-
<p>Given an array of integers <code>A</code>&nbsp;with even length, return <code>true</code> if and only if it is possible to reorder it such that <code>A[2 * i + 1] = 2 * A[2 * i]</code> for every <code>0 &lt;=&nbsp;i &lt; len(A) / 2</code>.</p>
15-
16-
<div>
17-
<div>
18-
<div>
19-
<ol>
20-
</ol>
21-
</div>
22-
</div>
23-
</div>
14+
<p>Given an array of integers <code>arr</code> of even length, return <code>true</code> if and only if it is possible to reorder it such that <code>arr[2 * i + 1] = 2 * arr[2 * i]</code> for every <code>0 &lt;= i &lt; len(arr) / 2</code>.</p>
2415

2516
<p>&nbsp;</p>
2617
<p><strong>Example 1:</strong></p>
2718

2819
<pre>
29-
<strong>Input:</strong> A = [3,1,3,6]
20+
<strong>Input:</strong> arr = [3,1,3,6]
3021
<strong>Output:</strong> false
3122
</pre>
3223

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

3526
<pre>
36-
<strong>Input:</strong> A = [2,1,2,6]
27+
<strong>Input:</strong> arr = [2,1,2,6]
3728
<strong>Output:</strong> false
3829
</pre>
3930

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

4233
<pre>
43-
<strong>Input:</strong> A = [4,-2,2,-4]
34+
<strong>Input:</strong> arr = [4,-2,2,-4]
4435
<strong>Output:</strong> true
4536
<strong>Explanation:</strong> We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].
4637
</pre>
4738

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

5041
<pre>
51-
<strong>Input:</strong> A = [1,2,4,16,8,4]
42+
<strong>Input:</strong> arr = [1,2,4,16,8,4]
5243
<strong>Output:</strong> false
5344
</pre>
5445

5546
<p>&nbsp;</p>
5647
<p><strong>Constraints:</strong></p>
5748

5849
<ul>
59-
<li><code>0 &lt;= A.length &lt;= 3 *&nbsp;10<sup>4</sup></code></li>
60-
<li><code>A.length</code> is even.</li>
61-
<li><code>-10<sup>5</sup> &lt;= A[i] &lt;= 10<sup>5</sup></code></li>
50+
<li><code>0 &lt;= arr.length &lt;= 3 * 10<sup>4</sup></code></li>
51+
<li><code>arr.length</code> is even.</li>
52+
<li><code>-10<sup>5</sup> &lt;= arr[i] &lt;= 10<sup>5</sup></code></li>
6253
</ul>
6354

6455
### Related Topics

problems/asteroid-collision/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<pre>
2424
<strong>Input:</strong> asteroids = [5,10,-5]
2525
<strong>Output:</strong> [5,10]
26-
<b>Explanation:</b> The 10 and -5 collide resulting in 10. The 5 and 10 never collide.
26+
<b>Explanation:</b> The 10 and -5 collide resulting in 10. The 5 and 10 never collide.
2727
</pre>
2828

2929
<p><strong>Example 2:</strong></p>
@@ -54,7 +54,7 @@
5454
<p><strong>Constraints:</strong></p>
5555

5656
<ul>
57-
<li><code>1 &lt;= asteroids &lt;= 10<sup>4</sup></code></li>
57+
<li><code>2 &lt;= asteroids &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/average-time-of-process-per-machine/README.md

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

1010
[Next >](../check-if-two-string-arrays-are-equivalent "Check If Two String Arrays are Equivalent")
1111

12-
## [1661. Average Time of Process per Machine (Easy)](https://leetcode.com/problems/average-time-of-process-per-machine "")
12+
## [1661. Average Time of Process per Machine (Easy)](https://leetcode.com/problems/average-time-of-process-per-machine "每台机器的进程平均运行时间")
1313

1414

problems/best-time-to-buy-and-sell-stock/README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,38 @@
1111

1212
## [121. Best Time to Buy and Sell Stock (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock "买卖股票的最佳时机")
1313

14-
<p>Say you have an array for which the <em>i</em><sup>th</sup> element is the price of a given stock on day <em>i</em>.</p>
14+
<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p>
1515

16-
<p>If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.</p>
16+
<p>You want to maximize your profit by choosing a <strong>single day</strong> to buy one stock and choosing a <strong>different day in the future</strong> to sell that stock.</p>
1717

18-
<p>Note that you cannot sell a stock before you buy one.</p>
18+
<p>Return <em>the maximum profit you can achieve from this transaction</em>. If you cannot achieve any profit, return <code>0</code>.</p>
1919

20+
<p>&nbsp;</p>
2021
<p><strong>Example 1:</strong></p>
2122

2223
<pre>
23-
<strong>Input:</strong> [7,1,5,3,6,4]
24+
<strong>Input:</strong> prices = [7,1,5,3,6,4]
2425
<strong>Output:</strong> 5
2526
<strong>Explanation:</strong> Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
26-
&nbsp; Not 7-1 = 6, as selling price needs to be larger than buying price.
27+
Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
2728
</pre>
2829

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

3132
<pre>
32-
<strong>Input:</strong> [7,6,4,3,1]
33+
<strong>Input:</strong> prices = [7,6,4,3,1]
3334
<strong>Output:</strong> 0
34-
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.
35+
<strong>Explanation:</strong> In this case, no transactions are done and the max profit = 0.
3536
</pre>
3637

38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>1 &lt;= prices.length &lt;= 10<sup>5</sup></code></li>
43+
<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>
44+
</ul>
45+
3746
### Related Topics
3847
[[Array](../../tag/array/README.md)]
3948
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]

problems/binary-tree-maximum-path-sum/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,27 @@
1111

1212
## [124. Binary Tree Maximum Path Sum (Hard)](https://leetcode.com/problems/binary-tree-maximum-path-sum "二叉树中的最大路径和")
1313

14-
<p>Given the <code>root</code> of a binary tree, return <em>the maximum path sum</em>.</p>
14+
<p>A <strong>path</strong> in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence <strong>at most once</strong>. Note that the path does not need to pass through the root.</p>
1515

16-
<p>For this problem, a path is defined as any node sequence from some starting node to any node in the tree along the parent-child connections. The path must contain <strong>at least one node</strong> and does not need to go through the root.</p>
16+
<p>The <strong>path sum</strong> of a path is the sum of the node&#39;s values in the path.</p>
17+
18+
<p>Given the <code>root</code> of a binary tree, return <em>the maximum <strong>path sum</strong> of any path</em>.</p>
1719

1820
<p>&nbsp;</p>
1921
<p><strong>Example 1:</strong></p>
2022
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/13/exx1.jpg" style="width: 322px; height: 182px;" />
2123
<pre>
2224
<strong>Input:</strong> root = [1,2,3]
2325
<strong>Output:</strong> 6
26+
<strong>Explanation:</strong> The optimal path is 2 -&gt; 1 -&gt; 3 with a path sum of 2 + 1 + 3 = 6.
2427
</pre>
2528

2629
<p><strong>Example 2:</strong></p>
2730
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/13/exx2.jpg" />
2831
<pre>
2932
<strong>Input:</strong> root = [-10,9,20,null,null,15,7]
3033
<strong>Output:</strong> 42
34+
<strong>Explanation:</strong> The optimal path is 15 -&gt; 20 -&gt; 7 with a path sum of 15 + 20 + 7 = 42.
3135
</pre>
3236

3337
<p>&nbsp;</p>

problems/binary-tree-preorder-traversal/README.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@
5858
</ul>
5959

6060
<p>&nbsp;</p>
61-
62-
<p><strong>Follow up:</strong></p>
63-
64-
<p>Recursive solution is trivial, could you do it iteratively?</p>
65-
66-
<p>&nbsp;</p>
61+
<p><strong>Follow up:</strong> Recursive solution is trivial, could you do it iteratively?</p>
6762

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

problems/boats-to-save-people/README.md

+16-23
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,42 @@
1111

1212
## [881. Boats to Save People (Medium)](https://leetcode.com/problems/boats-to-save-people "救生艇")
1313

14-
<p>The <code>i</code>-th person has weight <code>people[i]</code>, and each boat can carry a maximum weight of <code>limit</code>.</p>
14+
<p>You are given an array <code>people</code> where <code>people[i]</code> is the weight of the <code>i<sup>th</sup></code> person, and an <strong>infinite number of boats</strong> where each boat can carry a maximum weight of <code>limit</code>. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most <code>limit</code>.</p>
1515

16-
<p>Each boat carries at most 2 people at the same time, provided the sum of the&nbsp;weight of those people is at most <code>limit</code>.</p>
17-
18-
<p>Return the minimum number of boats to carry every given person.&nbsp; (It is guaranteed each person can be carried by a boat.)</p>
16+
<p>Return <em>the minimum number of boats to carry every given person</em>.</p>
1917

2018
<p>&nbsp;</p>
21-
22-
<div>
2319
<p><strong>Example 1:</strong></p>
2420

2521
<pre>
26-
<strong>Input: </strong>people = <span id="example-input-1-1">[1,2]</span>, limit = <span id="example-input-1-2">3</span>
27-
<strong>Output: </strong><span id="example-output-1">1</span>
28-
<strong>Explanation: </strong>1 boat (1, 2)
22+
<strong>Input:</strong> people = [1,2], limit = 3
23+
<strong>Output:</strong> 1
24+
<strong>Explanation:</strong> 1 boat (1, 2)
2925
</pre>
3026

31-
<div>
3227
<p><strong>Example 2:</strong></p>
3328

3429
<pre>
35-
<strong>Input: </strong>people = <span id="example-input-2-1">[3,2,2,1]</span>, limit = <span id="example-input-2-2">3</span>
36-
<strong>Output: </strong><span id="example-output-2">3</span>
37-
<strong>Explanation</strong>: 3 boats (1, 2), (2) and (3)
30+
<strong>Input:</strong> people = [3,2,2,1], limit = 3
31+
<strong>Output:</strong> 3
32+
<strong>Explanation:</strong> 3 boats (1, 2), (2) and (3)
3833
</pre>
3934

40-
<div>
4135
<p><strong>Example 3:</strong></p>
4236

4337
<pre>
44-
<strong>Input: </strong>people = <span id="example-input-3-1">[3,5,3,4]</span>, limit = <span id="example-input-3-2">5</span>
45-
<strong>Output: </strong><span id="example-output-3">4</span>
46-
<strong>Explanation</strong>: 4 boats (3), (3), (4), (5)</pre>
38+
<strong>Input:</strong> people = [3,5,3,4], limit = 5
39+
<strong>Output:</strong> 4
40+
<strong>Explanation:</strong> 4 boats (3), (3), (4), (5)
41+
</pre>
4742

48-
<p><strong>Note</strong>:</p>
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
4945

5046
<ul>
51-
<li><code>1 &lt;=&nbsp;people.length &lt;= 50000</code></li>
52-
<li><code>1 &lt;= people[i] &lt;=&nbsp;limit &lt;= 30000</code></li>
47+
<li><code>1 &lt;= people.length &lt;= 5 * 10<sup>4</sup></code></li>
48+
<li><code>1 &lt;= people[i] &lt;= limit &lt;= 3 * 10<sup>4</sup></code></li>
5349
</ul>
54-
</div>
55-
</div>
56-
</div>
5750

5851
### Related Topics
5952
[[Greedy](../../tag/greedy/README.md)]

problems/building-boxes/README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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](../find-kth-largest-xor-coordinate-value "Find Kth Largest XOR Coordinate Value")
9+
                
10+
[Next >](../find-distance-in-a-binary-tree "Find Distance in a Binary Tree")
11+
12+
## [1739. Building Boxes (Hard)](https://leetcode.com/problems/building-boxes "放置盒子")
13+
14+
<p>You have a cubic storeroom where the width, length, and height of the room are all equal to <code>n</code> units. You are asked to place <code>n</code> boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:</p>
15+
16+
<ul>
17+
<li>You can place the boxes anywhere on the floor.</li>
18+
<li>If box <code>x</code> is placed on top of the box <code>y</code>, then each side of the four vertical sides of the box <code>y</code> <strong>must</strong> either be adjacent to another box or to a wall.</li>
19+
</ul>
20+
21+
<p>Given an integer <code>n</code>, return<em> the <strong>minimum</strong> possible number of boxes touching the floor.</em></p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
26+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/3-boxes.png" style="width: 135px; height: 143px;" /></p>
27+
28+
<pre>
29+
<strong>Input:</strong> n = 3
30+
<strong>Output:</strong> 3
31+
<strong>Explanation:</strong> The figure above is for the placement of the three boxes.
32+
These boxes are placed in the corner of the room, where the corner is on the left side.
33+
</pre>
34+
35+
<p><strong>Example 2:</strong></p>
36+
37+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/4-boxes.png" style="width: 135px; height: 179px;" /></p>
38+
39+
<pre>
40+
<strong>Input:</strong> n = 4
41+
<strong>Output:</strong> 3
42+
<strong>Explanation:</strong> The figure above is for the placement of the four boxes.
43+
These boxes are placed in the corner of the room, where the corner is on the left side.
44+
</pre>
45+
46+
<p><strong>Example 3:</strong></p>
47+
48+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/10-boxes.png" style="width: 271px; height: 257px;" /></p>
49+
50+
<pre>
51+
<strong>Input:</strong> n = 10
52+
<strong>Output:</strong> 6
53+
<strong>Explanation:</strong> The figure above is for the placement of the ten boxes.
54+
These boxes are placed in the corner of the room, where the corner is on the back side.</pre>
55+
56+
<p>&nbsp;</p>
57+
<p><strong>Constraints:</strong></p>
58+
59+
<ul>
60+
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
61+
</ul>
62+
63+
### Related Topics
64+
[[Math](../../tag/math/README.md)]
65+
[[Binary Search](../../tag/binary-search/README.md)]
66+
67+
### Hints
68+
<details>
69+
<summary>Hint 1</summary>
70+
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in?
71+
</details>
72+
73+
<details>
74+
<summary>Hint 2</summary>
75+
The first box should always start in the corner
76+
</details>

problems/burst-balloons/README.md

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

1414
<p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
1515

16-
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[left] * nums[i] * nums[right]</code> coins. Here <code>left</code> and <code>right</code> are adjacent indices of <code>i</code>. After the burst, the <code>left</code> and <code>right</code> then becomes adjacent.</p>
16+
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums[i] * nums[i + 1]</code> coins. If <code>i - 1</code> or <code>i + 1</code> goes out of bounds of the array, then treat it as if there is a balloon with a <code>1</code> painted on it.</p>
1717

1818
<p>Return <em>the maximum coins you can collect by bursting the balloons wisely</em>.</p>
1919

@@ -23,8 +23,8 @@
2323
<pre>
2424
<strong>Input:</strong> nums = [3,1,5,8]
2525
<strong>Output:</strong> 167
26-
<code><strong>Explanation:
27-
</strong></code>nums = [3,1,5,8] --&gt; [3,5,8] --&gt; [3,8] --&gt; [8] --&gt; []
26+
<strong>Explanation:</strong>
27+
nums = [3,1,5,8] --&gt; [3,5,8] --&gt; [3,8] --&gt; [8] --&gt; []
2828
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167</pre>
2929

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

0 commit comments

Comments
 (0)