Add solution 0279、0518

This commit is contained in:
halfrost
2021-06-16 17:38:56 +08:00
parent 48cb642554
commit 5cf1b806b1
23 changed files with 507 additions and 44 deletions

View File

@ -126,16 +126,16 @@
| | Easy | Medium | Hard | Total |
|:--------:|:--------:|:--------:|:--------:|:--------:|
|Optimizing|33|35|23|91|
|Optimizing|33|33|23|89|
|Accepted|**285**|**386**|**114**|**785**|
|Total|499|1003|399|1901|
|Perfection Rate|88.4%|90.9%|79.8%|88.4%|
|Perfection Rate|88.4%|91.5%|79.8%|88.7%|
|Completion Rate|57.1%|38.5%|28.6%|41.3%|
|------------|----------------------------|----------------------------|----------------------------|----------------------------|
## 二. 目录
以下已经收录了 694 道题的题解,还有 11 道题在尝试优化到 beats 100%
以下已经收录了 696 道题的题解,还有 11 道题在尝试优化到 beats 100%
| No. | Title | Solution | Acceptance | Difficulty | Frequency |
|:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
@ -356,7 +356,7 @@
|0215|Kth Largest Element in an Array|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0215.Kth-Largest-Element-in-an-Array)|59.7%|Medium||
|0216|Combination Sum III|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0216.Combination-Sum-III)|61.3%|Medium||
|0217|Contains Duplicate|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0217.Contains-Duplicate)|57.5%|Easy||
|0218|The Skyline Problem|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0218.The-Skyline-Problem)|37.0%|Hard||
|0218|The Skyline Problem|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0218.The-Skyline-Problem)|37.1%|Hard||
|0219|Contains Duplicate II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0219.Contains-Duplicate-II)|39.2%|Easy||
|0220|Contains Duplicate III|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0220.Contains-Duplicate-III)|21.4%|Medium||
|0221|Maximal Square||40.2%|Medium||
@ -417,7 +417,7 @@
|0276|Paint Fence||39.5%|Medium||
|0277|Find the Celebrity||44.6%|Medium||
|0278|First Bad Version|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0278.First-Bad-Version)|38.3%|Easy||
|0279|Perfect Squares||49.7%|Medium||
|0279|Perfect Squares|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0279.Perfect-Squares)|49.7%|Medium||
|0280|Wiggle Sort||65.0%|Medium||
|0281|Zigzag Iterator||59.9%|Medium||
|0282|Expression Add Operators||37.2%|Hard||
@ -536,7 +536,7 @@
|0395|Longest Substring with At Least K Repeating Characters|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0395.Longest-Substring-with-At-Least-K-Repeating-Characters)|43.8%|Medium||
|0396|Rotate Function||36.9%|Medium||
|0397|Integer Replacement|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0397.Integer-Replacement)|33.7%|Medium||
|0398|Random Pick Index||59.2%|Medium||
|0398|Random Pick Index||59.3%|Medium||
|0399|Evaluate Division|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0399.Evaluate-Division)|55.1%|Medium||
|0400|Nth Digit||32.6%|Medium||
|0401|Binary Watch|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0401.Binary-Watch)|48.9%|Easy||
@ -656,7 +656,7 @@
|0515|Find Largest Value in Each Tree Row|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0515.Find-Largest-Value-in-Each-Tree-Row)|62.8%|Medium||
|0516|Longest Palindromic Subsequence||56.5%|Medium||
|0517|Super Washing Machines||38.8%|Hard||
|0518|Coin Change 2||52.9%|Medium||
|0518|Coin Change 2|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0518.Coin-Change-2)|52.9%|Medium||
|0519|Random Flip Matrix||38.0%|Medium||
|0520|Detect Capital||54.1%|Easy||
|0521|Longest Uncommon Subsequence I||59.2%|Easy||
@ -664,7 +664,7 @@
|0523|Continuous Subarray Sum|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0523.Continuous-Subarray-Sum)|25.2%|Medium||
|0524|Longest Word in Dictionary through Deleting|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0524.Longest-Word-in-Dictionary-through-Deleting)|50.3%|Medium||
|0525|Contiguous Array|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0525.Contiguous-Array)|43.9%|Medium||
|0526|Beautiful Arrangement|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0526.Beautiful-Arrangement)|62.3%|Medium||
|0526|Beautiful Arrangement|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0526.Beautiful-Arrangement)|62.4%|Medium||
|0527|Word Abbreviation||56.8%|Hard||
|0528|Random Pick with Weight|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0528.Random-Pick-with-Weight)|45.0%|Medium||
|0529|Minesweeper|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0529.Minesweeper)|62.1%|Medium||
@ -932,7 +932,7 @@
|0791|Custom Sort String||66.0%|Medium||
|0792|Number of Matching Subsequences||48.7%|Medium||
|0793|Preimage Size of Factorial Zeroes Function|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0793.Preimage-Size-of-Factorial-Zeroes-Function)|40.7%|Hard||
|0794|Valid Tic-Tac-Toe State||34.3%|Medium||
|0794|Valid Tic-Tac-Toe State||34.4%|Medium||
|0795|Number of Subarrays with Bounded Maximum||48.4%|Medium||
|0796|Rotate String||48.9%|Easy||
|0797|All Paths From Source to Target||78.8%|Medium||
@ -1158,7 +1158,7 @@
|1017|Convert to Base -2|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1017.Convert-to-Base--2)|59.4%|Medium||
|1018|Binary Prefix Divisible By 5|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1018.Binary-Prefix-Divisible-By-5)|47.6%|Easy||
|1019|Next Greater Node In Linked List|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1019.Next-Greater-Node-In-Linked-List)|58.4%|Medium||
|1020|Number of Enclaves|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1020.Number-of-Enclaves)|59.7%|Medium||
|1020|Number of Enclaves|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1020.Number-of-Enclaves)|59.6%|Medium||
|1021|Remove Outermost Parentheses|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1021.Remove-Outermost-Parentheses)|79.3%|Easy||
|1022|Sum of Root To Leaf Binary Numbers||71.8%|Easy||
|1023|Camelcase Matching||57.8%|Medium||
@ -1178,7 +1178,7 @@
|1037|Valid Boomerang|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1037.Valid-Boomerang)|37.4%|Easy||
|1038|Binary Search Tree to Greater Sum Tree|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1038.Binary-Search-Tree-to-Greater-Sum-Tree)|83.1%|Medium||
|1039|Minimum Score Triangulation of Polygon||50.8%|Medium||
|1040|Moving Stones Until Consecutive II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1040.Moving-Stones-Until-Consecutive-II)|54.8%|Medium||
|1040|Moving Stones Until Consecutive II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1040.Moving-Stones-Until-Consecutive-II)|54.7%|Medium||
|1041|Robot Bounded In Circle||54.9%|Medium||
|1042|Flower Planting With No Adjacent||49.0%|Medium||
|1043|Partition Array for Maximum Sum||68.1%|Medium||
@ -1314,7 +1314,7 @@
|1173|Immediate Food Delivery I||83.0%|Easy||
|1174|Immediate Food Delivery II||62.6%|Medium||
|1175|Prime Arrangements|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1175.Prime-Arrangements)|51.8%|Easy||
|1176|Diet Plan Performance||53.7%|Easy||
|1176|Diet Plan Performance||53.8%|Easy||
|1177|Can Make Palindrome from Substring||36.2%|Medium||
|1178|Number of Valid Words for Each Puzzle|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1178.Number-of-Valid-Words-for-Each-Puzzle)|40.3%|Hard||
|1179|Reformat Department Table||82.1%|Easy||
@ -1416,7 +1416,7 @@
|1275|Find Winner on a Tic Tac Toe Game|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1275.Find-Winner-on-a-Tic-Tac-Toe-Game)|52.9%|Easy||
|1276|Number of Burgers with No Waste of Ingredients||50.4%|Medium||
|1277|Count Square Submatrices with All Ones||73.0%|Medium||
|1278|Palindrome Partitioning III||61.4%|Hard||
|1278|Palindrome Partitioning III||61.3%|Hard||
|1279|Traffic Light Controlled Intersection||76.3%|Easy||
|1280|Students and Examinations||75.6%|Easy||
|1281|Subtract the Product and Sum of Digits of an Integer|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer)|85.6%|Easy||
@ -1609,7 +1609,7 @@
|1468|Calculate Salaries||82.4%|Medium||
|1469|Find All The Lonely Nodes||80.7%|Easy||
|1470|Shuffle the Array|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1470.Shuffle-the-Array)|88.1%|Easy||
|1471|The k Strongest Values in an Array||58.8%|Medium||
|1471|The k Strongest Values in an Array||58.9%|Medium||
|1472|Design Browser History||72.6%|Medium||
|1473|Paint House III||49.0%|Hard||
|1474|Delete N Nodes After M Nodes of a Linked List||73.5%|Easy||
@ -1633,7 +1633,7 @@
|1492|The kth Factor of n||63.0%|Medium||
|1493|Longest Subarray of 1's After Deleting One Element||57.7%|Medium||
|1494|Parallel Courses II||30.8%|Hard||
|1495|Friendly Movies Streamed Last Month||51.0%|Easy||
|1495|Friendly Movies Streamed Last Month||51.1%|Easy||
|1496|Path Crossing||55.1%|Easy||
|1497|Check If Array Pairs Are Divisible by k||40.4%|Medium||
|1498|Number of Subsequences That Satisfy the Given Sum Condition||39.2%|Medium||
@ -1683,7 +1683,7 @@
|1542|Find Longest Awesome Substring||37.1%|Hard||
|1543|Fix Product Name Format||65.7%|Easy||
|1544|Make The String Great||55.7%|Easy||
|1545|Find Kth Bit in Nth Binary String||57.9%|Medium||
|1545|Find Kth Bit in Nth Binary String||58.0%|Medium||
|1546|Maximum Number of Non-Overlapping Subarrays With Sum Equals Target||44.6%|Medium||
|1547|Minimum Cost to Cut a Stick||53.4%|Hard||
|1548|The Most Similar Path in a Graph||55.6%|Hard||
@ -1695,7 +1695,7 @@
|1554|Strings Differ by One Character||64.6%|Medium||
|1555|Bank Account Summary||53.1%|Medium||
|1556|Thousand Separator||57.0%|Easy||
|1557|Minimum Number of Vertices to Reach All Nodes||76.1%|Medium||
|1557|Minimum Number of Vertices to Reach All Nodes||76.2%|Medium||
|1558|Minimum Numbers of Function Calls to Make Target Array||63.4%|Medium||
|1559|Detect Cycles in 2D Grid||45.1%|Hard||
|1560|Most Visited Sector in a Circular Track||57.2%|Easy||
@ -1745,11 +1745,11 @@
|1604|Alert Using Same Key-Card Three or More Times in a One Hour Period||43.5%|Medium||
|1605|Find Valid Matrix Given Row and Column Sums||77.6%|Medium||
|1606|Find Servers That Handled Most Number of Requests||38.1%|Hard||
|1607|Sellers With No Sales||55.2%|Easy||
|1607|Sellers With No Sales||55.1%|Easy||
|1608|Special Array With X Elements Greater Than or Equal X|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X)|61.4%|Easy||
|1609|Even Odd Tree||52.3%|Medium||
|1610|Maximum Number of Visible Points||32.5%|Hard||
|1611|Minimum One Bit Operations to Make Integers Zero||59.2%|Hard||
|1611|Minimum One Bit Operations to Make Integers Zero||59.3%|Hard||
|1612|Check If Two Expression Trees are Equivalent||70.0%|Medium||
|1613|Find the Missing IDs||75.1%|Medium||
|1614|Maximum Nesting Depth of the Parentheses|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1614.Maximum-Nesting-Depth-of-the-Parentheses)|82.6%|Easy||
@ -1814,7 +1814,7 @@
|1673|Find the Most Competitive Subsequence|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1673.Find-the-Most-Competitive-Subsequence)|45.8%|Medium||
|1674|Minimum Moves to Make Array Complementary|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary)|36.2%|Medium||
|1675|Minimize Deviation in Array|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1675.Minimize-Deviation-in-Array)|48.1%|Hard||
|1676|Lowest Common Ancestor of a Binary Tree IV||79.0%|Medium||
|1676|Lowest Common Ancestor of a Binary Tree IV||79.1%|Medium||
|1677|Product's Worth Over Invoices||53.2%|Easy||
|1678|Goal Parser Interpretation|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1678.Goal-Parser-Interpretation)|84.9%|Easy||
|1679|Max Number of K-Sum Pairs|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1679.Max-Number-of-K-Sum-Pairs)|53.6%|Medium||
@ -1828,7 +1828,7 @@
|1687|Delivering Boxes from Storage to Ports||35.9%|Hard||
|1688|Count of Matches in Tournament|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1688.Count-of-Matches-in-Tournament)|81.8%|Easy||
|1689|Partitioning Into Minimum Number Of Deci-Binary Numbers|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers)|88.5%|Medium||
|1690|Stone Game VII|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1690.Stone-Game-VII)|58.5%|Medium||
|1690|Stone Game VII|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1690.Stone-Game-VII)|58.6%|Medium||
|1691|Maximum Height by Stacking Cuboids|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1691.Maximum-Height-by-Stacking-Cuboids)|51.0%|Hard||
|1692|Count Ways to Distribute Candies||60.2%|Hard||
|1693|Daily Leads and Partners||90.7%|Easy||
@ -1865,7 +1865,7 @@
|1724|Checking Existence of Edge Length Limited Paths II||56.9%|Hard||
|1725|Number Of Rectangles That Can Form The Largest Square|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square)|78.3%|Easy||
|1726|Tuple with Same Product||58.4%|Medium||
|1727|Largest Submatrix With Rearrangements||59.3%|Medium||
|1727|Largest Submatrix With Rearrangements||59.4%|Medium||
|1728|Cat and Mouse II||41.0%|Hard||
|1729|Find Followers Count||70.5%|Easy||
|1730|Shortest Path to Get Food||55.2%|Medium||
@ -1929,7 +1929,7 @@
|1788|Maximize the Beauty of the Garden||67.3%|Hard||
|1789|Primary Department for Each Employee||79.3%|Easy||
|1790|Check if One String Swap Can Make Strings Equal||44.2%|Easy||
|1791|Find Center of Star Graph||84.3%|Medium||
|1791|Find Center of Star Graph||84.4%|Medium||
|1792|Maximum Average Pass Ratio||47.3%|Medium||
|1793|Maximum Score of a Good Subarray||47.7%|Hard||
|1794|Count Pairs of Equal Substrings With Minimum Difference||68.5%|Medium||
@ -1943,7 +1943,7 @@
|1802|Maximum Value at a Given Index in a Bounded Array||28.3%|Medium||
|1803|Count Pairs With XOR in a Range||44.1%|Hard||
|1804|Implement Trie II (Prefix Tree)||58.9%|Medium||
|1805|Number of Different Integers in a String||34.7%|Easy||
|1805|Number of Different Integers in a String||34.8%|Easy||
|1806|Minimum Number of Operations to Reinitialize a Permutation||70.6%|Medium||
|1807|Evaluate the Bracket Pairs of a String||66.3%|Medium||
|1808|Maximize Number of Nice Divisors||28.3%|Hard||
@ -1962,7 +1962,7 @@
|1821|Find Customers With Positive Revenue this Year||89.0%|Easy||
|1822|Sign of the Product of an Array||63.9%|Easy||
|1823|Find the Winner of the Circular Game||72.3%|Medium||
|1824|Minimum Sideway Jumps||47.5%|Medium||
|1824|Minimum Sideway Jumps||47.6%|Medium||
|1825|Finding MK Average||28.2%|Hard||
|1826|Faulty Sensor||55.6%|Easy||
|1827|Minimum Operations to Make the Array Increasing||77.8%|Easy||
@ -1970,14 +1970,14 @@
|1829|Maximum XOR for Each Query||73.7%|Medium||
|1830|Minimum Number of Operations to Make String Sorted||46.4%|Hard||
|1831|Maximum Transaction Each Day||84.5%|Medium||
|1832|Check if the Sentence Is Pangram||82.5%|Easy||
|1832|Check if the Sentence Is Pangram||82.4%|Easy||
|1833|Maximum Ice Cream Bars||63.7%|Medium||
|1834|Single-Threaded CPU||33.7%|Medium||
|1835|Find XOR Sum of All Pairs Bitwise AND||56.6%|Hard||
|1836|Remove Duplicates From an Unsorted Linked List||73.0%|Medium||
|1837|Sum of Digits in Base K||74.9%|Easy||
|1838|Frequency of the Most Frequent Element||32.9%|Medium||
|1839|Longest Substring Of All Vowels in Order||47.2%|Medium||
|1839|Longest Substring Of All Vowels in Order||47.3%|Medium||
|1840|Maximum Building Height||34.3%|Hard||
|1841|League Statistics||61.7%|Medium||
|1842|Next Palindrome Using Same Digits||63.8%|Hard||
@ -2006,7 +2006,7 @@
|1865|Finding Pairs With a Certain Sum||45.8%|Medium||
|1866|Number of Ways to Rearrange Sticks With K Sticks Visible||54.0%|Hard||
|1867|Orders With Maximum Quantity Above Average||78.4%|Medium||
|1868|Product of Two Run-Length Encoded Arrays||61.2%|Medium||
|1868|Product of Two Run-Length Encoded Arrays||61.0%|Medium||
|1869|Longer Contiguous Segments of Ones than Zeros||59.6%|Easy||
|1870|Minimum Speed to Arrive on Time||32.3%|Medium||
|1871|Jump Game VII||24.3%|Medium||
@ -2029,17 +2029,17 @@
|1888|Minimum Number of Flips to Make the Binary String Alternating||33.6%|Medium||
|1889|Minimum Space Wasted From Packaging||29.2%|Hard||
|1890|The Latest Login in 2020||87.0%|Easy||
|1891|Cutting Ribbons||55.5%|Medium||
|1892|Page Recommendations II||40.2%|Hard||
|1891|Cutting Ribbons||55.8%|Medium||
|1892|Page Recommendations II||40.6%|Hard||
|1893|Check if All the Integers in a Range Are Covered||48.8%|Easy||
|1894|Find the Student that Will Replace the Chalk||37.8%|Medium||
|1894|Find the Student that Will Replace the Chalk||37.9%|Medium||
|1895|Largest Magic Square||48.4%|Medium||
|1896|Minimum Cost to Change the Final Value of Expression||49.4%|Hard||
|1897|Redistribute Characters to Make All Strings Equal||58.1%|Easy||
|1898|Maximum Number of Removable Characters||31.5%|Medium||
|1899|Merge Triplets to Form Target Triplet||58.1%|Medium||
|1900|The Earliest and Latest Rounds Where Players Compete||46.3%|Hard||
|1901|Find a Peak Element II||69.6%|Medium||
|1901|Find a Peak Element II||69.2%|Medium||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|
------------------------------------------------------------------

View File

@ -0,0 +1,33 @@
package leetcode
import "math"
func numSquares(n int) int {
if isPerfectSquare(n) {
return 1
}
if checkAnswer4(n) {
return 4
}
for i := 1; i*i <= n; i++ {
j := n - i*i
if isPerfectSquare(j) {
return 2
}
}
return 3
}
// 判断是否为完全平方数
func isPerfectSquare(n int) bool {
sq := int(math.Floor(math.Sqrt(float64(n))))
return sq*sq == n
}
// 判断是否能表示为 4^k*(8m+7)
func checkAnswer4(x int) bool {
for x%4 == 0 {
x /= 4
}
return x%8 == 7
}

View File

@ -0,0 +1,46 @@
package leetcode
import (
"fmt"
"testing"
)
type question279 struct {
para279
ans279
}
// para 是参数
// one 代表第一个参数
type para279 struct {
n int
}
// ans 是答案
// one 代表第一个答案
type ans279 struct {
one int
}
func Test_Problem279(t *testing.T) {
qs := []question279{
{
para279{13},
ans279{2},
},
{
para279{12},
ans279{3},
},
}
fmt.Printf("------------------------Leetcode Problem 279------------------------\n")
for _, q := range qs {
_, p := q.ans279, q.para279
fmt.Printf("【input】:%v 【output】:%v\n", p, numSquares(p.n))
}
fmt.Printf("\n\n\n")
}

View File

@ -0,0 +1,78 @@
# [279. Perfect Squares](https://leetcode.com/problems/perfect-squares/)
## 题目
Given an integer `n`, return *the least number of perfect square numbers that sum to* `n`.
A **perfect square** is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, `1`, `4`, `9`, and `16` are perfect squares while `3` and `11` are not.
**Example 1:**
```
Input: n = 12
Output: 3
Explanation: 12 = 4 + 4 + 4.
```
**Example 2:**
```
Input: n = 13
Output: 2
Explanation: 13 = 4 + 9.
```
**Constraints:**
- `1 <= n <= 104`
## 题目大意
给定正整数 n找到若干个完全平方数比如 1, 4, 9, 16, ...)使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。给你一个整数 n ,返回和为 n 的完全平方数的 最少数量 。
完全平方数 是一个整数其值等于另一个整数的平方换句话说其值等于一个整数自乘的积。例如1、4、9 和 16 都是完全平方数,而 3 和 11 不是。
## 解题思路
- 由拉格朗日的四平方定理可得,每个自然数都可以表示为四个整数平方之和。 其中四个数字是整数。四平方和定理证明了任意一个正整数都可以被表示为至多四个正整数的平方和。这给出了本题的答案的上界。
- 四平方和定理可以推出三平方和推论:当且仅当 {{< katex >}} n \neq 4^{k} \times (8*m + 7){{< /katex >}} 时n 可以被表示为至多三个正整数的平方和。所以当 {{< katex >}} n = 4^{k} * (8*m + 7){{< /katex >}} 时n 只能被表示为四个正整数的平方和。此时我们可以直接返回 4。
- 当 {{< katex >}} n \neq 4^{k} \times (8*m + 7){{< /katex >}} 时,需要判断 n 到底可以分解成几个完全平方数之和。答案肯定是 123 中的一个。题目要求我们求最小的,所以从 1 开始一个个判断是否满足。如果答案为 1代表 n 为完全平方数,这很好判断。如果答案为 2代表 {{< katex >}} n = a^{2} + b^{2} {{< /katex >}},枚举 {{< katex >}} 1 \leqslant a \leqslant \sqrt{n} {{< /katex >}},判断 {{< katex >}} n - a^{2} {{< /katex >}} 是否为完全平方数。当 1 和 2 都排除了,剩下的答案只能为 3 了。
## 代码
```go
package leetcode
import "math"
func numSquares(n int) int {
if isPerfectSquare(n) {
return 1
}
if checkAnswer4(n) {
return 4
}
for i := 1; i*i <= n; i++ {
j := n - i*i
if isPerfectSquare(j) {
return 2
}
}
return 3
}
// 判断是否为完全平方数
func isPerfectSquare(n int) bool {
sq := int(math.Floor(math.Sqrt(float64(n))))
return sq*sq == n
}
// 判断是否能表示为 4^k*(8m+7)
func checkAnswer4(x int) bool {
for x%4 == 0 {
x /= 4
}
return x%8 == 7
}
```

View File

@ -0,0 +1,12 @@
package leetcode
func change(amount int, coins []int) int {
dp := make([]int, amount+1)
dp[0] = 1
for _, coin := range coins {
for i := coin; i <= amount; i++ {
dp[i] += dp[i-coin]
}
}
return dp[amount]
}

View File

@ -0,0 +1,53 @@
package leetcode
import (
"fmt"
"testing"
)
type question518 struct {
para518
ans518
}
// para 是参数
// one 代表第一个参数
type para518 struct {
amount int
coins []int
}
// ans 是答案
// one 代表第一个答案
type ans518 struct {
one int
}
func Test_Problem518(t *testing.T) {
qs := []question518{
{
para518{5, []int{1, 2, 5}},
ans518{4},
},
{
para518{3, []int{2}},
ans518{0},
},
{
para518{10, []int{10}},
ans518{1},
},
}
fmt.Printf("------------------------Leetcode Problem 518------------------------\n")
for _, q := range qs {
_, p := q.ans518, q.para518
fmt.Printf("【input】:%v 【output】:%v\n", p, change(p.amount, p.coins))
}
fmt.Printf("\n\n\n")
}

View File

@ -0,0 +1,73 @@
# [518. Coin Change 2](https://leetcode.com/problems/coin-change-2/)
## 题目
You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money.
Return *the number of combinations that make up that amount*. If that amount of money cannot be made up by any combination of the coins, return `0`.
You may assume that you have an infinite number of each kind of coin.
The answer is **guaranteed** to fit into a signed **32-bit** integer.
**Example 1:**
```
Input: amount = 5, coins = [1,2,5]
Output: 4
Explanation: there are four ways to make up the amount:
5=5
5=2+2+1
5=2+1+1+1
5=1+1+1+1+1
```
**Example 2:**
```
Input: amount = 3, coins = [2]
Output: 0
Explanation: the amount of 3 cannot be made up just with coins of 2.
```
**Example 3:**
```
Input: amount = 10, coins = [10]
Output: 1
```
**Constraints:**
- `1 <= coins.length <= 300`
- `1 <= coins[i] <= 5000`
- All the values of `coins` are **unique**.
- `0 <= amount <= 5000`
## 题目大意
给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0 。假设每一种面额的硬币有无限个。题目数据保证结果符合 32 位带符号整数。
## 解题思路
- 此题虽然名字叫 Coin Change但是不是经典的背包九讲问题。题目中 coins 的每个元素可以选取多次,且不考虑选取元素的顺序,因此这道题实际需要计算的是选取硬币的组合数。定义 dp[i] 表示金额之和等于 i 的硬币组合数,目标求 dp[amount]。初始边界条件为 dp[0] = 1即不取任何硬币就这一种取法金额为 0 。状态转移方程 dp[i] += dp[i-coin]coin 为当前枚举的 coin。
- 可能有读者会有疑惑,上述做法会不会出现重复计算。答案是不会。外层循环是遍历数组 coins 的值,内层循环是遍历不同的金额之和,在计算 dp[i] 的值时,可以确保金额之和等于 i 的硬币面额的顺序,由于顺序确定,因此不会重复计算不同的排列。
- 和此题完全一致的解题思路的题有,第 377 题和第 494 题。
## 代码
```go
package leetcode
func change(amount int, coins []int) int {
dp := make([]int, amount+1)
dp[0] = 1
for _, coin := range coins {
for i := coin; i <= amount; i++ {
dp[i] += dp[i-coin]
}
}
return dp[amount]
}
```

View File

@ -65,5 +65,5 @@ func firstBadVersion(n int) int {
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0275.H-Index-II/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0283.Move-Zeroes/">下一页➡️</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0279.Perfect-Squares/">下一页➡️</a></p>
</div>

View File

@ -0,0 +1,85 @@
# [279. Perfect Squares](https://leetcode.com/problems/perfect-squares/)
## 题目
Given an integer `n`, return *the least number of perfect square numbers that sum to* `n`.
A **perfect square** is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, `1`, `4`, `9`, and `16` are perfect squares while `3` and `11` are not.
**Example 1:**
```
Input: n = 12
Output: 3
Explanation: 12 = 4 + 4 + 4.
```
**Example 2:**
```
Input: n = 13
Output: 2
Explanation: 13 = 4 + 9.
```
**Constraints:**
- `1 <= n <= 104`
## 题目大意
给定正整数 n找到若干个完全平方数比如 1, 4, 9, 16, ...)使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。给你一个整数 n ,返回和为 n 的完全平方数的 最少数量 。
完全平方数 是一个整数其值等于另一个整数的平方换句话说其值等于一个整数自乘的积。例如1、4、9 和 16 都是完全平方数,而 3 和 11 不是。
## 解题思路
- 由拉格朗日的四平方定理可得,每个自然数都可以表示为四个整数平方之和。 其中四个数字是整数。四平方和定理证明了任意一个正整数都可以被表示为至多四个正整数的平方和。这给出了本题的答案的上界。
- 四平方和定理可以推出三平方和推论:当且仅当 {{< katex >}} n \neq 4^{k} \times (8*m + 7){{< /katex >}} 时n 可以被表示为至多三个正整数的平方和。所以当 {{< katex >}} n = 4^{k} * (8*m + 7){{< /katex >}} 时n 只能被表示为四个正整数的平方和。此时我们可以直接返回 4。
- 当 {{< katex >}} n \neq 4^{k} \times (8*m + 7){{< /katex >}} 时,需要判断 n 到底可以分解成几个完全平方数之和。答案肯定是 123 中的一个。题目要求我们求最小的,所以从 1 开始一个个判断是否满足。如果答案为 1代表 n 为完全平方数,这很好判断。如果答案为 2代表 {{< katex >}} n = a^{2} + b^{2} {{< /katex >}},枚举 {{< katex >}} 1 \leqslant a \leqslant \sqrt{n} {{< /katex >}},判断 {{< katex >}} n - a^{2} {{< /katex >}} 是否为完全平方数。当 1 和 2 都排除了,剩下的答案只能为 3 了。
## 代码
```go
package leetcode
import "math"
func numSquares(n int) int {
if isPerfectSquare(n) {
return 1
}
if checkAnswer4(n) {
return 4
}
for i := 1; i*i <= n; i++ {
j := n - i*i
if isPerfectSquare(j) {
return 2
}
}
return 3
}
// 判断是否为完全平方数
func isPerfectSquare(n int) bool {
sq := int(math.Floor(math.Sqrt(float64(n))))
return sq*sq == n
}
// 判断是否能表示为 4^k*(8m+7)
func checkAnswer4(x int) bool {
for x%4 == 0 {
x /= 4
}
return x%8 == 7
}
```
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0278.First-Bad-Version/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0283.Move-Zeroes/">下一页➡️</a></p>
</div>

View File

@ -57,6 +57,6 @@ func moveZeroes(nums []int) {
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0278.First-Bad-Version/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0279.Perfect-Squares/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0200~0299/0284.Peeking-Iterator/">下一页➡️</a></p>
</div>

View File

@ -96,5 +96,5 @@ func largestValues1(root *TreeNode) []int {
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0513.Find-Bottom-Left-Tree-Value/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0523.Continuous-Subarray-Sum/">下一页➡️</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0518.Coin-Change-2/">下一页➡️</a></p>
</div>

View File

@ -0,0 +1,80 @@
# [518. Coin Change 2](https://leetcode.com/problems/coin-change-2/)
## 题目
You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money.
Return *the number of combinations that make up that amount*. If that amount of money cannot be made up by any combination of the coins, return `0`.
You may assume that you have an infinite number of each kind of coin.
The answer is **guaranteed** to fit into a signed **32-bit** integer.
**Example 1:**
```
Input: amount = 5, coins = [1,2,5]
Output: 4
Explanation: there are four ways to make up the amount:
5=5
5=2+2+1
5=2+1+1+1
5=1+1+1+1+1
```
**Example 2:**
```
Input: amount = 3, coins = [2]
Output: 0
Explanation: the amount of 3 cannot be made up just with coins of 2.
```
**Example 3:**
```
Input: amount = 10, coins = [10]
Output: 1
```
**Constraints:**
- `1 <= coins.length <= 300`
- `1 <= coins[i] <= 5000`
- All the values of `coins` are **unique**.
- `0 <= amount <= 5000`
## 题目大意
给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0 。假设每一种面额的硬币有无限个。题目数据保证结果符合 32 位带符号整数。
## 解题思路
- 此题虽然名字叫 Coin Change但是不是经典的背包九讲问题。题目中 coins 的每个元素可以选取多次,且不考虑选取元素的顺序,因此这道题实际需要计算的是选取硬币的组合数。定义 dp[i] 表示金额之和等于 i 的硬币组合数,目标求 dp[amount]。初始边界条件为 dp[0] = 1即不取任何硬币就这一种取法金额为 0 。状态转移方程 dp[i] += dp[i-coin]coin 为当前枚举的 coin。
- 可能有读者会有疑惑,上述做法会不会出现重复计算。答案是不会。外层循环是遍历数组 coins 的值,内层循环是遍历不同的金额之和,在计算 dp[i] 的值时,可以确保金额之和等于 i 的硬币面额的顺序,由于顺序确定,因此不会重复计算不同的排列。
- 和此题完全一致的解题思路的题有,第 377 题和第 494 题。
## 代码
```go
package leetcode
func change(amount int, coins []int) int {
dp := make([]int, amount+1)
dp[0] = 1
for _, coin := range coins {
for i := coin; i <= amount; i++ {
dp[i] += dp[i-coin]
}
}
return dp[amount]
}
```
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0515.Find-Largest-Value-in-Each-Tree-Row/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0523.Continuous-Subarray-Sum/">下一页➡️</a></p>
</div>

View File

@ -77,6 +77,6 @@ func checkSubarraySum(nums []int, k int) bool {
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0515.Find-Largest-Value-in-Each-Tree-Row/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0518.Coin-Change-2/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0500~0599/0524.Longest-Word-in-Dictionary-through-Deleting/">下一页➡️</a></p>
</div>

View File

@ -119,7 +119,7 @@ weight: 1
|1002|Find Common Characters|[Go]({{< relref "/ChapterFour/1000~1099/1002.Find-Common-Characters.md" >}})|Easy||||68.7%|
|1011|Capacity To Ship Packages Within D Days|[Go]({{< relref "/ChapterFour/1000~1099/1011.Capacity-To-Ship-Packages-Within-D-Days.md" >}})|Medium||||60.4%|
|1018|Binary Prefix Divisible By 5|[Go]({{< relref "/ChapterFour/1000~1099/1018.Binary-Prefix-Divisible-By-5.md" >}})|Easy||||47.6%|
|1040|Moving Stones Until Consecutive II|[Go]({{< relref "/ChapterFour/1000~1099/1040.Moving-Stones-Until-Consecutive-II.md" >}})|Medium||||54.8%|
|1040|Moving Stones Until Consecutive II|[Go]({{< relref "/ChapterFour/1000~1099/1040.Moving-Stones-Until-Consecutive-II.md" >}})|Medium||||54.7%|
|1051|Height Checker|[Go]({{< relref "/ChapterFour/1000~1099/1051.Height-Checker.md" >}})|Easy||||73.0%|
|1052|Grumpy Bookstore Owner|[Go]({{< relref "/ChapterFour/1000~1099/1052.Grumpy-Bookstore-Owner.md" >}})|Medium||||56.1%|
|1074|Number of Submatrices That Sum to Target|[Go]({{< relref "/ChapterFour/1000~1099/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})|Hard||||65.2%|

View File

@ -10,7 +10,7 @@ weight: 19
| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
|0218|The Skyline Problem|[Go]({{< relref "/ChapterFour/0200~0299/0218.The-Skyline-Problem.md" >}})|Hard||||37.0%|
|0218|The Skyline Problem|[Go]({{< relref "/ChapterFour/0200~0299/0218.The-Skyline-Problem.md" >}})|Hard||||37.1%|
|0307|Range Sum Query - Mutable|[Go]({{< relref "/ChapterFour/0300~0399/0307.Range-Sum-Query-Mutable.md" >}})|Medium||||37.3%|
|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0300~0399/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard||||42.3%|
|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0300~0399/0327.Count-of-Range-Sum.md" >}})|Hard||||36.3%|

View File

@ -21,6 +21,7 @@ weight: 10
|0200|Number of Islands|[Go]({{< relref "/ChapterFour/0200~0299/0200.Number-of-Islands.md" >}})|Medium| O(n^2)| O(n^2)||50.3%|
|0207|Course Schedule|[Go]({{< relref "/ChapterFour/0200~0299/0207.Course-Schedule.md" >}})|Medium| O(n^2)| O(n^2)||44.5%|
|0210|Course Schedule II|[Go]({{< relref "/ChapterFour/0200~0299/0210.Course-Schedule-II.md" >}})|Medium| O(n^2)| O(n^2)||43.6%|
|0279|Perfect Squares|[Go]({{< relref "/ChapterFour/0200~0299/0279.Perfect-Squares.md" >}})|Medium||||49.7%|
|0417|Pacific Atlantic Water Flow|[Go]({{< relref "/ChapterFour/0400~0499/0417.Pacific-Atlantic-Water-Flow.md" >}})|Medium||||44.8%|
|0513|Find Bottom Left Tree Value|[Go]({{< relref "/ChapterFour/0500~0599/0513.Find-Bottom-Left-Tree-Value.md" >}})|Medium||||63.2%|
|0515|Find Largest Value in Each Tree Row|[Go]({{< relref "/ChapterFour/0500~0599/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})|Medium| O(n)| O(n)||62.8%|

View File

@ -77,7 +77,7 @@ weight: 9
|0979|Distribute Coins in Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0979.Distribute-Coins-in-Binary-Tree.md" >}})|Medium||||70.2%|
|0980|Unique Paths III|[Go]({{< relref "/ChapterFour/0900~0999/0980.Unique-Paths-III.md" >}})|Hard| O(n log n)| O(n)||77.1%|
|0987|Vertical Order Traversal of a Binary Tree|[Go]({{< relref "/ChapterFour/0900~0999/0987.Vertical-Order-Traversal-of-a-Binary-Tree.md" >}})|Hard||||39.3%|
|1020|Number of Enclaves|[Go]({{< relref "/ChapterFour/1000~1099/1020.Number-of-Enclaves.md" >}})|Medium||||59.7%|
|1020|Number of Enclaves|[Go]({{< relref "/ChapterFour/1000~1099/1020.Number-of-Enclaves.md" >}})|Medium||||59.6%|
|1026|Maximum Difference Between Node and Ancestor|[Go]({{< relref "/ChapterFour/1000~1099/1026.Maximum-Difference-Between-Node-and-Ancestor.md" >}})|Medium||||70.1%|
|1028|Recover a Tree From Preorder Traversal|[Go]({{< relref "/ChapterFour/1000~1099/1028.Recover-a-Tree-From-Preorder-Traversal.md" >}})|Hard||||71.3%|
|1038|Binary Search Tree to Greater Sum Tree|[Go]({{< relref "/ChapterFour/1000~1099/1038.Binary-Search-Tree-to-Greater-Sum-Tree.md" >}})|Medium||||83.1%|

View File

@ -30,6 +30,7 @@ weight: 7
|0198|House Robber|[Go]({{< relref "/ChapterFour/0100~0199/0198.House-Robber.md" >}})|Medium| O(n)| O(n)||43.6%|
|0213|House Robber II|[Go]({{< relref "/ChapterFour/0200~0299/0213.House-Robber-II.md" >}})|Medium| O(n)| O(n)||37.9%|
|0264|Ugly Number II|[Go]({{< relref "/ChapterFour/0200~0299/0264.Ugly-Number-II.md" >}})|Medium||||43.2%|
|0279|Perfect Squares|[Go]({{< relref "/ChapterFour/0200~0299/0279.Perfect-Squares.md" >}})|Medium||||49.7%|
|0300|Longest Increasing Subsequence|[Go]({{< relref "/ChapterFour/0300~0399/0300.Longest-Increasing-Subsequence.md" >}})|Medium| O(n log n)| O(n)||45.2%|
|0303|Range Sum Query - Immutable|[Go]({{< relref "/ChapterFour/0300~0399/0303.Range-Sum-Query-Immutable.md" >}})|Easy||||49.3%|
|0304|Range Sum Query 2D - Immutable|[Go]({{< relref "/ChapterFour/0300~0399/0304.Range-Sum-Query-2D-Immutable.md" >}})|Medium||||43.8%|
@ -76,7 +77,7 @@ weight: 7
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.2%|
|1659|Maximize Grid Happiness|[Go]({{< relref "/ChapterFour/1600~1699/1659.Maximize-Grid-Happiness.md" >}})|Hard||||35.9%|
|1664|Ways to Make a Fair Array|[Go]({{< relref "/ChapterFour/1600~1699/1664.Ways-to-Make-a-Fair-Array.md" >}})|Medium||||62.1%|
|1690|Stone Game VII|[Go]({{< relref "/ChapterFour/1600~1699/1690.Stone-Game-VII.md" >}})|Medium||||58.5%|
|1690|Stone Game VII|[Go]({{< relref "/ChapterFour/1600~1699/1690.Stone-Game-VII.md" >}})|Medium||||58.6%|
|1691|Maximum Height by Stacking Cuboids|[Go]({{< relref "/ChapterFour/1600~1699/1691.Maximum-Height-by-Stacking-Cuboids.md" >}})|Hard||||51.0%|
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|

View File

@ -33,6 +33,7 @@ weight: 12
|0263|Ugly Number|[Go]({{< relref "/ChapterFour/0200~0299/0263.Ugly-Number.md" >}})|Easy| O(log n)| O(1)||41.7%|
|0264|Ugly Number II|[Go]({{< relref "/ChapterFour/0200~0299/0264.Ugly-Number-II.md" >}})|Medium||||43.2%|
|0268|Missing Number|[Go]({{< relref "/ChapterFour/0200~0299/0268.Missing-Number.md" >}})|Easy||||56.0%|
|0279|Perfect Squares|[Go]({{< relref "/ChapterFour/0200~0299/0279.Perfect-Squares.md" >}})|Medium||||49.7%|
|0326|Power of Three|[Go]({{< relref "/ChapterFour/0300~0399/0326.Power-of-Three.md" >}})|Easy| O(1)| O(1)||42.5%|
|0343|Integer Break|[Go]({{< relref "/ChapterFour/0300~0399/0343.Integer-Break.md" >}})|Medium| O(n^2)| O(n)||51.5%|
|0357|Count Numbers with Unique Digits|[Go]({{< relref "/ChapterFour/0300~0399/0357.Count-Numbers-with-Unique-Digits.md" >}})|Medium| O(1)| O(1)||49.3%|

View File

@ -37,7 +37,7 @@ weight: 18
| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
|0218|The Skyline Problem|[Go]({{< relref "/ChapterFour/0200~0299/0218.The-Skyline-Problem.md" >}})|Hard| O(n log n)| O(n)|❤️|37.0%|
|0218|The Skyline Problem|[Go]({{< relref "/ChapterFour/0200~0299/0218.The-Skyline-Problem.md" >}})|Hard| O(n log n)| O(n)|❤️|37.1%|
|0307|Range Sum Query - Mutable|[Go]({{< relref "/ChapterFour/0300~0399/0307.Range-Sum-Query-Mutable.md" >}})|Medium| O(1)| O(n)||37.3%|
|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0300~0399/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard| O(n log n)| O(n)||42.3%|
|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0300~0399/0327.Count-of-Range-Sum.md" >}})|Hard| O(n log n)| O(n)|❤️|36.3%|

View File

@ -40,7 +40,7 @@ weight: 17
|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0900~0999/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard| O(n)| O(n)|❤️|51.4%|
|0995|Minimum Number of K Consecutive Bit Flips|[Go]({{< relref "/ChapterFour/0900~0999/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md" >}})|Hard| O(n)| O(1)|❤️|50.3%|
|1004|Max Consecutive Ones III|[Go]({{< relref "/ChapterFour/1000~1099/1004.Max-Consecutive-Ones-III.md" >}})|Medium| O(n)| O(1) ||61.3%|
|1040|Moving Stones Until Consecutive II|[Go]({{< relref "/ChapterFour/1000~1099/1040.Moving-Stones-Until-Consecutive-II.md" >}})|Medium| O(n log n)| O(1) |❤️|54.8%|
|1040|Moving Stones Until Consecutive II|[Go]({{< relref "/ChapterFour/1000~1099/1040.Moving-Stones-Until-Consecutive-II.md" >}})|Medium| O(n log n)| O(1) |❤️|54.7%|
|1052|Grumpy Bookstore Owner|[Go]({{< relref "/ChapterFour/1000~1099/1052.Grumpy-Bookstore-Owner.md" >}})|Medium| O(n log n)| O(1) ||56.1%|
|1074|Number of Submatrices That Sum to Target|[Go]({{< relref "/ChapterFour/1000~1099/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})|Hard| O(n^3)| O(n) |❤️|65.2%|
|1208|Get Equal Substrings Within Budget|[Go]({{< relref "/ChapterFour/1200~1299/1208.Get-Equal-Substrings-Within-Budget.md" >}})|Medium||||44.7%|

View File

@ -24,7 +24,7 @@ weight: 5
|0094|Binary Tree Inorder Traversal|[Go]({{< relref "/ChapterFour/0001~0099/0094.Binary-Tree-Inorder-Traversal.md" >}})|Easy| O(n)| O(1)||67.1%|
|0103|Binary Tree Zigzag Level Order Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})|Medium| O(n)| O(n)||51.0%|
|0144|Binary Tree Preorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0144.Binary-Tree-Preorder-Traversal.md" >}})|Easy| O(n)| O(1)||58.5%|
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Easy| O(n)| O(1)||58.9%|
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Easy| O(n)| O(1)||59.0%|
|0150|Evaluate Reverse Polish Notation|[Go]({{< relref "/ChapterFour/0100~0199/0150.Evaluate-Reverse-Polish-Notation.md" >}})|Medium| O(n)| O(1)||39.6%|
|0155|Min Stack|[Go]({{< relref "/ChapterFour/0100~0199/0155.Min-Stack.md" >}})|Easy| O(n)| O(n)||47.3%|
|0173|Binary Search Tree Iterator|[Go]({{< relref "/ChapterFour/0100~0199/0173.Binary-Search-Tree-Iterator.md" >}})|Medium| O(n)| O(1)||61.5%|

View File

@ -31,7 +31,7 @@ weight: 6
|0124|Binary Tree Maximum Path Sum|[Go]({{< relref "/ChapterFour/0100~0199/0124.Binary-Tree-Maximum-Path-Sum.md" >}})|Hard| O(n)| O(1)||36.0%|
|0129|Sum Root to Leaf Numbers|[Go]({{< relref "/ChapterFour/0100~0199/0129.Sum-Root-to-Leaf-Numbers.md" >}})|Medium| O(n)| O(1)||52.0%|
|0144|Binary Tree Preorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0144.Binary-Tree-Preorder-Traversal.md" >}})|Easy| O(n)| O(1)||58.5%|
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Easy| O(n)| O(1)||58.9%|
|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0100~0199/0145.Binary-Tree-Postorder-Traversal.md" >}})|Easy| O(n)| O(1)||59.0%|
|0173|Binary Search Tree Iterator|[Go]({{< relref "/ChapterFour/0100~0199/0173.Binary-Search-Tree-Iterator.md" >}})|Medium| O(n)| O(1)||61.5%|
|0199|Binary Tree Right Side View|[Go]({{< relref "/ChapterFour/0100~0199/0199.Binary-Tree-Right-Side-View.md" >}})|Medium| O(n)| O(1)||57.0%|
|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0200~0299/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||50.5%|