Skip to content
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1771">1771</span> | [Maximize Palindrome Length From Subsequences](https://leetcode.com/problems/maximize-palindrome-length-from-subsequences "由子序列构造的最长回文串的长度") | [Go](problems/maximize-palindrome-length-from-subsequences) | Hard |
| <span id="1770">1770</span> | [Maximum Score from Performing Multiplication Operations](https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations "执行乘法运算的最大分数") | [Go](problems/maximum-score-from-performing-multiplication-operations) | Medium |
| <span id="1769">1769</span> | [Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box "移动所有球到每个盒子所需的最小操作数") | [Go](problems/minimum-number-of-operations-to-move-all-balls-to-each-box) | Medium |
| <span id="1768">1768</span> | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately "交替合并字符串") | [Go](problems/merge-strings-alternately) | Easy |
| <span id="1767">1767</span> | [Find the Subtasks That Did Not Execute](https://leetcode.com/problems/find-the-subtasks-that-did-not-execute) 🔒 | [MySQL](problems/find-the-subtasks-that-did-not-execute) | Hard |
| <span id="1766">1766</span> | [Tree of Coprimes](https://leetcode.com/problems/tree-of-coprimes "互质树") | [Go](problems/tree-of-coprimes) | Hard |
| <span id="1765">1765</span> | [Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak "地图中的最高点") | [Go](problems/map-of-highest-peak) | Medium |
| <span id="1764">1764</span> | [Form Array by Concatenating Subarrays of Another Array](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array "通过连接另一个数组的子数组得到一个数组") | [Go](problems/form-array-by-concatenating-subarrays-of-another-array) | Medium |
| <span id="1763">1763</span> | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring "最长的美好子字符串") | [Go](problems/longest-nice-substring) | Easy |
| <span id="1762">1762</span> | [Buildings With an Ocean View](https://leetcode.com/problems/buildings-with-an-ocean-view) 🔒 | [Go](problems/buildings-with-an-ocean-view) | Medium |
| <span id="1761">1761</span> | [Minimum Degree of a Connected Trio in a Graph](https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph "一个图中连通三元组的最小度数") | [Go](problems/minimum-degree-of-a-connected-trio-in-a-graph) | Hard |
| <span id="1760">1760</span> | [Minimum Limit of Balls in a Bag](https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag "袋子里最少数目的球") | [Go](problems/minimum-limit-of-balls-in-a-bag) | Medium |
| <span id="1759">1759</span> | [Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings "统计同构子字符串的数目") | [Go](problems/count-number-of-homogenous-substrings) | Medium |
| <span id="1758">1758</span> | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string "生成交替二进制字符串的最少操作数") | [Go](problems/minimum-changes-to-make-alternating-binary-string) | Easy |
| <span id="1757">1757</span> | [Recyclable and Low Fat Products](https://leetcode.com/problems/recyclable-and-low-fat-products) 🔒 | [MySQL](problems/recyclable-and-low-fat-products) | Easy |
| <span id="1756">1756</span> | [Design Most Recently Used Queue](https://leetcode.com/problems/design-most-recently-used-queue) 🔒 | [Go](problems/design-most-recently-used-queue) | Medium |
| <span id="1755">1755</span> | [Closest Subsequence Sum](https://leetcode.com/problems/closest-subsequence-sum "最接近目标值的子序列和") | [Go](problems/closest-subsequence-sum) | Hard |
| <span id="1754">1754</span> | [Largest Merge Of Two Strings](https://leetcode.com/problems/largest-merge-of-two-strings "构造字典序最大的合并字符串") | [Go](problems/largest-merge-of-two-strings) | Medium |
| <span id="1753">1753</span> | [Maximum Score From Removing Stones](https://leetcode.com/problems/maximum-score-from-removing-stones "移除石子的最大得分") | [Go](problems/maximum-score-from-removing-stones) | Medium |
| <span id="1752">1752</span> | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated "检查数组是否经排序和轮转得到") | [Go](problems/check-if-array-is-sorted-and-rotated) | Easy |
| <span id="1751">1751</span> | [Maximum Number of Events That Can Be Attended II](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii "最多可以参加的会议数目 II") | [Go](problems/maximum-number-of-events-that-can-be-attended-ii) | Hard |
| <span id="1750">1750</span> | [Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends "删除字符串两端相同字符后的最短长度") | [Go](problems/minimum-length-of-string-after-deleting-similar-ends) | Medium |
| <span id="1749">1749</span> | [Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray "任意子数组和的绝对值的最大值") | [Go](problems/maximum-absolute-sum-of-any-subarray) | Medium |
| <span id="1748">1748</span> | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements "唯一元素的和") | [Go](problems/sum-of-unique-elements) | Easy |
| <span id="1747">1747</span> | [Leetflex Banned Accounts](https://leetcode.com/problems/leetflex-banned-accounts) 🔒 | [MySQL](problems/leetflex-banned-accounts) | Medium |
| <span id="1746">1746</span> | [Maximum Subarray Sum After One Operation](https://leetcode.com/problems/maximum-subarray-sum-after-one-operation) 🔒 | [Go](problems/maximum-subarray-sum-after-one-operation) | Medium |
| <span id="1745">1745</span> | [Palindrome Partitioning IV](https://leetcode.com/problems/palindrome-partitioning-iv "回文串分割 IV") | [Go](problems/palindrome-partitioning-iv) | Hard |
Expand Down
2 changes: 1 addition & 1 deletion problems/average-of-levels-in-binary-tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2

### Similar Questions
1. [Binary Tree Level Order Traversal](../binary-tree-level-order-traversal) (Medium)
1. [Binary Tree Level Order Traversal II](../binary-tree-level-order-traversal-ii) (Easy)
1. [Binary Tree Level Order Traversal II](../binary-tree-level-order-traversal-ii) (Medium)
4 changes: 3 additions & 1 deletion problems/base-7/base_7.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package problem504

import "fmt"

func convertToBase7(num int) string {
ans := ""
if num < 0 {
Expand All @@ -8,5 +10,5 @@ func convertToBase7(num int) string {
if num >= 7 {
ans += convertToBase7(num / 7)
}
return ans + string('0'+num%7)
return ans + fmt.Sprintf("%c", '0'+num%7)
}
31 changes: 18 additions & 13 deletions problems/best-sightseeing-pair/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,35 @@

## [1014. Best Sightseeing Pair (Medium)](https://leetcode.com/problems/best-sightseeing-pair "最佳观光组合")

<p>Given an array <code>A</code> of positive integers, <code>A[i]</code> represents the value of the <code>i</code>-th sightseeing spot, and two&nbsp;sightseeing spots <code>i</code> and <code>j</code>&nbsp;have distance <code>j - i</code>&nbsp;between them.</p>
<p>You are given an integer array <code>values</code> where values[i] represents the value of the <code>i<sup>th</sup></code> sightseeing spot. Two sightseeing spots <code>i</code> and <code>j</code> have a <strong>distance</strong> <code>j - i</code> between them.</p>

<p>The <em>score</em>&nbsp;of a pair (<code>i &lt; j</code>) of sightseeing spots is (<code>A[i] + A[j] + i&nbsp;- j)</code> : the sum of the values of the sightseeing spots, <strong>minus</strong> the distance between them.</p>
<p>The score of a pair (<code>i &lt; j</code>) of sightseeing spots is <code>values[i] + values[j] + i - j</code>: the sum of the values of the sightseeing spots, minus the distance between them.</p>

<p>Return the maximum score of a pair of sightseeing spots.</p>
<p>Return <em>the maximum score of a pair of sightseeing spots</em>.</p>

<p>&nbsp;</p>

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

<pre>
<strong>Input: </strong><span id="example-input-1-1">[8,1,5,2,6]</span>
<strong>Output: </strong><span id="example-output-1">11
<strong>Explanation:</strong> i = 0, j = 2, </span><code>A[i] + A[j] + i - j = 8 + 5 + 0 - 2 = 11</code>
<strong>Input:</strong> values = [8,1,5,2,6]
<strong>Output:</strong> 11
<strong>Explanation:</strong> i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11
</pre>

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

<pre>
<strong>Input:</strong> values = [1,2]
<strong>Output:</strong> 2
</pre>

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

<ol>
<li><code>2 &lt;= A.length &lt;= 50000</code></li>
<li><code>1 &lt;= A[i] &lt;= 1000</code></li>
</ol>
<ul>
<li><code>2 &lt;= values.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= values[i] &lt;= 1000</code></li>
</ul>

### Related Topics
[[Array](../../tag/array/README.md)]
Expand Down
25 changes: 13 additions & 12 deletions problems/best-time-to-buy-and-sell-stock-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,45 @@

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

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

<p>Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p>
<p>Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p>

<p><strong>Note:</strong> You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p>
<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p>

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

<pre>
<strong>Input:</strong> [7,1,5,3,6,4]
<strong>Input:</strong> prices = [7,1,5,3,6,4]
<strong>Output:</strong> 7
<strong>Explanation:</strong> Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
&nbsp; Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
</pre>

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

<pre>
<strong>Input:</strong> [1,2,3,4,5]
<strong>Input:</strong> prices = [1,2,3,4,5]
<strong>Output:</strong> 4
<strong>Explanation:</strong> Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
&nbsp; Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
&nbsp; engaging multiple transactions at the same time. You must sell before buying again.
Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.
</pre>

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

<pre>
<strong>Input:</strong> [7,6,4,3,1]
<strong>Input:</strong> prices = [7,6,4,3,1]
<strong>Output:</strong> 0
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>
<strong>Explanation:</strong> In this case, no transaction is done, i.e., max profit = 0.
</pre>

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

<ul>
<li><code>1 &lt;= prices.length &lt;= 3 * 10 ^ 4</code></li>
<li><code>0 &lt;= prices[i]&nbsp;&lt;= 10 ^ 4</code></li>
<li><code>1 &lt;= prices.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>
</ul>

### Related Topics
Expand Down
46 changes: 27 additions & 19 deletions problems/binary-tree-level-order-traversal-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,39 @@

[Next >](../convert-sorted-array-to-binary-search-tree "Convert Sorted Array to Binary Search Tree")

## [107. Binary Tree Level Order Traversal II (Easy)](https://leetcode.com/problems/binary-tree-level-order-traversal-ii "二叉树的层序遍历 II")
## [107. Binary Tree Level Order Traversal II (Medium)](https://leetcode.com/problems/binary-tree-level-order-traversal-ii "二叉树的层序遍历 II")

<p>Given a binary tree, return the <i>bottom-up level order</i> traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).</p>
<p>Given the <code>root</code> of a binary tree, return <em>the bottom-up level order traversal of its nodes&#39; values</em>. (i.e., from left to right, level by level from leaf to root).</p>

<p>
For example:<br />
Given binary tree <code>[3,9,20,null,null,15,7]</code>,<br />
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
<pre>
3
/ \
9 20
/ \
15 7
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
<strong>Output:</strong> [[15,7],[9,20],[3]]
</pre>
</p>
<p>
return its bottom-up level order traversal as:<br />

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

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [[1]]
</pre>

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

<pre>
[
[15,7],
[9,20],
[3]
]
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>
</p>

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

<ul>
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
</ul>

### Related Topics
[[Tree](../../tag/tree/README.md)]
Expand Down
46 changes: 27 additions & 19 deletions problems/binary-tree-level-order-traversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,45 @@

## [102. Binary Tree Level Order Traversal (Medium)](https://leetcode.com/problems/binary-tree-level-order-traversal "二叉树的层序遍历")

<p>Given a binary tree, return the <i>level order</i> traversal of its nodes' values. (ie, from left to right, level by level).</p>
<p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes&#39; values</em>. (i.e., from left to right, level by level).</p>

<p>
For example:<br />
Given binary tree <code>[3,9,20,null,null,15,7]</code>,<br />
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
<pre>
3
/ \
9 20
/ \
15 7
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
<strong>Output:</strong> [[3],[9,20],[15,7]]
</pre>
</p>
<p>
return its level order traversal as:<br />

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

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [[1]]
</pre>

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

<pre>
[
[3],
[9,20],
[15,7]
]
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>
</p>

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

<ul>
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
</ul>

### Related Topics
[[Tree](../../tag/tree/README.md)]
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]

### Similar Questions
1. [Binary Tree Zigzag Level Order Traversal](../binary-tree-zigzag-level-order-traversal) (Medium)
1. [Binary Tree Level Order Traversal II](../binary-tree-level-order-traversal-ii) (Easy)
1. [Binary Tree Level Order Traversal II](../binary-tree-level-order-traversal-ii) (Medium)
1. [Minimum Depth of Binary Tree](../minimum-depth-of-binary-tree) (Easy)
1. [Binary Tree Vertical Order Traversal](../binary-tree-vertical-order-traversal) (Medium)
1. [Average of Levels in Binary Tree](../average-of-levels-in-binary-tree) (Easy)
Expand Down
40 changes: 29 additions & 11 deletions problems/binary-tree-right-side-view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,44 @@

## [199. Binary Tree Right Side View (Medium)](https://leetcode.com/problems/binary-tree-right-side-view "二叉树的右视图")

<p>Given a binary tree, imagine yourself standing on the <em>right</em> side of it, return the values of the nodes you can see ordered from top to bottom.</p>
<p>Given the <code>root</code> of a binary tree, imagine yourself standing on the <strong>right side</strong> of it, return <em>the values of the nodes you can see ordered from top to bottom</em>.</p>

<p><strong>Example:</strong></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/14/tree.jpg" style="width: 401px; height: 301px;" />
<pre>
<strong>Input:</strong> root = [1,2,3,null,5,null,4]
<strong>Output:</strong> [1,3,4]
</pre>

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

<pre>
<strong>Input:</strong>&nbsp;[1,2,3,null,5,null,4]
<strong>Output:</strong>&nbsp;[1, 3, 4]
<strong>Explanation:
</strong>
1 &lt;---
/ \
2 3 &lt;---
\ \
5 4 &lt;---
<strong>Input:</strong> root = [1,null,3]
<strong>Output:</strong> [1,3]
</pre>

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

<pre>
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>

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

<ul>
<li>The number of nodes in the tree is in the range <code>[0, 100]</code>.</li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

### Related Topics
[[Tree](../../tag/tree/README.md)]
[[Depth-first Search](../../tag/depth-first-search/README.md)]
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]
[[Recursion](../../tag/recursion/README.md)]
[[Queue](../../tag/queue/README.md)]

### Similar Questions
1. [Populating Next Right Pointers in Each Node](../populating-next-right-pointers-in-each-node) (Medium)
Expand Down
44 changes: 26 additions & 18 deletions problems/binary-tree-zigzag-level-order-traversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,37 @@

## [103. Binary Tree Zigzag Level Order Traversal (Medium)](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal "二叉树的锯齿形层序遍历")

<p>Given a binary tree, return the <i>zigzag level order</i> traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).</p>
<p>Given the <code>root</code> of a binary tree, return <em>the zigzag level order traversal of its nodes&#39; values</em>. (i.e., from left to right, then right to left for the next level and alternate between).</p>

<p>
For example:<br />
Given binary tree <code>[3,9,20,null,null,15,7]</code>,<br />
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
<pre>
3
/ \
9 20
/ \
15 7
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
<strong>Output:</strong> [[3],[20,9],[15,7]]
</pre>
</p>
<p>
return its zigzag level order traversal as:<br />

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

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [[1]]
</pre>

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

<pre>
[
[3],
[20,9],
[15,7]
]
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>
</p>

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

<ul>
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

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