diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..405ec2c3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.toml
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 93139647..eb946948 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,6 +3,7 @@
"go.formatFlags": [
"-s"
],
+ "go.autocompleteUnimportedPackages": true,
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
diff --git a/README_old.md b/README_old.md
new file mode 100644
index 00000000..bc1892c4
--- /dev/null
+++ b/README_old.md
@@ -0,0 +1,1173 @@
+
+# LeetCode by Go
+[LeetCode Online Judge] (https://leetcode.com/) is a website containing many **algorithm questions**. Most of them are real interview questions of **Google, Facebook, LinkedIn, Apple**, etc. This repo shows my solutions by Go with the code style strictly follows the [Google Golang Style Guide](https://github.com/golang/go/wiki/CodeReviewComments). Please feel free to reference and **STAR** to support this repo, thank you!
+
+
+
+
+
+
+
+
+
+## 数据结构
+
+| 数据结构 | 变种 | 相关题目 |
+|:-------:|:-------|:------|
+|顺序线性表:向量|||
+|单链表|1.双链表 2.静态链表 3.对称矩阵 4.稀疏矩阵||
+|栈|广义栈||
+|队列|1.链表实现 2.循环数组实现 3.双端队列||
+|字符串|1.KMP算法 2.有限状态自动机 3.模式匹配有限状态自动机 4.BM模式匹配算法 5.BM-KMP算法||
+|树|1.二叉树 2.并查集 3.Huffman数||
+|数组实现的堆|1.极大堆和极小堆 2.极大极小堆 3.双端堆 4.d叉堆||
+|树实现的堆|1.左堆 2.扁堆 3.二项式堆 4.斐波那契堆 5.配对堆||
+|查找|1.哈希表 2.跳跃表 3.排序二叉树 4.AVL树 5.B树 6.AA树 7.红黑树 8.排序二叉堆 9.Splay树 10.双链树 11.Trie树||
+
+
+## Data Structures
+
+> 标识了 (已全部做完) 的专题是全部完成了的,没有标识的是还没有做完的
+
+* [Array](#array)
+* [String](#string)
+* [Linked List](#linked-list)
+* [Stack](#stack)
+* [Tree](#tree)
+* [Dynamic programming](#dynamic-programming)
+* [Depth-first search](#depth-first-search)
+* [Math](#math)
+* [Search](#search)
+* [Sort](#sort)
+* [Union Find](#union-find)
+
+## Companies
+* [Google](#google)
+* [Facebook](#facebook)
+* [Snapchat](#snapchat)
+* [Uber](#uber)
+* [Airbnb](#airbnb)
+* [LinkedIn](#linkedin)
+* [Amazon](#amazon)
+* [Microsoft](#microsoft)
+
+
+## 算法
+
+
+## 一. 目录
+
+|题号|题目|通过率|难度|收藏|
+|:--:|:--|:--: | :--: | :--: |
+|1|[Two Sum](./Algorithms/1.two-sum)|38%|Easy||
+|2|[Add Two Numbers](./Algorithms/2.add-two-numbers)|28%|Medium||
+|3|[Longest Substring Without Repeating Characters](./Algorithms/3.longest-substring-without-repeating-characters)|24%|Medium||
+|4|[Median of Two Sorted Arrays](./Algorithms/4.median-of-two-sorted-arrays)|23%|Hard||
+|5|[Longest Palindromic Substring](./Algorithms/5.longest-palindromic-substring)|25%|Medium||
+|6|[ZigZag Conversion](./Algorithms/6.zigzag-conversion)|27%|Medium||
+|7|[Reverse Integer](./Algorithms/7.reverse-integer)|24%|Easy||
+|8|[String to Integer (atoi)](./Algorithms/8.string-to-integer-atoi)|14%|Medium||
+|9|[Palindrome Number](./Algorithms/9.palindrome-number)|35%|Easy||
+|10|[Regular Expression Matching](./Algorithms/10.regular-expression-matching)|24%|Hard|❤️|
+|11|[Container With Most Water](./Algorithms/11.container-with-most-water)|37%|Medium||
+|12|[Integer to Roman](./Algorithms/12.integer-to-roman)|46%|Medium||
+|13|[Roman to Integer](./Algorithms/13.roman-to-integer)|48%|Easy||
+|14|[Longest Common Prefix](./Algorithms/14.longest-common-prefix)|31%|Easy||
+|15|[3Sum](./Algorithms/15.3sum)|21%|Medium||
+|16|[3Sum Closest](./Algorithms/16.3sum-closest)|31%|Medium||
+|17|[Letter Combinations of a Phone Number](./Algorithms/17.letter-combinations-of-a-phone-number)|36%|Medium||
+|18|[4Sum](./Algorithms/18.4sum)|27%|Medium||
+|19|[Remove Nth Node From End of List](./Algorithms/19.remove-nth-node-from-end-of-list)|33%|Medium||
+|20|[Valid Parentheses](./Algorithms/20.Valid-Parentheses)|33%|Easy||
+|21|[Merge Two Sorted Lists](./Algorithms/21.merge-two-sorted-lists)|41%|Easy||
+|22|[Generate Parentheses](./Algorithms/22.generate-parentheses)|48%|Medium|❤️|
+|23|[Merge k Sorted Lists](./Algorithms/23.merge-k-sorted-lists)|28%|Hard||
+|24|[Swap Nodes in Pairs](./Algorithms/24.Swap-Nodes-In-Pairs)|39%|Medium|❤️|
+|25|[Reverse Nodes in k-Group](./Algorithms/25.Reverse-Nodes-In-k-Group)|31%|Hard|❤️|
+|26|[Remove Duplicates from Sorted Array](./Algorithms/26.remove-duplicates-from-sorted-array)|36%|Easy|❤️|
+|27|[Remove Element](./Algorithms/27.remove-element)|40%|Easy||
+|28|[Implement strStr()](./Algorithms/28.implement-strstr)|28%|Easy||
+|29|[Divide Two Integers](./Algorithms/29.divide-two-integers)|15%|Medium||
+|30|[Substring with Concatenation of All Words](./Algorithms/30.substring-with-concatenation-of-all-words)|22%|Hard|❤️|
+|31|[Next Permutation](./Algorithms/31.next-permutation)|29%|Medium|❤️|
+|32|[Longest Valid Parentheses](./Algorithms/32.longest-valid-parentheses)|23%|Hard||
+|33|[Search in Rotated Sorted Array](./Algorithms/33.search-in-rotated-sorted-array)|31%|Medium|❤️|
+|34|[Search for a Range](./Algorithms/34.search-for-a-range)|31%|Medium||
+|35|[Search Insert Position](./Algorithms/35.search-insert-position)|40%|Easy||
+|36|[Valid Sudoku](./Algorithms/36.valid-sudoku)|37%|Medium|❤️|
+|37|[Sudoku Solver](./Algorithms/37.sudoku-solver)|32%|Hard|❤️|
+|38|[Count and Say](./Algorithms/38.count-and-say)|36%|Easy||
+|39|[Combination Sum](./Algorithms/39.combination-sum)|41%|Medium||
+|40|[Combination Sum II](./Algorithms/40.combination-sum-ii)|35%|Medium||
+|41|[First Missing Positive](./Algorithms/41.First-Missing-Positive)|25%|Hard||
+|42|[Trapping Rain Water](./Algorithms/42.trapping-rain-water)|37%|Hard||
+|43|[Multiply Strings](./Algorithms/43.multiply-strings)|28%|Medium||
+|44|[Wildcard Matching](./Algorithms/44.wildcard-matching)|21%|Hard|❤️|
+|45|[Jump Game II](./Algorithms/45.jump-game-ii)|26%|Hard||
+|46|[Permutations](./Algorithms/46.permutations)|47%|Medium||
+|47|[Permutations II](./Algorithms/47.permutations-ii)|35%|Medium||
+|48|[Rotate Image](./Algorithms/48.rotate-image)|41%|Medium||
+|49|[Group Anagrams](./Algorithms/49.group-anagrams)|38%|Medium|❤️|
+|50|[Pow(x, n)](./Algorithms/50.powx-n)|26%|Medium||
+|51|[N-Queens](./Algorithms/51.n-queens)|33%|Hard||
+|52|[N-Queens II](./Algorithms/52.n-queens-ii)|46%|Hard||
+|53|[Maximum Subarray](./Algorithms/53.maximum-subarray)|40%|Easy|❤️|
+|54|[Spiral Matrix](./Algorithms/54.spiral-matrix)|27%|Medium|❤️|
+|55|[Jump Game](./Algorithms/55.jump-game)|29%|Medium||
+|56|[Merge Intervals](./Algorithms/56.merge-intervals)|31%|Medium|❤️|
+|57|[Insert Interval](./Algorithms/57.insert-interval)|28%|Hard||
+|58|[Length of Last Word](./Algorithms/58.length-of-last-word)|32%|Easy||
+|59|[Spiral Matrix II](./Algorithms/59.spiral-matrix-ii)|41%|Medium|❤️|
+|60|[Permutation Sequence](./Algorithms/60.permutation-sequence)|29%|Medium||
+|61|[Rotate List](./Algorithms/61.rotate-list)|24%|Medium|❤️|
+|62|[Unique Paths](./Algorithms/62.unique-paths)|42%|Medium|❤️|
+|63|[Unique Paths II](./Algorithms/63.unique-paths-ii)|32%|Medium||
+|64|[Minimum Path Sum](./Algorithms/64.minimum-path-sum)|40%|Medium||
+|65|[Valid Number](./Algorithms/65.valid-number)|12%|Hard||
+|66|[Plus One](./Algorithms/66.plus-one)|39%|Easy||
+|67|[Add Binary](./Algorithms/67.add-binary)|34%|Easy||
+|68|[Text Justification](./Algorithms/68.text-justification)|20%|Hard||
+|69|[Sqrt(x)](./Algorithms/69.sqrtx)|28%|Easy||
+|70|[Climbing Stairs](./Algorithms/70.climbing-stairs)|41%|Easy||
+|71|[Simplify Path](./Algorithms/71.simplify-path)|26%|Medium||
+|72|[Edit Distance](./Algorithms/72.edit-distance)|32%|Hard|❤️|
+|73|[Set Matrix Zeroes](./Algorithms/73.set-matrix-zeroes)|36%|Medium|❤️|
+|74|[Search a 2D Matrix](./Algorithms/74.search-a-2d-matrix)|34%|Medium||
+|75|[Sort Colors](./Algorithms/75.sort-colors)|38%|Medium|❤️|
+|76|[Minimum Window Substring](./Algorithms/76.minimum-window-substring)|26%|Hard|❤️|
+|77|[Combinations](./Algorithms/77.combinations)|41%|Medium||
+|78|[Subsets](./Algorithms/78.subsets)|44%|Medium|❤️|
+|79|[Word Search](./Algorithms/79.word-search)|28%|Medium||
+|80|[Remove Duplicates from Sorted Array II](./Algorithms/80.remove-duplicates-from-sorted-array-ii)|36%|Medium|❤️|
+|81|[Search in Rotated Sorted Array II](./Algorithms/81.search-in-rotated-sorted-array-ii)|32%|Medium||
+|82|[Remove Duplicates from Sorted List II](./Algorithms/82.remove-duplicates-from-sorted-list-ii)|29%|Medium|❤️|
+|83|[Remove Duplicates from Sorted List](./Algorithms/83.remove-duplicates-from-sorted-list)|40%|Easy||
+|84|[Largest Rectangle in Histogram](./Algorithms/84.largest-rectangle-in-histogram)|27%|Hard|❤️|
+|85|[Maximal Rectangle](./Algorithms/85.maximal-rectangle)|29%|Hard|❤️|
+|86|[Partition List](./Algorithms/86.partition-list)|33%|Medium||
+|87|[Scramble String](./Algorithms/87.scramble-string)|29%|Hard|❤️|
+|88|[Merge Sorted Array](./Algorithms/88.Merge-Sorted-Array)|32%|Easy||
+|89|[Gray Code](./Algorithms/89.gray-code)|42%|Medium||
+|90|[Subsets II](./Algorithms/90.subsets-ii)|38%|Medium|❤️|
+|91|[Decode Ways](./Algorithms/91.decode-ways)|20%|Medium|❤️|
+|92|[Reverse Linked List II](./Algorithms/92.reverse-linked-list-ii)|31%|Medium||
+|93|[Restore IP Addresses](./Algorithms/93.restore-ip-addresses)|28%|Medium|❤️|
+|94|[Binary Tree Inorder Traversal](./Algorithms/94.binary-tree-inorder-traversal)|49%|Medium||
+|95|[Unique Binary Search Trees II](./Algorithms/95.unique-binary-search-trees-ii)|32%|Medium|❤️|
+|96|[Unique Binary Search Trees](./Algorithms/96.unique-binary-search-trees)|41%|Medium||
+|97|[Interleaving String](./Algorithms/97.interleaving-string)|25%|Hard|❤️|
+|98|[Validate Binary Search Tree](./Algorithms/98.validate-binary-search-tree)|24%|Medium|❤️|
+|99|[Recover Binary Search Tree](./Algorithms/99.recover-binary-search-tree)|31%|Hard|❤️|
+|100|[Same Tree](./Algorithms/100.same-tree)|47%|Easy||
+|101|[Symmetric Tree](./Algorithms/101.symmetric-tree)|40%|Easy|❤️|
+|102|[Binary Tree Level Order Traversal](./Algorithms/102.binary-tree-level-order-traversal)|42%|Medium||
+|103|[Binary Tree Zigzag Level Order Traversal](./Algorithms/103.binary-tree-zigzag-level-order-traversal)|36%|Medium||
+|104|[Maximum Depth of Binary Tree](./Algorithms/104.maximum-depth-of-binary-tree)|54%|Easy||
+|105|[Construct Binary Tree from Preorder and Inorder Traversal](./Algorithms/105.construct-binary-tree-from-preorder-and-inorder-traversal)|34%|Medium|❤️|
+|106|[Construct Binary Tree from Inorder and Postorder Traversal](./Algorithms/106.construct-binary-tree-from-inorder-and-postorder-traversal)|33%|Medium|❤️|
+|107|[Binary Tree Level Order Traversal II](./Algorithms/107.binary-tree-level-order-traversal-ii)|42%|Easy||
+|108|[Convert Sorted Array to Binary Search Tree](./Algorithms/108.convert-sorted-array-to-binary-search-tree)|44%|Easy||
+|109|[Convert Sorted List to Binary Search Tree](./Algorithms/109.convert-sorted-list-to-binary-search-tree)|35%|Medium||
+|110|[Balanced Binary Tree](./Algorithms/110.balanced-binary-tree)|38%|Easy||
+|111|[Minimum Depth of Binary Tree](./Algorithms/111.minimum-depth-of-binary-tree)|33%|Easy||
+|112|[Path Sum](./Algorithms/112.path-sum)|34%|Easy||
+|113|[Path Sum II](./Algorithms/113.path-sum-ii)|35%|Medium||
+|114|[Flatten Binary Tree to Linked List](./Algorithms/114.flatten-binary-tree-to-linked-list)|36%|Medium|❤️|
+|115|[Distinct Subsequences](./Algorithms/115.distinct-subsequences)|32%|Hard|❤️|
+|118|[Pascal's Triangle](./Algorithms/118.pascals-triangle)|40%|Easy||
+|119|[Pascal's Triangle II](./Algorithms/119.pascals-triangle-ii)|38%|Easy||
+|120|[Triangle](./Algorithms/120.triangle)|34%|Medium|❤️|
+|121|[Best Time to Buy and Sell Stock](./Algorithms/121.best-time-to-buy-and-sell-stock)|42%|Easy||
+|122|[Best Time to Buy and Sell Stock II](./Algorithms/122.best-time-to-buy-and-sell-stock-ii)|47%|Easy||
+|123|[Best Time to Buy and Sell Stock III](./Algorithms/123.best-time-to-buy-and-sell-stock-iii)|30%|Hard||
+|124|[Binary Tree Maximum Path Sum](./Algorithms/124.binary-tree-maximum-path-sum)|27%|Hard|❤️|
+|125|[Valid Palindrome](./Algorithms/125.Valid-Palindrome)|27.0%|Easy||
+|126|[Word Ladder II](./Algorithms/126.word-ladder-ii)|14%|Hard|❤️|
+|127|[Word Ladder](./Algorithms/127.word-ladder)|20%|Medium|❤️|
+|128|[Longest Consecutive Sequence](./Algorithms/128.longest-consecutive-sequence)|38%|Hard||
+|129|[Sum Root to Leaf Numbers](./Algorithms/129.sum-root-to-leaf-numbers)|37%|Medium||
+|130|[Surrounded Regions](./Algorithms/130.surrounded-regions)|19%|Medium|❤️|
+|131|[Palindrome Partitioning](./Algorithms/131.palindrome-partitioning)|35%|Medium|❤️|
+|132|[Palindrome Partitioning II](./Algorithms/132.palindrome-partitioning-ii)|24%|Hard|❤️|
+|134|[Gas Station](./Algorithms/134.gas-station)|29%|Medium|❤️|
+|135|[Candy](./Algorithms/135.candy)|25%|Hard||
+|136|[Single Number](./Algorithms/136.single-number)|55%|Easy||
+|137|[Single Number II](./Algorithms/137.single-number-ii)|42%|Medium|❤️|
+|139|[Word Break](./Algorithms/139.word-break)|31%|Medium|❤️|
+|140|[Word Break II](./Algorithms/140.word-break-ii)|24%|Hard|❤️|
+|141|[Linked List Cycle](./Algorithms/140.Linked-List-Cycle)|24%|Hard|❤️|
+|142|[Linked List Cycle II](./Algorithms/140.Linked-List-Cycle-II)|24%|Hard|❤️|
+|143|[Reorder List](./Algorithms/143.reorder-list)|26%|Medium|❤️|
+|144|[Binary Tree Preorder Traversal](./Algorithms/144.binary-tree-preorder-traversal)|46%|Medium|❤️|
+|145|[Binary Tree Postorder Traversal](./Algorithms/145.binary-tree-postorder-traversal)|42%|Hard||
+|146|[LRU Cache](./Algorithms/146.lru-cache)|19%|Hard|❤️|
+|147|[Insertion Sort List](./Algorithms/147.insertion-sort-list)|33%|Medium|❤️|
+|148|[Sort List](./Algorithms/148.sort-list)|29%|Medium|❤️|
+|149|[Max Points on a Line](./Algorithms/149.max-points-on-a-line)|15%|Hard|❤️|
+|150|[Evaluate Reverse Polish Notation](./Algorithms/150.evaluate-reverse-polish-notation)|28%|Medium||
+|152|[Maximum Product Subarray](./Algorithms/152.maximum-product-subarray)|26%|Medium|❤️|
+|153|[Find Minimum in Rotated Sorted Array](./Algorithms/153.find-minimum-in-rotated-sorted-array)|40%|Medium||
+|154|[Find Minimum in Rotated Sorted Array II](./Algorithms/154.find-minimum-in-rotated-sorted-array-ii)|37%|Hard||
+|155|[Min Stack](./Algorithms/155.min-stack)|31%|Easy||
+|162|[Find Peak Element](./Algorithms/162.find-peak-element)|38%|Medium||
+|164|[Maximum Gap](./Algorithms/164.maximum-gap)|30%|Hard||
+|165|[Compare Version Numbers](./Algorithms/165.compare-version-numbers)|20%|Medium||
+|166|[Fraction to Recurring Decimal](./Algorithms/166.fraction-to-recurring-decimal)|18%|Medium|❤️|
+|167|[Two Sum II - Input array is sorted](./Algorithms/167.two-sum-ii-input-array-is-sorted)|47%|Easy||
+|168|[Excel Sheet Column Title](./Algorithms/168.excel-sheet-column-title)|27%|Easy|❤️|
+|169|[Majority Element](./Algorithms/169.majority-element)|48%|Easy|❤️|
+|171|[Excel Sheet Column Number](./Algorithms/171.excel-sheet-column-number)|48%|Easy||
+|172|[Factorial Trailing Zeroes](./Algorithms/172.factorial-trailing-zeroes)|36%|Easy||
+|174|[Dungeon Game](./Algorithms/174.dungeon-game)|24%|Hard|❤️|
+|179|[Largest Number](./Algorithms/179.largest-number)|23%|Medium|❤️|
+|187|[Repeated DNA Sequences](./Algorithms/187.repeated-dna-sequences)|33%|Medium||
+|188|[Best Time to Buy and Sell Stock IV](./Algorithms/188.best-time-to-buy-and-sell-stock-iv)|24%|Hard|❤️|
+|189|[Rotate Array](./Algorithms/189.rotate-array)|25%|Easy||
+|198|[House Robber](./Algorithms/198.house-robber)|39%|Easy|❤️|
+|199|[Binary Tree Right Side View](./Algorithms/199.binary-tree-right-side-view)|42%|Medium||
+|200|[Number of Islands](./Algorithms/200.number-of-islands)|36%|Medium||
+|201|[Bitwise AND of Numbers Range](./Algorithms/201.bitwise-and-of-numbers-range)|34%|Medium|❤️|
+|202|[Happy Number](./Algorithms/202.happy-number)|41%|Easy||
+|203|[Remove Linked List Elements](./Algorithms/203.remove-linked-list-elements)|33%|Easy||
+|204|[Count Primes](./Algorithms/204.count-primes)|26%|Easy|❤️|
+|205|[Isomorphic Strings](./Algorithms/205.isomorphic-strings)|34%|Easy|❤️|
+|206|[Reverse Linked List](./Algorithms/206.Reverse-Linked-List)|46%|Easy||
+|207|[Course Schedule](./Algorithms/207.course-schedule)|33%|Medium|❤️|
+|208|[Implement Trie (Prefix Tree)](./Algorithms/208.implement-trie-prefix-tree)|30%|Medium|❤️|
+|209|[Minimum Size Subarray Sum](./Algorithms/209.minimum-size-subarray-sum)|32%|Medium||
+|210|[Course Schedule II](./Algorithms/210.course-schedule-ii)|30%|Medium||
+|211|[Add and Search Word - Data structure design](./Algorithms/211.add-and-search-word-data-structure-design)|25%|Medium|❤️|
+|212|[Word Search II](./Algorithms/212.word-search-ii)|24%|Hard|❤️|
+|213|[House Robber II](./Algorithms/213.house-robber-ii)|34%|Medium||
+|214|[Shortest Palindrome](./Algorithms/214.shortest-palindrome)|25%|Hard|❤️|
+|215|[Kth Largest Element in an Array](./Algorithms/215.kth-largest-element-in-an-array)|40%|Medium|❤️|
+|216|[Combination Sum III](./Algorithms/216.combination-sum-iii)|47%|Medium||
+|217|[Contains Duplicate](./Algorithms/217.contains-duplicate)|47%|Easy||
+|218|[The Skyline Problem](./Algorithms/218.the-skyline-problem)|29%|Hard|❤️|
+|219|[Contains Duplicate II](./Algorithms/219.contains-duplicate-ii)|32%|Easy||
+|220|[Contains Duplicate III](./Algorithms/220.contains-duplicate-iii)|18%|Medium|❤️|
+|221|[Maximal Square](./Algorithms/221.maximal-square)|30%|Medium|❤️|
+|223|[Rectangle Area](./Algorithms/223.rectangle-area)|33%|Medium||
+|224|[Basic Calculator](./Algorithms/224.basic-calculator)|28%|Hard||
+|225|[Implement Stack using Queues](./Algorithms/225.implement-stack-using-queues)|34%|Easy||
+|226|[Invert Binary Tree](./Algorithms/226.invert-binary-tree)|53%|Easy||
+|227|[Basic Calculator II](./Algorithms/227.basic-calculator-ii)|30%|Medium||
+|228|[Summary Ranges](./Algorithms/228.summary-ranges)|32%|Medium||
+|229|[Majority Element II](./Algorithms/229.majority-element-ii)|29%|Medium|❤️|
+|230|[Kth Smallest Element in a BST](./Algorithms/230.kth-smallest-element-in-a-bst)|45%|Medium||
+|231|[Power of Two](./Algorithms/231.power-of-two)|40%|Easy||
+|232|[Implement Queue using Stacks](./Algorithms/232.implement-queue-using-stacks)|38%|Easy||
+|233|[Number of Digit One](./Algorithms/233.number-of-digit-one)|29%|Hard|❤️|
+|234|[Palindrome Linked List](./Algorithms/234.palindrome-linked-list)|33%|Easy||
+|238|[Product of Array Except Self](./Algorithms/238.product-of-array-except-self)|50%|Medium||
+|239|[Sliding Window Maximum](./Algorithms/239.sliding-window-maximum)|34%|Hard|❤️|
+|240|[Search a 2D Matrix II](./Algorithms/240.search-a-2d-matrix-ii)|39%|Medium|❤️|
+|241|[Different Ways to Add Parentheses](./Algorithms/241.different-ways-to-add-parentheses)|46%|Medium||
+|242|[Valid Anagram](./Algorithms/242.valid-anagram)|47%|Easy||
+|257|[Binary Tree Paths](./Algorithms/257.binary-tree-paths)|41%|Easy||
+|258|[Add Digits](./Algorithms/258.add-digits)|51%|Easy||
+|260|[Single Number III](./Algorithms/260.single-number-iii)|53%|Medium|❤️|
+|263|[Ugly Number](./Algorithms/263.ugly-number)|39%|Easy||
+|264|[Ugly Number II](./Algorithms/264.ugly-number-ii)|33%|Medium|❤️|
+|268|[Missing Number](./Algorithms/268.missing-number)|45%|Easy||
+|273|[Integer to English Words](./Algorithms/273.integer-to-english-words)|22%|Hard|❤️|
+|274|[H-Index](./Algorithms/274.h-index)|33%|Medium||
+|275|[H-Index II](./Algorithms/275.h-index-ii)|34%|Medium|❤️|
+|279|[Perfect Squares](./Algorithms/279.perfect-squares)|37%|Medium|❤️|
+|282|[Expression Add Operators](./Algorithms/282.expression-add-operators)|30%|Hard|❤️|
+|283|[Move Zeroes](./Algorithms/283.move-zeroes)|51%|Easy||
+|287|[Find the Duplicate Number](./Algorithms/287.find-the-duplicate-number)|44%|Medium|❤️|
+|289|[Game of Life](./Algorithms/289.game-of-life)|37%|Medium|❤️|
+|290|[Word Pattern](./Algorithms/290.word-pattern)|33%|Easy||
+|292|[Nim Game](./Algorithms/292.nim-game)|55%|Easy|❤️|
+|295|[Find Median from Data Stream](./Algorithms/295.find-median-from-data-stream)|29%|Hard|❤️|
+|299|[Bulls and Cows](./Algorithms/299.bulls-and-cows)|35%|Medium||
+|300|[Longest Increasing Subsequence](./Algorithms/300.longest-increasing-subsequence)|38%|Medium|❤️|
+|301|[Remove Invalid Parentheses](./Algorithms/301.remove-invalid-parentheses)|35%|Hard|❤️|
+|303|[Range Sum Query - Immutable](./Algorithms/303.range-sum-query-immutable)|32%|Easy||
+|304|[Range Sum Query 2D - Immutable](./Algorithms/304.range-sum-query-2d-immutable)|27%|Medium||
+|306|[Additive Number](./Algorithms/306.additive-number)|27%|Medium||
+|307|[Range Sum Query - Mutable](./Algorithms/307.range-sum-query-mutable)|22%|Medium||
+|309|[Best Time to Buy and Sell Stock with Cooldown](./Algorithms/309.best-time-to-buy-and-sell-stock-with-cooldown)|41%|Medium|❤️|
+|310|[Minimum Height Trees](./Algorithms/310.minimum-height-trees)|28%|Medium||
+|312|[Burst Balloons](./Algorithms/312.burst-balloons)|43%|Hard|❤️|
+|313|[Super Ugly Number](./Algorithms/313.super-ugly-number)|38%|Medium|❤️|
+|315|[Count of Smaller Numbers After Self](./Algorithms/315.count-of-smaller-numbers-after-self)|34%|Hard|❤️|
+|316|[Remove Duplicate Letters](./Algorithms/316.remove-duplicate-letters)|30%|Hard|❤️|
+|318|[Maximum Product of Word Lengths](./Algorithms/318.maximum-product-of-word-lengths)|45%|Medium|❤️|
+|319|[Bulb Switcher](./Algorithms/319.bulb-switcher)|42%|Medium|❤️|
+|321|[Create Maximum Number](./Algorithms/321.create-maximum-number)|24%|Hard|❤️|
+|322|[Coin Change](./Algorithms/322.coin-change)|26%|Medium|❤️|
+|324|[Wiggle Sort II](./Algorithms/324.wiggle-sort-ii)|26%|Medium||
+|326|[Power of Three](./Algorithms/326.power-of-three)|40%|Easy|❤️|
+|327|[Count of Range Sum](./Algorithms/327.count-of-range-sum)|30%|Hard|❤️|
+|328|[Odd Even Linked List](./Algorithms/328.odd-even-linked-list)|44%|Medium|❤️|
+|329|[Longest Increasing Path in a Matrix](./Algorithms/329.longest-increasing-path-in-a-matrix)|37%|Hard|❤️|
+|330|[Patching Array](./Algorithms/330.patching-array)|32%|Hard||
+|331|[Verify Preorder Serialization of a Binary Tree](./Algorithms/331.verify-preorder-serialization-of-a-binary-tree)|37%|Medium|❤️|
+|332|[Reconstruct Itinerary](./Algorithms/332.reconstruct-itinerary)|29%|Medium|❤️|
+|334|[Increasing Triplet Subsequence](./Algorithms/334.increasing-triplet-subsequence)|39%|Medium|❤️|
+|335|[Self Crossing](./Algorithms/335.self-crossing)|26%|Hard||
+|336|[Palindrome Pairs](./Algorithms/336.palindrome-pairs)|27%|Hard|❤️|
+|337|[House Robber III](./Algorithms/337.house-robber-iii)|44%|Medium|❤️|
+|338|[Counting Bits](./Algorithms/338.counting-bits)|62%|Medium||
+|342|[Power of Four](./Algorithms/342.power-of-four)|39%|Easy||
+|343|[Integer Break](./Algorithms/343.integer-break)|46%|Medium||
+|344|[Reverse String](./Algorithms/344.reverse-string)|60%|Easy||
+|345|[Reverse Vowels of a String](./Algorithms/345.reverse-vowels-of-a-string)|39%|Easy||
+|347|[Top K Frequent Elements](./Algorithms/347.top-k-frequent-elements)|49%|Medium||
+|349|[Intersection of Two Arrays](./Algorithms/349.intersection-of-two-arrays)|48%|Easy||
+|350|[Intersection of Two Arrays II](./Algorithms/350.intersection-of-two-arrays-ii)|44%|Easy|❤️|
+|352|[Data Stream as Disjoint Intervals](./Algorithms/352.data-stream-as-disjoint-intervals)|41%|Hard||
+|354|[Russian Doll Envelopes](./Algorithms/354.russian-doll-envelopes)|32%|Hard|❤️|
+|355|[Design Twitter](./Algorithms/355.design-twitter)|25%|Medium|❤️|
+|357|[Count Numbers with Unique Digits](./Algorithms/357.count-numbers-with-unique-digits)|46%|Medium|❤️|
+|363|[Max Sum of Rectangle No Larger Than K](./Algorithms/363.max-sum-of-rectangle-no-larger-than-k)|33%|Hard|❤️|
+|365|[Water and Jug Problem](./Algorithms/365.water-and-jug-problem)|28%|Medium|❤️|
+|367|[Valid Perfect Square](./Algorithms/367.valid-perfect-square)|38%|Easy||
+|368|[Largest Divisible Subset](./Algorithms/368.largest-divisible-subset)|33%|Medium|❤️|
+|371|[Sum of Two Integers](./Algorithms/371.sum-of-two-integers)|50%|Easy|❤️|
+|372|[Super Pow](./Algorithms/372.super-pow)|34%|Medium||
+|373|[Find K Pairs with Smallest Sums](./Algorithms/373.find-k-pairs-with-smallest-sums)|31%|Medium|❤️|
+|375|[Guess Number Higher or Lower II](./Algorithms/375.guess-number-higher-or-lower-ii)|36%|Medium||
+|376|[Wiggle Subsequence](./Algorithms/376.wiggle-subsequence)|36%|Medium|❤️|
+|377|[Combination Sum IV](./Algorithms/377.combination-sum-iv)|42%|Medium||
+|378|[Kth Smallest Element in a Sorted Matrix](./Algorithms/378.kth-smallest-element-in-a-sorted-matrix)|45%|Medium|❤️|
+|380|[Insert Delete GetRandom O(1)](./Algorithms/380.insert-delete-getrandom-o1)|39%|Medium|❤️|
+|381|[Insert Delete GetRandom O(1) - Duplicates allowed](./Algorithms/381.insert-delete-getrandom-o1-duplicates-allowed)|29%|Hard|❤️|
+|382|[Linked List Random Node](./Algorithms/382.linked-list-random-node)|47%|Medium||
+|383|[Ransom Note](./Algorithms/383.ransom-note)|47%|Easy||
+|384|[Shuffle an Array](./Algorithms/384.shuffle-an-array)|47%|Medium|❤️|
+|385|[Mini Parser](./Algorithms/385.mini-parser)|30%|Medium|❤️|
+|387|[First Unique Character in a String](./Algorithms/387.first-unique-character-in-a-string)|47%|Easy||
+|388|[Longest Absolute File Path](./Algorithms/388.longest-absolute-file-path)|37%|Medium||
+|389|[Find the Difference](./Algorithms/389.find-the-difference)|51%|Easy||
+|390|[Elimination Game](./Algorithms/390.elimination-game)|42%|Medium|❤️|
+|391|[Perfect Rectangle](./Algorithms/391.perfect-rectangle)|27%|Hard||
+|392|[Is Subsequence](./Algorithms/392.is-subsequence)|44%|Medium|❤️|
+|393|[UTF-8 Validation](./Algorithms/393.utf-8-validation)|34%|Medium|❤️|
+|394|[Decode String](./Algorithms/394.decode-string)|42%|Medium||
+|395|[Longest Substring with At Least K Repeating Characters](./Algorithms/395.longest-substring-with-at-least-k-repeating-characters)|35%|Medium||
+|396|[Rotate Function](./Algorithms/396.rotate-function)|33%|Medium|❤️|
+|397|[Integer Replacement](./Algorithms/397.integer-replacement)|30%|Medium|❤️|
+|398|[Random Pick Index](./Algorithms/398.random-pick-index)|44%|Medium||
+|399|[Evaluate Division](./Algorithms/399.evaluate-division)|42%|Medium|❤️|
+|400|[Nth Digit](./Algorithms/400.nth-digit)|30%|Easy|❤️|
+|401|[Binary Watch](./Algorithms/401.binary-watch)|44%|Easy||
+|402|[Remove K Digits](./Algorithms/402.remove-k-digits)|25%|Medium|❤️|
+|403|[Frog Jump](./Algorithms/403.frog-jump)|32%|Hard|❤️|
+|404|[Sum of Left Leaves](./Algorithms/404.sum-of-left-leaves)|47%|Easy||
+|405|[Convert a Number to Hexadecimal](./Algorithms/405.convert-a-number-to-hexadecimal)|41%|Easy||
+|406|[Queue Reconstruction by Height](./Algorithms/406.queue-reconstruction-by-height)|56%|Medium|❤️|
+|407|[Trapping Rain Water II](./Algorithms/407.trapping-rain-water-ii)|37%|Hard||
+|409|[Longest Palindrome](./Algorithms/409.longest-palindrome)|45%|Easy||
+|410|[Split Array Largest Sum](./Algorithms/410.split-array-largest-sum)|39%|Hard||
+|412|[Fizz Buzz](./Algorithms/412.Fizz-Buzz)|58%|Easy||
+|413|[Arithmetic Slices](./Algorithms/413.arithmetic-slices)|54%|Medium||
+|414|[Third Maximum Number](./Algorithms/414.third-maximum-number)|28%|Easy||
+|415|[Add Strings](./Algorithms/415.add-strings)|41%|Easy||
+|416|[Partition Equal Subset Sum](./Algorithms/416.partition-equal-subset-sum)|38%|Medium|❤️|
+|417|[Pacific Atlantic Water Flow](./Algorithms/417.pacific-atlantic-water-flow)|34%|Medium||
+|419|[Battleships in a Board](./Algorithms/419.battleships-in-a-board)|63%|Medium||
+|420|[Strong Password Checker](./Algorithms/420.strong-password-checker)|19%|Hard|❤️|
+|421|[Maximum XOR of Two Numbers in an Array](./Algorithms/421.maximum-xor-of-two-numbers-in-an-array)|47%|Medium|❤️|
+|423|[Reconstruct Original Digits from English](./Algorithms/423.reconstruct-original-digits-from-english)|44%|Medium||
+|424|[Longest Repeating Character Replacement](./Algorithms/424.longest-repeating-character-replacement)|42%|Medium|❤️|
+|432|[All O`one Data Structure](./Algorithms/432.all-oone-data-structure)|27%|Hard|❤️|
+|434|[Number of Segments in a String](./Algorithms/434.number-of-segments-in-a-string)|36%|Easy||
+|435|[Non-overlapping Intervals](./Algorithms/435.non-overlapping-intervals)|41%|Medium|❤️|
+|436|[Find Right Interval](./Algorithms/436.find-right-interval)|41%|Medium||
+|437|[Path Sum III](./Algorithms/437.path-sum-iii)|40%|Easy|❤️|
+|438|[Find All Anagrams in a String](./Algorithms/438.find-all-anagrams-in-a-string)|33%|Easy||
+|440|[K-th Smallest in Lexicographical Order](./Algorithms/440.k-th-smallest-in-lexicographical-order)|25%|Hard|❤️|
+|441|[Arranging Coins](./Algorithms/441.arranging-coins)|36%|Easy||
+|442|[Find All Duplicates in an Array](./Algorithms/442.find-all-duplicates-in-an-array)|56%|Medium||
+|443|[String Compression](./Algorithms/443.string-compression)|35%|Easy|❤️|
+|445|[Add Two Numbers II](./Algorithms/445.add-two-numbers-ii)|46%|Medium|❤️|
+|446|[Arithmetic Slices II - Subsequence](./Algorithms/446.arithmetic-slices-ii-subsequence)|28%|Hard|❤️|
+|447|[Number of Boomerangs](./Algorithms/447.number-of-boomerangs)|46%|Easy||
+|448|[Find All Numbers Disappeared in an Array](./Algorithms/448.find-all-numbers-disappeared-in-an-array)|51%|Easy||
+|450|[Delete Node in a BST](./Algorithms/450.delete-node-in-a-bst)|37%|Medium|❤️|
+|451|[Sort Characters By Frequency](./Algorithms/451.sort-characters-by-frequency)|51%|Medium||
+|452|[Minimum Number of Arrows to Burst Balloons](./Algorithms/452.minimum-number-of-arrows-to-burst-balloons)|44%|Medium||
+|453|[Minimum Moves to Equal Array Elements](./Algorithms/453.minimum-moves-to-equal-array-elements)|48%|Easy||
+|454|[4Sum II](./Algorithms/454.4sum-ii)|47%|Medium||
+|455|[Assign Cookies](./Algorithms/455.assign-cookies)|47%|Easy||
+|456|[132 Pattern](./Algorithms/456.132-pattern)|27%|Medium|❤️|
+|459|[Repeated Substring Pattern](./Algorithms/459.repeated-substring-pattern)|38%|Easy|❤️|
+|460|[LFU Cache](./Algorithms/460.lfu-cache)|25%|Hard||
+|461|[Hamming Distance](./Algorithms/461.hamming-distance)|69%|Easy||
+|462|[Minimum Moves to Equal Array Elements II](./Algorithms/462.minimum-moves-to-equal-array-elements-ii)|51%|Medium||
+|463|[Island Perimeter](./Algorithms/463.island-perimeter)|57%|Easy||
+|464|[Can I Win](./Algorithms/464.can-i-win)|25%|Medium|❤️|
+|466|[Count The Repetitions](./Algorithms/466.count-the-repetitions)|27%|Hard|❤️|
+|467|[Unique Substrings in Wraparound String](./Algorithms/467.unique-substrings-in-wraparound-string)|33%|Medium|❤️|
+|468|[Validate IP Address](./Algorithms/468.validate-ip-address)|20%|Medium||
+|472|[Concatenated Words](./Algorithms/472.concatenated-words)|30%|Hard||
+|473|[Matchsticks to Square](./Algorithms/473.matchsticks-to-square)|35%|Medium|❤️|
+|474|[Ones and Zeroes](./Algorithms/474.ones-and-zeroes)|38%|Medium||
+|475|[Heaters](./Algorithms/475.heaters)|29%|Easy||
+|476|[Number Complement](./Algorithms/476.number-complement)|61%|Easy||
+|477|[Total Hamming Distance](./Algorithms/477.total-hamming-distance)|47%|Medium|❤️|
+|479|[Largest Palindrome Product](./Algorithms/479.largest-palindrome-product)|25%|Easy||
+|480|[Sliding Window Median](./Algorithms/480.sliding-window-median)|30%|Hard|❤️|
+|481|[Magical String](./Algorithms/481.magical-string)|45%|Medium||
+|482|[License Key Formatting](./Algorithms/482.license-key-formatting)|39%|Easy||
+|483|[Smallest Good Base](./Algorithms/483.smallest-good-base)|33%|Hard|❤️|
+|485|[Max Consecutive Ones](./Algorithms/485.max-consecutive-ones)|53%|Easy||
+|486|[Predict the Winner](./Algorithms/486.predict-the-winner)|45%|Medium||
+|488|[Zuma Game](./Algorithms/488.zuma-game)|37%|Hard|❤️|
+|491|[Increasing Subsequences](./Algorithms/491.increasing-subsequences)|38%|Medium|❤️|
+|492|[Construct the Rectangle](./Algorithms/492.construct-the-rectangle)|48%|Easy|❤️|
+|493|[Reverse Pairs](./Algorithms/493.reverse-pairs)|20%|Hard||
+|494|[Target Sum](./Algorithms/494.target-sum)|43%|Medium|❤️|
+|495|[Teemo Attacking](./Algorithms/495.teemo-attacking)|51%|Medium||
+|496|[Next Greater Element I](./Algorithms/496.next-greater-element-i)|56%|Easy||
+|498|[Diagonal Traverse](./Algorithms/498.diagonal-traverse)|46%|Medium||
+|500|[Keyboard Row](./Algorithms/500.keyboard-row)|59%|Easy||
+|501|[Find Mode in Binary Search Tree](./Algorithms/501.find-mode-in-binary-search-tree)|37%|Easy|❤️|
+|502|[IPO](./Algorithms/502.ipo)|36%|Hard||
+|503|[Next Greater Element II](./Algorithms/503.next-greater-element-ii)|48%|Medium|❤️|
+|504|[Base 7](./Algorithms/504.base-7)|43%|Easy||
+|506|[Relative Ranks](./Algorithms/506.relative-ranks)|46%|Easy||
+|507|[Perfect Number](./Algorithms/507.perfect-number)|32%|Easy||
+|508|[Most Frequent Subtree Sum](./Algorithms/508.most-frequent-subtree-sum)|52%|Medium||
+|513|[Find Bottom Left Tree Value](./Algorithms/513.find-bottom-left-tree-value)|56%|Medium||
+|514|[Freedom Trail](./Algorithms/514.freedom-trail)|39%|Hard||
+|515|[Find Largest Value in Each Tree Row](./Algorithms/515.find-largest-value-in-each-tree-row)|55%|Medium||
+|516|[Longest Palindromic Subsequence](./Algorithms/516.longest-palindromic-subsequence)|42%|Medium|❤️|
+|517|[Super Washing Machines](./Algorithms/517.super-washing-machines)|36%|Hard|❤️|
+|520|[Detect Capital](./Algorithms/520.detect-capital)|51%|Easy||
+|521|[Longest Uncommon Subsequence I](./Algorithms/521.longest-uncommon-subsequence-i)|55%|Easy||
+|522|[Longest Uncommon Subsequence II](./Algorithms/522.longest-uncommon-subsequence-ii)|31%|Medium||
+|523|[Continuous Subarray Sum](./Algorithms/523.continuous-subarray-sum)|23%|Medium|❤️|
+|524|[Longest Word in Dictionary through Deleting](./Algorithms/524.longest-word-in-dictionary-through-deleting)|43%|Medium||
+|525|[Contiguous Array](./Algorithms/525.contiguous-array)|41%|Medium|❤️|
+|526|[Beautiful Arrangement](./Algorithms/526.beautiful-arrangement)|53%|Medium|❤️|
+|529|[Minesweeper](./Algorithms/529.minesweeper)|49%|Medium||
+|530|[Minimum Absolute Difference in BST](./Algorithms/530.minimum-absolute-difference-in-bst)|47%|Easy|❤️|
+|532|[K-diff Pairs in an Array](./Algorithms/532.k-diff-pairs-in-an-array)|28%|Easy||
+|537|[Complex Number Multiplication](./Algorithms/537.complex-number-multiplication)|63%|Medium||
+|538|[Convert BST to Greater Tree](./Algorithms/538.convert-bst-to-greater-tree)|48%|Easy||
+|539|[Minimum Time Difference](./Algorithms/539.minimum-time-difference)|46%|Medium||
+|540|[Single Element in a Sorted Array](./Algorithms/540.single-element-in-a-sorted-array)|55%|Medium||
+|541|[Reverse String II](./Algorithms/541.reverse-string-ii)|43%|Easy||
+|542|[01 Matrix](./Algorithms/542.01-matrix)|33%|Medium|❤️|
+|543|[Diameter of Binary Tree](./Algorithms/543.diameter-of-binary-tree)|44%|Easy||
+|546|[Remove Boxes](./Algorithms/546.remove-boxes)|35%|Hard|❤️|
+|547|[Friend Circles](./Algorithms/547.friend-circles)|49%|Medium|❤️|
+|551|[Student Attendance Record I](./Algorithms/551.student-attendance-record-i)|44%|Easy||
+|552|[Student Attendance Record II](./Algorithms/552.student-attendance-record-ii)|31%|Hard|❤️|
+|553|[Optimal Division](./Algorithms/553.optimal-division)|55%|Medium||
+|554|[Brick Wall](./Algorithms/554.brick-wall)|46%|Medium||
+|556|[Next Greater Element III](./Algorithms/556.next-greater-element-iii)|28%|Medium||
+|557|[Reverse Words in a String III](./Algorithms/557.reverse-words-in-a-string-iii)|60%|Easy||
+|560|[Subarray Sum Equals K](./Algorithms/560.subarray-sum-equals-k)|39%|Medium|❤️|
+|561|[Array Partition I](./Algorithms/561.array-partition-i)|66%|Easy||
+|563|[Binary Tree Tilt](./Algorithms/563.binary-tree-tilt)|47%|Easy||
+|564|[Find the Closest Palindrome](./Algorithms/564.find-the-closest-palindrome)|17%|Hard||
+|565|[Array Nesting](./Algorithms/565.array-nesting)|49%|Medium||
+|566|[Reshape the Matrix](./Algorithms/566.reshape-the-matrix)|57%|Easy||
+|567|[Permutation in String](./Algorithms/567.permutation-in-string)|36%|Medium||
+|572|[Subtree of Another Tree](./Algorithms/572.subtree-of-another-tree)|40%|Easy|❤️|
+|575|[Distribute Candies](./Algorithms/575.distribute-candies)|57%|Easy||
+|576|[Out of Boundary Paths](./Algorithms/576.out-of-boundary-paths)|30%|Medium|❤️|
+|581|[Shortest Unsorted Continuous Subarray](./Algorithms/581.shortest-unsorted-continuous-subarray)|29%|Easy|❤️|
+|583|[Delete Operation for Two Strings](./Algorithms/583.delete-operation-for-two-strings)|44%|Medium|❤️|
+|587|[Erect the Fence](./Algorithms/587.erect-the-fence)|33%|Hard|❤️|
+|591|[Tag Validator](./Algorithms/591.tag-validator)|31%|Hard|❤️|
+|592|[Fraction Addition and Subtraction](./Algorithms/592.fraction-addition-and-subtraction)|46%|Medium||
+|593|[Valid Square](./Algorithms/593.valid-square)|39%|Medium||
+|594|[Longest Harmonious Subsequence](./Algorithms/594.longest-harmonious-subsequence)|40%|Easy||
+|598|[Range Addition II](./Algorithms/598.range-addition-ii)|48%|Easy||
+|599|[Minimum Index Sum of Two Lists](./Algorithms/599.minimum-index-sum-of-two-lists)|46%|Easy||
+|600|[Non-negative Integers without Consecutive Ones](./Algorithms/600.non-negative-integers-without-consecutive-ones)|31%|Hard|❤️|
+|605|[Can Place Flowers](./Algorithms/605.can-place-flowers)|30%|Easy|❤️|
+|606|[Construct String from Binary Tree](./Algorithms/606.construct-string-from-binary-tree)|49%|Easy||
+|609|[Find Duplicate File in System](./Algorithms/609.find-duplicate-file-in-system)|52%|Medium||
+|611|[Valid Triangle Number](./Algorithms/611.valid-triangle-number)|42%|Medium|❤️|
+|617|[Merge Two Binary Trees](./Algorithms/617.merge-two-binary-trees)|67%|Easy||
+|621|[Task Scheduler](./Algorithms/621.task-scheduler)|42%|Medium|❤️|
+|623|[Add One Row to Tree](./Algorithms/623.add-one-row-to-tree)|46%|Medium||
+|628|[Maximum Product of Three Numbers](./Algorithms/628.maximum-product-of-three-numbers)|44%|Easy|❤️|
+|629|[K Inverse Pairs Array](./Algorithms/629.k-inverse-pairs-array)|27%|Hard||
+|630|[Course Schedule III](./Algorithms/630.course-schedule-iii)|29%|Hard|❤️|
+|632|[Smallest Range](./Algorithms/632.smallest-range)|41%|Hard||
+|633|[Sum of Square Numbers](./Algorithms/633.sum-of-square-numbers)|32%|Easy||
+|636|[Exclusive Time of Functions](./Algorithms/636.exclusive-time-of-functions)|44%|Medium|❤️|
+|637|[Average of Levels in Binary Tree](./Algorithms/637.average-of-levels-in-binary-tree)|55%|Easy||
+|638|[Shopping Offers](./Algorithms/638.shopping-offers)|45%|Medium|❤️|
+|639|[Decode Ways II](./Algorithms/639.decode-ways-ii)|24%|Hard||
+|640|[Solve the Equation](./Algorithms/640.solve-the-equation)|38%|Medium||
+|643|[Maximum Average Subarray I](./Algorithms/643.maximum-average-subarray-i)|37%|Easy||
+|645|[Set Mismatch](./Algorithms/645.set-mismatch)|39%|Easy|❤️|
+|646|[Maximum Length of Pair Chain](./Algorithms/646.maximum-length-of-pair-chain)|47%|Medium||
+|647|[Palindromic Substrings](./Algorithms/647.palindromic-substrings)|54%|Medium|❤️|
+|648|[Replace Words](./Algorithms/648.replace-words)|47%|Medium||
+|649|[Dota2 Senate](./Algorithms/649.dota2-senate)|36%|Medium|❤️|
+|650|[2 Keys Keyboard](./Algorithms/650.2-keys-keyboard)|44%|Medium||
+|652|[Find Duplicate Subtrees](./Algorithms/652.find-duplicate-subtrees)|36%|Medium||
+|653|[Two Sum IV - Input is a BST](./Algorithms/653.two-sum-iv-input-is-a-bst)|49%|Easy||
+|654|[Maximum Binary Tree](./Algorithms/654.maximum-binary-tree)|69%|Medium|❤️|
+|655|[Print Binary Tree](./Algorithms/655.print-binary-tree)|49%|Medium||
+|657|[Judge Route Circle](./Algorithms/657.judge-route-circle)|68%|Easy||
+|658|[Find K Closest Elements](./Algorithms/658.find-k-closest-elements)|34%|Medium|❤️|
+|659|[Split Array into Consecutive Subsequences](./Algorithms/659.split-array-into-consecutive-subsequences)|36%|Medium|❤️|
+|661|[Image Smoother](./Algorithms/661.image-smoother)|46%|Easy||
+|662|[Maximum Width of Binary Tree](./Algorithms/662.maximum-width-of-binary-tree)|37%|Medium||
+|664|[Strange Printer](./Algorithms/664.strange-printer)|34%|Hard|❤️|
+|665|[Non-decreasing Array](./Algorithms/665.non-decreasing-array)|20%|Easy||
+|667|[Beautiful Arrangement II](./Algorithms/667.beautiful-arrangement-ii)|51%|Medium||
+|668|[Kth Smallest Number in Multiplication Table](./Algorithms/668.kth-smallest-number-in-multiplication-table)|40%|Hard||
+|669|[Trim a Binary Search Tree](./Algorithms/669.trim-a-binary-search-tree)|58%|Easy||
+|670|[Maximum Swap](./Algorithms/670.maximum-swap)|38%|Medium|❤️|
+|671|[Second Minimum Node In a Binary Tree](./Algorithms/671.second-minimum-node-in-a-binary-tree)|41%|Easy||
+|672|[Bulb Switcher II](./Algorithms/672.bulb-switcher-ii)|49%|Medium||
+|673|[Number of Longest Increasing Subsequence](./Algorithms/673.number-of-longest-increasing-subsequence)|31%|Medium|❤️|
+|674|[Longest Continuous Increasing Subsequence](./Algorithms/674.longest-continuous-increasing-subsequence)|42%|Easy||
+|675|[Cut Off Trees for Golf Event](./Algorithms/675.cut-off-trees-for-golf-event)|27%|Hard|❤️|
+|676|[Implement Magic Dictionary](./Algorithms/676.implement-magic-dictionary)|49%|Medium||
+|677|[Map Sum Pairs](./Algorithms/677.map-sum-pairs)|51%|Medium|❤️|
+|678|[Valid Parenthesis String](./Algorithms/678.valid-parenthesis-string)|29%|Medium|❤️|
+|679|[24 Game](./Algorithms/679.24-game)|38%|Hard|❤️|
+|680|[Valid Palindrome II](./Algorithms/680.valid-palindrome-ii)|32%|Easy||
+|682|[Baseball Game](./Algorithms/682.baseball-game)|58%|Easy||
+|684|[Redundant Connection](./Algorithms/684.redundant-connection)|43%|Medium||
+|685|[Redundant Connection II](./Algorithms/685.redundant-connection-ii)|27%|Hard|❤️|
+|686|[Repeated String Match](./Algorithms/686.repeated-string-match)|32%|Easy|❤️|
+|687|[Longest Univalue Path](./Algorithms/687.longest-univalue-path)|32%|Easy||
+|688|[Knight Probability in Chessboard](./Algorithms/688.knight-probability-in-chessboard)|39%|Medium||
+|689|[Maximum Sum of 3 Non-Overlapping Subarrays](./Algorithms/689.maximum-sum-of-3-non-overlapping-subarrays)|41%|Hard||
+|691|[Stickers to Spell Word](./Algorithms/691.stickers-to-spell-word)|34%|Hard|❤️|
+|692|[Top K Frequent Words](./Algorithms/692.top-k-frequent-words)|41%|Medium||
+|693|[Binary Number with Alternating Bits](./Algorithms/693.binary-number-with-alternating-bits)|55%|Easy||
+|695|[Max Area of Island](./Algorithms/695.max-area-of-island)|51%|Easy|❤️|
+|696|[Count Binary Substrings](./Algorithms/696.count-binary-substrings)|50%|Easy||
+|697|[Degree of an Array](./Algorithms/697.degree-of-an-array)|46%|Easy||
+|698|[Partition to K Equal Sum Subsets](./Algorithms/698.partition-to-k-equal-sum-subsets)|37%|Medium|❤️|
+|699|[Falling Squares](./Algorithms/699.falling-squares)|37%|Hard||
+|712|[Minimum ASCII Delete Sum for Two Strings](./Algorithms/712.minimum-ascii-delete-sum-for-two-strings)|51%|Medium|❤️|
+|713|[Subarray Product Less Than K](./Algorithms/713.subarray-product-less-than-k)|33%|Medium|❤️|
+|714|[Best Time to Buy and Sell Stock with Transaction Fee](./Algorithms/714.best-time-to-buy-and-sell-stock-with-transaction-fee)|45%|Medium|❤️|
+|715|[Range Module](./Algorithms/715.range-module)|31%|Hard||
+|717|[1-bit and 2-bit Characters](./Algorithms/717.1-bit-and-2-bit-characters)|49%|Easy||
+|718|[Maximum Length of Repeated Subarray](./Algorithms/718.maximum-length-of-repeated-subarray)|41%|Medium|❤️|
+|719|[Find K-th Smallest Pair Distance](./Algorithms/719.find-k-th-smallest-pair-distance)|27%|Hard|❤️|
+|720|[Longest Word in Dictionary](./Algorithms/720.longest-word-in-dictionary)|41%|Easy||
+|721|[Accounts Merge](./Algorithms/721.accounts-merge)|32%|Medium|❤️|
+|722|[Remove Comments](./Algorithms/722.remove-comments)|27%|Medium|❤️|
+|724|[Find Pivot Index](./Algorithms/724.find-pivot-index)|39%|Easy||
+|725|[Split Linked List in Parts](./Algorithms/725.split-linked-list-in-parts)|47%|Medium||
+|726|[Number of Atoms](./Algorithms/726.number-of-atoms)|43%|Hard|❤️|
+|728|[Self Dividing Numbers](./Algorithms/728.self-dividing-numbers)|66%|Easy||
+|729|[My Calendar I](./Algorithms/729.my-calendar-i)|42%|Medium||
+|730|[Count Different Palindromic Subsequences](./Algorithms/730.count-different-palindromic-subsequences)|34%|Hard|❤️|
+|731|[My Calendar II](./Algorithms/731.my-calendar-ii)|37%|Medium|❤️|
+|732|[My Calendar III](./Algorithms/732.my-calendar-iii)|50%|Hard||
+|733|[Flood Fill](./Algorithms/733.flood-fill)|47%|Easy||
+|735|[Asteroid Collision](./Algorithms/735.asteroid-collision)|37%|Medium||
+|736|[Parse Lisp Expression](./Algorithms/736.parse-lisp-expression)|42%|Hard|❤️|
+|738|[Monotone Increasing Digits](./Algorithms/738.monotone-increasing-digits)|40%|Medium||
+|739|[Daily Temperatures](./Algorithms/739.daily-temperatures)|52%|Medium|❤️|
+|740|[Delete and Earn](./Algorithms/740.delete-and-earn)|43%|Medium|❤️|
+|741|[Cherry Pickup](./Algorithms/741.cherry-pickup)|23%|Hard||
+|743|[Network Delay Time](./Algorithms/743.network-delay-time)|34%|Medium||
+|744|[Find Smallest Letter Greater Than Target](./Algorithms/744.find-smallest-letter-greater-than-target)|44%|Easy||
+|745|[Prefix and Suffix Search](./Algorithms/745.prefix-and-suffix-search)|25%|Hard||
+|746|[Min Cost Climbing Stairs](./Algorithms/746.min-cost-climbing-stairs)|43%|Easy||
+|747|[Largest Number At Least Twice of Others](./Algorithms/747.largest-number-at-least-twice-of-others)|41%|Easy||
+|748|[Shortest Completing Word](./Algorithms/748.shortest-completing-word)|51%|Medium||
+|749|[Contain Virus](./Algorithms/749.contain-virus)|39%|Hard||
+|752|[Open the Lock](./Algorithms/752.open-the-lock)|38%|Medium|❤️|
+|753|[Cracking the Safe](./Algorithms/753.cracking-the-safe)|39%|Hard|❤️|
+|754|[Reach a Number](./Algorithms/754.reach-a-number)|26%|Medium|❤️|
+|756|[Pyramid Transition Matrix](./Algorithms/756.pyramid-transition-matrix)|45%|Medium|❤️|
+|757|[Set Intersection Size At Least Two](./Algorithms/757.set-intersection-size-at-least-two)|34%|Hard||
+|761|[Special Binary String](./Algorithms/761.special-binary-string)|41%|Hard||
+|762|[Prime Number of Set Bits in Binary Representation](./Algorithms/762.prime-number-of-set-bits-in-binary-representation)|55%|Easy||
+|763|[Partition Labels](./Algorithms/763.partition-labels)|64%|Medium||
+|764|[Largest Plus Sign](./Algorithms/764.largest-plus-sign)|37%|Medium||
+|765|[Couples Holding Hands](./Algorithms/765.couples-holding-hands)|48%|Hard||
+|766|[Toeplitz Matrix](./Algorithms/766.toeplitz-matrix)|57%|Easy||
+|767|[Reorganize String](./Algorithms/767.reorganize-string)|35%|Medium||
+|768|[Max Chunks To Make Sorted II](./Algorithms/768.max-chunks-to-make-sorted-ii)|42%|Hard||
+|769|[Max Chunks To Make Sorted](./Algorithms/769.max-chunks-to-make-sorted)|47%|Medium||
+|770|[Basic Calculator IV](./Algorithms/770.basic-calculator-iv)|43%|Hard|❤️|
+|771|[Jewels and Stones](./Algorithms/771.jewels-and-stones)|82%|Easy||
+|773|[Sliding Puzzle](./Algorithms/773.sliding-puzzle)|47%|Hard||
+|775|[Global and Local Inversions](./Algorithms/775.global-and-local-inversions)|31%|Medium||
+|777|[Swap Adjacent in LR String](./Algorithms/777.swap-adjacent-in-lr-string)|27%|Medium||
+|778|[Swim in Rising Water](./Algorithms/778.swim-in-rising-water)|44%|Hard||
+|779|[K-th Symbol in Grammar](./Algorithms/779.k-th-symbol-in-grammar)|35%|Medium||
+|780|[Reaching Points](./Algorithms/780.reaching-points)|21%|Hard||
+|781|[Rabbits in Forest](./Algorithms/781.rabbits-in-forest)|49%|Medium||
+|782|[Transform to Chessboard](./Algorithms/782.transform-to-chessboard)|35%|Hard||
+|783|[Minimum Distance Between BST Nodes](./Algorithms/783.minimum-distance-between-bst-nodes)|47%|Easy||
+|784|[Letter Case Permutation](./Algorithms/784.letter-case-permutation)|52%|Easy|❤️|
+|785|[Is Graph Bipartite?](./Algorithms/785.is-graph-bipartite)|38%|Medium|❤️|
+|786|[K-th Smallest Prime Fraction](./Algorithms/786.k-th-smallest-prime-fraction)|29%|Hard|❤️|
+|787|[Cheapest Flights Within K Stops](./Algorithms/787.cheapest-flights-within-k-stops)|30%|Medium|❤️|
+|788|[Rotated Digits](./Algorithms/788.rotated-digits)|50%|Easy||
+|789|[Escape The Ghosts](./Algorithms/789.escape-the-ghosts)|47%|Medium||
+|790|[Domino and Tromino Tiling](./Algorithms/790.domino-and-tromino-tiling)|32%|Medium|❤️|
+|791|[Custom Sort String](./Algorithms/791.custom-sort-string)|60%|Medium||
+|792|[Number of Matching Subsequences](./Algorithms/792.number-of-matching-subsequences)|35%|Medium|❤️|
+|793| * Preimage Size of Factorial Zeroes Function|45%|Hard||
+|794| * Valid Tic-Tac-Toe State|27%|Medium||
+|795| * Number of Subarrays with Bounded Maximum|40%|Medium||
+|796| * Rotate String|54%|Easy||
+|797| * All Paths From Source to Target|69%|Medium||
+|798| * Smallest Rotation with Highest Score|31%|Hard||
+|799| * Champagne Tower|28%|Medium||
+|801| * Minimum Swaps To Make Sequences Increasing|23%|Medium||
+|802| * Find Eventual Safe States|35%|Medium||
+|803| * Bricks Falling When Hit|20%|Hard||
+|804| * Unique Morse Code Words|76%|Easy||
+|805| * Split Array With Same Average|19%|Hard||
+|806| * Number of Lines To Write String|64%|Easy||
+|807| * Max Increase to Keep City Skyline|82%|Medium||
+|808| * Soup Servings|30%|Medium||
+|809| * Expressive Words|34%|Medium||
+|810| * Chalkboard XOR Game|35%|Hard||
+|811| * Subdomain Visit Count|65%|Easy||
+|812| * Largest Triangle Area :new: |51%|Easy||
+|813| * Largest Sum of Averages :new: |37%|Medium||
+|814| * Binary Tree Pruning :new: |73%|Medium||
+|815| * Bus Routes :new: |30%|Hard||
+
+
+------------------------------------------------------------------
+
+以下免费的算法题,暂时不能使用 Go 解答
+
+- [116.Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/)
+- [117.Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/)
+- [133.Clone Graph](https://leetcode.com/problems/clone-graph/)
+- [138.Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/)
+- [141.Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)
+- [142.Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/)
+- [151.Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/)
+- [160.Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/)
+- [173.Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/)
+- [190.Reverse Bits](https://leetcode.com/problems/reverse-bits/)
+- [191.Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/)
+- [222.Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes/)
+- [235.Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/)
+- [236.Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/)
+- [237.Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/)
+- [278.First Bad Version](https://leetcode.com/problems/first-bad-version/)
+- [284.Peeking Iterator](https://leetcode.com/problems/peeking-iterator/)
+- [297.Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/)
+- [341.Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator/)
+- [374.Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/)
+- [386.Lexicographical Numbers](https://leetcode.com/problems/lexicographical-numbers/)
+- [449.Serialize and Deserialize BST](https://leetcode.com/problems/serialize-and-deserialize-bst/)
+- [535.Encode and Decode TinyURL](https://leetcode.com/problems/encode-and-decode-tinyurl/)
+- [690.Employee Importance](https://leetcode.com/problems/employee-importance/)
+
+------------------------------------------------------------------
+
+## 二.分类
+
+## Array
+
+| Title | Solution | Difficulty | Time | Space |收藏|
+| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
+|[1. Two Sum](https://leetcode.com/problems/two-sum/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0001.%20Two%20Sum)| Easy | O(n)| O(n)||
+|[11. Container With Most Water](https://leetcode.com/problems/container-with-most-water/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0011.%20Container%20With%20Most%20Water)| Medium | O(n)| O(1)||
+|[15. 3Sum](https://leetcode.com/problems/3sum)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0015.%203Sum)| Medium | O(n^2)| O(n)||
+|[16. 3Sum Closest](https://leetcode.com/problems/3sum-closest)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0016.%203Sum%20Closest)| Medium | O(n^2)| O(1)||
+|[18. 4Sum](https://leetcode.com/problems/4sum)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0018.%204Sum)| Medium | O(n^3)| O(n^2)||
+|[26. Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0026.%20Remove%20Duplicates%20from%20Sorted%20Array)| Easy | O(n)| O(1)||
+|[27. Remove Element](https://leetcode.com/problems/remove-element)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0027.%20Remove%20Element)| Easy | O(n)| O(1)||
+|[39. Combination Sum](https://leetcode.com/problems/combination-sum)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0039.%20Combination%20Sum)| Medium | O(n log n)| O(n)||
+|[40. Combination Sum II](https://leetcode.com/problems/combination-sum-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0040.%20Combination%20Sum%20II)| Medium | O(n log n)| O(n)||
+|[41. First Missing Positive](https://leetcode.com/problems/first-missing-positive)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0041.%20First-Missing-Positive)| Hard | O(n)| O(n)||
+|[42. Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0042.%20Trapping%20Rain%20Water)| Hard | O(n)| O(1)||
+|[48. Rotate Image](https://leetcode.com/problems/rotate-image)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0048.%20Rotate%20Image)| Medium | O(n)| O(1)||
+|[53. Maximum Subarray](https://leetcode.com/problems/maximum-subarray)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0053.%20Maximum%20Subarray)| Easy | O(n)| O(n)||
+|[54. Spiral Matrix](https://leetcode.com/problems/spiral-matrix)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0054.%20Spiral%20Matrix)| Medium | O(n)| O(n^2)||
+|[56. Merge Intervals](https://leetcode.com/problems/merge-intervals)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0056.%20Merge%20Intervals)| Medium | O(n log n)| O(1)||
+|[57. Insert Interval](https://leetcode.com/problems/insert-interval)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0057.%20Insert%20Interval)| Hard | O(n)| O(1)||
+|[59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0059.%20Spiral%20Matrix%20II)| Medium | O(n)| O(n^2)||
+|[62. Unique Paths](https://leetcode.com/problems/unique-paths)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0062.%20Unique%20Paths)| Medium | O(n^2)| O(n^2)||
+|[63. Unique Paths II](https://leetcode.com/problems/unique-paths-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0063.%20Unique%20Paths%20II)| Medium | O(n^2)| O(n^2)||
+|[64. Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0064.%20Minimum%20Path%20Sum)| Medium | O(n^2)| O(n^2)||
+|[75. Sort Colors](https://leetcode.com/problems/sort-colors)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0075.%20Sort%20Colors)| Medium | O(n)| O(1)||
+|[78. Subsets](https://leetcode.com/problems/subsets)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0078.%20Subsets)| Medium | O(n^2)| O(n)||
+|[79. Word Search](https://leetcode.com/problems/word-search)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0079.%20Word%20Search)| Medium | O(n^2)| O(n^2)||
+|[80. Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0080.%20Remove%20Duplicates%20from%20Sorted%20Array%20II)| Medium | O(n^2)| O(n^2)||
+|[84. Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0084.%20Largest%20Rectangle%20in%20Histogram)| Medium | O(n)| O(n)||
+|[88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0088.%20Merge-Sorted-Array)| Easy | O(n)| O(1)||
+|[90. Subsets II](https://leetcode.com/problems/subsets-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0090.%20Subsets%20II)| Medium | O(n^2)| O(n)||
+|[120. Triangle](https://leetcode.com/problems/triangle)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0120.%20Triangle)| Medium | O(n^2)| O(n)||
+|[121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0121.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock)| Easy | O(n)| O(1)||
+|[122. Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0122.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II)| Easy | O(n)| O(1)||
+|[126. Word Ladder II](https://leetcode.com/problems/word-ladder-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0126.%20Word%20Ladder%20II)| Hard | O(n)| O(n^2)||
+|[152. Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0152.%20Maximum%20Product%20Subarray)| Medium | O(n)| O(1)||
+|[167. Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0167.%20Two%20Sum%20II%20-%20Input%20array%20is%20sorted)| Easy | O(n)| O(1)||
+|[209. Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0209.%20Minimum%20Size%20Subarray%20Sum)| Medium | O(n)| O(1)||
+|[216. Combination Sum III](https://leetcode.com/problems/combination-sum-iii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0216.%20Combination%20Sum%20III)| Medium | O(n)| O(1)||
+|[217. Contains Duplicate](https://leetcode.com/problems/contains-duplicate)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0217.%20Contains%20Duplicate)| Easy | O(n)| O(n)||
+|[219. Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0219.%20Contains%20Duplicate%20II)| Easy | O(n)| O(n)||
+|[283. Move Zeroes](https://leetcode.com/problems/move-zeroes)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0283.%20Move%20Zeroes)| Easy | O(n)| O(1)||
+|[287. Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0287.%20Find%20the%20Duplicate%20Number)| Easy | O(n)| O(1)||
+|[532. K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0532.%20K-diff%20Pairs%20in%20an%20Array)| Easy | O(n)| O(n)||
+|[566. Reshape the Matrix](https://leetcode.com/problems/reshape-the-matrix)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0566.%20Reshape%20the%20Matrix)| Easy | O(n^2)| O(n^2)||
+|[628. Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0628.%20Maximum%20Product%20of%20Three%20Numbers)| Easy | O(n)| O(1)||
+|[713. Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0713.%20Subarray%20Product%20Less%20Than%20K)| Medium | O(n)| O(1)||
+|[714. Best Time to Buy and Sell Stock with Transaction Fee](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0714.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee)| Medium | O(n)| O(1)||
+|[746. Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0746.%20Min%20Cost%20Climbing%20Stairs)| Easy | O(n)| O(1)||
+|[766. Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0766.%20Toeplitz%20Matrix)| Easy | O(n)| O(1)||
+|[867. Transpose Matrix](https://leetcode.com/problems/transpose-matrix)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0867.%20Transpose%20Matrix)| Easy | O(n)| O(1)||
+|[891. Sum of Subsequence Widths](https://leetcode.com/problems/sum-of-subsequence-widths)| [Go]()| Hard | O(n)| O(1)||
+|[907. Sum of Subarray Minimums](https://leetcode.com/problems/sum-of-subarray-minimums)| [Go]()| Medium | O(n)| O(1)||
+|[922. Sort Array By Parity II](https://leetcode.com/problems/sum-of-subarray-minimums)| [Go]()| Medium | O(n)| O(1)||
+|[969. Pancake Sorting](https://leetcode.com/problems/pancake-sorting)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0969.%20Pancake%20Sorting)| Medium | O(n)| O(1)||
+|[977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0977.%20Squares%20of%20a%20Sorted%20Array)| Easy | O(n)| O(1)||
+
+
+
+
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/)| [Go](./Array/MaxConsecutiveOnes.Go)| Easy| O(n)| O(1)|
+[Heaters](https://leetcode.com/problems/heaters/)| [Go](./Array/Heaters.Go)| Easy| O(nlogn)| O(1)|
+[Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs/)| [Go](./Array/NumberBoomerangs.Go)| Easy| O(n ^ 2)| O(n)|
+[Island Perimeter](https://leetcode.com/problems/island-perimeter/)| [Go](./Array/IslandPerimeter.Go)| Easy| O(nm)| O(1)|
+[Majority Element](https://leetcode.com/problems/majority-element/)| [Go](./Array/MajorityElement.Go)| Easy| O(n)| O(1)|
+[Majority Element II](https://leetcode.com/problems/majority-element-ii/)| [Go](./Array/MajorityElementII.Go)| Medium| O(n)| O(1)|
+[Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/)| [Go](./Array/IntersectionTwoArrays.Go)| Easy| O(n)| O(n)|
+[Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/)| [Go](./Array/IntersectionTwoArraysII.Go)| Easy| O(n)| O(n)|
+[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)| [Go](./Array/ContainsDuplicate.Go)| Easy| O(n)| O(n)|
+[Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/)| [Go](./Array/ContainsDuplicateII.Go)| Easy| O(n)| O(n)|
+[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [Go](./Array/RemoveDuplicatesFromSortedArray.Go)| Easy| O(n)| O(1)|
+[Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/)| [Go](./Array/RemoveDuplicatesFromSortedArrayII.Go)| Medium| O(n)| O(1)|
+[Move Zeroes](https://leetcode.com/problems/move-zeroes/)| [Go](./Array/MoveZeroes.Go)| Easy| O(n)| O(1)|
+[Remove Element](https://leetcode.com/problems/remove-element/)| [Go](./Array/RemoveElement.Go)| Easy| O(n)| O(1)|
+[Two Sum](https://leetcode.com/problems/two-sum/)| [Go](./Array/TwoSum.Go)| Easy| O(n)| O(n)|
+[3Sum](https://leetcode.com/problems/3sum/)| [Go](./Array/ThreeSum.Go)| Medium| O(n^2)| O(nC3)|
+[3Sum Closest](https://leetcode.com/problems/3sum-closest/)| [Go](./Array/ThreeSum.Go)| Medium| O(n^2)| O(nC3)|
+[4Sum](https://leetcode.com/problems/4sum/)| [Go](./Array/FourSum.Go)| Medium| O(n^3)| O(nC4)|
+[Summary Ranges](https://leetcode.com/problems/summary-ranges/)| [Go](./Array/SummaryRanges.Go)| Medium| O(n)| O(n)|
+[Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance/)| [Go](./Array/ShortestWordDistance.Go)| Easy| O(n)| O(1)|
+[Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii/)| [Go](./Array/ShortestWordDistanceIII.Go)| Medium| O(n)| O(1)|
+[Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)| [Go](./Array/MinimumSizeSubarraySum.Go)| Medium| O(n)| O(1)|
+[Maximum Size Subarray Sum Equals k](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/)| [Go](./Array/MaximumSizeSubarraySumEqualsK.Go)| Medium| O(n)| O(n)|
+[Smallest Range](https://leetcode.com/problems/smallest-range/)| [Go](./Array/SmallestRange.Go)| Hard | O(nm)| O(nm)|
+[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)| [Go](./Array/ProductExceptSelf.Go)| Medium| O(n)| O(n)|
+[Rotate Array](https://leetcode.com/problems/rotate-array/)| [Go](./Array/RotateArray.Go)| Easy| O(n)| O(1)|
+[Rotate Image](https://leetcode.com/problems/rotate-image/)| [Go](./Array/RotateImage.Go)| Medium| O(n^2)| O(1)|
+[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)| [Go](./Array/SpiralMatrix.Go)| Medium| O(n^2)| O(1)|
+[Spiral Matrix II](https://leetcode.com/problems/spiral-matrix/)| [Go](./Array/SpiralMatrixII.Go)| Medium| O(n^2)| O(1)|
+[Valid Sudoku](https://leetcode.com/problems/valid-sudoku/)| [Go](./Array/ValidSudoku.Go)| Easy| O(n^2)| O(n)|
+[Set Matrix Zero](https://leetcode.com/problems/set-matrix-zeroes/)| [Go](./Array/SetMatrixZero.Go)| Medium| O(n^2)| O(1)|
+[Next Permutation](https://leetcode.com/problems/next-permutation/)| [Go](./Array/NextPermutation.Go)| Medium| O(n)| O(1)|
+[Gas Station](https://leetcode.com/problems/gas-station/)| [Go](./Array/GasStation.Go)| Medium| O(n)| O(1)|
+[Game of Life](https://leetcode.com/problems/game-of-life/)| [Go](./Array/GameLife.Go)| Medium| O(n)| O(1)|
+[Task Scheduler](https://leetcode.com/problems/task-scheduler/)| [Go](./Array/TaskScheduler.Go)| Medium| O(nlogn)| O(n)|
+[Sliding Window Maximum ](https://leetcode.com/problems/sliding-window-maximum/)| [Go](./Array/SlidingWindowMaximum.Go)| Hard| O(n)| O(n)|
+[Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/)| [Go](./Array/LongestConsecutiveSequence.Go)| Hard| O(n)| O(n)|
+
+
+## String
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Fizz Buzz](https://leetcode.com/problems/fizz-buzz/)| [Go](./String/FizzBuzz.Go)| Easy| O(n)| O(1)|
+[First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/)| [Go](./String/FirstUniqueCharacterInString.Go)| Easy| O(n)| O(1)|
+[Keyboard Row](https://leetcode.com/problems/keyboard-row/)| [Go](./String/KeyboardRow.Go)| Easy| O(nm)| O(n)|
+[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)| [Go](./String/ValidPalindrome.Go)| Easy| O(n)| O(n)|
+[Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii/)| [Go](./String/ValidPalindromeII.Go)| Easy| O(n)| O(n)|
+[Detect Capital](https://leetcode.com/problems/detect-capital/)| [Go](./String/DetectCapital.Go)| Easy| O(n)| O(1)|
+[Count and Say](https://leetcode.com/problems/count-and-say/)| [Go](./String/CountAndSay.Go)| Easy| O(n^2)| O(n)|
+[Flip Game](https://leetcode.com/problems/flip-game/)| [Go](./String/FlipGame.Go)| Easy| O(n)| O(n)|
+[Implement strStr()](https://leetcode.com/problems/implement-strstr/)| [Go](./String/StrStr.Go)| Easy| O(nm)| O(n)|
+[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)| [Go](./String/IsomorphicStrings.Go)| Easy| O(n)| O(n)|
+[Reverse String](https://leetcode.com/problems/reverse-string/)| [Go](./String/ReverseString.Go)| Easy| O(n)| O(n)|
+[Reverse String II](https://leetcode.com/problems/reverse-string-ii/)| [Go](./String/ReverseStringII.Go)| Easy| O(n)| O(n)|
+[Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/)| [Go](./String/ReverseVowelsOfAString.Go)| Easy| O(n)| O(n)|
+[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)| [Go](./String/AddStrings.Go)| Easy| O(n)| O(n)|
+[Add Strings](https://leetcode.com/problems/add-strings/)| [Go](./String/LengthLastWord.Go)| Easy| O(n)| O(1)|
+[Multiply Strings](https://leetcode.com/problems/multiply-strings/)| [Go](./String/MultiplyStrings.Go)| Medium| O(n)| O(1)|
+[Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation/)| [Go](./String/PalindromePermutation.Go)| Easy| O(n)| O(n)|
+[Valid Anagram](https://leetcode.com/problems/valid-anagram/)| [Go](./String/ValidAnagram.Go)| Easy| O(nlogn)| O(1)|
+[Ransom Note](https://leetcode.com/problems/ransom-note/)| [Go](./String/RansomNote.Go)| Easy| O(n)| O(n)|
+[Group Anagrams](https://leetcode.com/problems/anagrams/)| [Go](./String/GroupAnagrams.Go)| Medium| O(nmlogm + nlogn)| O(n)
+[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)| [Go](./String/LongestCommonPrefix.Go)| Easy| O(nm)| O(m)|
+[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [Go](./String/LongestSubstringWithoutRepeatingCharacters.Go)| Medium| O(n)| O(n)|
+[One Edit Distance](https://leetcode.com/problems/one-edit-distance/)| [Go](./String/OneEditDistance.Go)| Medium| O(n)| O(n)|
+[Word Pattern](https://leetcode.com/problems/word-pattern/)| [Go](./String/WordPattern.Go)| Easy| O(n)| O(n)|
+[Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)| [Go](./Array/MinimumWindowSubstring.Go)| Hard| O(n^2)| O(n)|
+[Text Justification](https://leetcode.com/problems/text-justification/)| [Go](./String/TextJustification.Go)| Hard| O(n)| O(n)|
+
+## Linked List (已全部做完)
+
+- 巧妙的构造虚拟头结点。可以使遍历处理逻辑更加统一。
+- 灵活使用递归。构造递归条件,使用递归可以巧妙的解题。不过需要注意有些题目不能使用递归,因为递归深度太深会导致超时和栈溢出。
+- 链表区间逆序。第 92 题。
+- 链表寻找中间节点。第 876 题。链表寻找倒数第 n 个节点。第 19 题。只需要一次遍历就可以得到答案。
+- 合并 K 个有序链表。第 21 题,第 23 题。
+- 链表归类。第 86 题,第 328 题。
+- 链表排序,时间复杂度要求 O(n * log n),空间复杂度 O(1)。只有一种做法,归并排序,至顶向下归并。第 148 题。
+- 判断链表是否存在环,如果有环,输出环的交叉点的下标;判断 2 个链表是否有交叉点,如果有交叉点,输出交叉点。第 141 题,第 142 题,第 160 题。
+
+
+
+| Title | Solution | Difficulty | Time | Space |收藏|
+| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
+|[2. Add Two Numbers](https://leetcode.com/problems/add-two-numbers)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0002.%20Add-Two-Number)| Medium | O(n)| O(1)||
+|[19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0019.%20Remove%20Nth%20Node%20From%20End%20of%20List)| Medium | O(n)| O(1)||
+|[21. Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0021.%20Merge%20Two%20Sorted%20Lists)| Easy | O(log n)| O(1)||
+|[23. Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0023.%20Merge%20k%20Sorted%20Lists)| Hard | O(log n)| O(1)|❤️|
+|[24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0024.%20Swap%20Nodes%20in%20Pairs)| Medium | O(n)| O(1)||
+|[25. Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0025.%20Reverse%20Nodes%20in%20k%20Group)| Hard | O(log n)| O(1)|❤️|
+|[61. Rotate List](https://leetcode.com/problems/rotate-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0061.%20Rotate%20List)| Medium | O(n)| O(1)||
+|[82. Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0082.%20Remove%20Duplicates%20from%20Sorted%20List%20II)| Medium | O(n)| O(1)||
+|[83. Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0083.%20Remove%20Duplicates%20from%20Sorted%20List)| Easy | O(n)| O(1)||
+|[86. Partition List](https://leetcode.com/problems/partition-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0086.%20Partition%20List)| Medium | O(n)| O(1)|❤️|
+|[92. Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0092.%20Reverse%20Linked%20List%20II)| Medium | O(n)| O(1)|❤️|
+|[109. Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0109.%20Convert%20Sorted%20List%20to%20Binary%20Search%20Tree)| Medium | O(log n)| O(n)||
+|[141. Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0141.%20Linked%20List%20Cycle)| Easy | O(n)| O(1)|❤️|
+|[142. Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0142.%20Linked%20List%20Cycle%20II)| Medium | O(n)| O(1)|❤️|
+|[143. Reorder List](https://leetcode.com/problems/reorder-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0143.%20Reorder%20List)| Medium | O(n)| O(1)|❤️|
+|[147. Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0147.%20Insertion%20Sort%20List)| Medium | O(n)| O(1)||
+|[148. Sort List](https://leetcode.com/problems/sort-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0148.%20Sort%20List)| Medium | O(log n)| O(n)|❤️|
+|[160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0160.%20Intersection%20of%20Two%20Linked%20Lists)| Easy | O(n)| O(1)|❤️|
+|[203. Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0203.%20Remove%20Linked%20List%20Elements)| Easy | O(n)| O(1)||
+|[206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0206.%20Reverse-Linked-List)| Easy | O(n)| O(1)||
+|[234. Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0234.%20Palindrome%20Linked%20List)| Easy | O(n)| O(1)||
+|[237. Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0237.%20Delete%20Node%20in%20a%20Linked%20List)| Easy | O(n)| O(1)||
+|[328. Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0328.%20Odd%20Even%20Linked%20List)| Medium | O(n)| O(1)||
+|[445. Add Two Numbers II](https://leetcode.com/problems/add-two-numbers-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0445.%20Add%20Two%20Numbers%20II)| Medium | O(n)| O(n)||
+|[725. Split Linked List in Parts](https://leetcode.com/problems/split-linked-list-in-parts/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0725.%20Split%20Linked%20List%20in%20Parts)| Medium | O(n)| O(1)||
+|[817. Linked List Components](https://leetcode.com/problems/linked-list-components/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0817.%20Linked%20List%20Components)| Medium | O(n)| O(1)||
+|[707. Design Linked List](https://leetcode.com/problems/design-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0707.%20Design%20Linked%20List)| Easy | O(n)| O(1)||
+|[876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0876.%20Middle%20of%20the%20Linked%20List)| Easy | O(n)| O(1)|❤️|
+|[1019. Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/1019.%20Next%20Greater%20Node%20In%20Linked%20List)| Medium | O(n)| O(1)||
+|----------------------------------------------------------------------------|-------------|-------------| -------------| -------------|-------------|
+
+## Stack (已全部做完)
+
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)| [Go](./Stack/ValidParentheses.Go)| Easy| O(n)| O(n)|
+[Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/)| [Go](./Stack/LongestValidParentheses.Go)| Hard| O(n)| O(n)|
+[Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/)| [Go](./Stack/EvaluateReversePolishNotation.Go)| Medium| O(n)| O(n)|
+[Simplify Path](https://leetcode.com/problems/simplify-path/)| [Go](./Stack/SimplifyPath.Go)| Medium| O(n)| O(n)|
+[Remove K Digits](https://leetcode.com/problems/remove-k-digits/)| [Go](./Stack/RemoveKDigits.Go)| Medium| O(n)| O(n)|
+[Ternary Expression Parser](https://leetcode.com/problems/ternary-expression-parser/)| [Go](./Stack/TernaryExpressionParser.Go)| Medium| O(n)| O(n)|
+[Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/)| [Go](./Stack/PreorderTraversal.Go)| Medium| O(n)| O(n)|
+[Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/)| [Go](./Stack/InorderTraversal.Go)| Medium| O(n)| O(n)|
+[Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/)| [Go](./Stack/PostorderTraversal.Go)| Hard| O(n)| O(n)|
+
+
+## Tree
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Same Tree](https://oj.leetcode.com/problems/same-tree/)| [Go](./Tree/SameTree.Go)| Easy| O(n)| O(n)|
+[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [Go](./Tree/SymmetricTree.Go)| Easy| O(n)| O(n)|
+[Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/)| [Go](./Tree/InvertBinaryTree)| Easy| O(n)| O(n)|
+[Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down/)| [Go](./Tree/BinaryTreeUpsideDown)| Medium| O(n)| O(1)|
+[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/)| [Go](./Tree/MinimumDepthOfBinaryTree.Go)| Easy| O(n)| O(1)|
+[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| [Go](./Tree/MaximumDepthOfBinaryTree.Go)| Easy| O(n)| O(1)|
+[Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/)| [Go](./Tree/DiameterBinaryTree.Go)| Easy| O(n)| O(1)|
+[Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/)| [Go](./Tree/BalancedBinaryTree.Go)| Easy| O(n)| O(n)|
+[Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/)| [Go](./Tree/SumLeftLeaves.Go)| Easy| O(n)| O(1)|
+[Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/)| [Go](./Tree/FlattenBinaryTreeLinkedList.Go)| Medium| O(n)| O(1)|
+[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)| [Go](./Tree/ValidateBinarySearchTree.Go)| Medium| O(n)| O(n)|
+[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)| [Go](./Tree/BinaryTreeLevelOrderTraversal.Go)| Easy| O(n)| O(n)|
+[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/)| [Go](./Tree/BinaryTreeLevelOrderTraversalII.Go)| Easy| O(n)| O(n)|
+[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)| [Go](./Tree/BinaryTreeZigzagLevelOrderTraversal.Go)| Medium| O(n)| O(n)|
+[Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/)| [Go](./Tree/BinaryTreeVerticalOrderTraversal.Go)| Medium| O(n)| O(n)|
+[Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/)| [Go](./Tree/BinaryTreeRightSideView.Go)| Medium| O(n)| O(n)|
+[Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/)| [Go](./Tree/ConstructBinaryTreePreorderInorder.Go)| Medium| O(n)| O(n)|
+[Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/)| [Go](./Tree/ConstructBinaryTreeInorderPostorder.Go)| Medium| O(n)| O(n)|
+[Path Sum](https://leetcode.com/problems/path-sum/)| [Go](./Tree/PathSum.Go)| Easy| O(n)| O(n)|
+[Path Sum II](https://leetcode.com/problems/path-sum-ii/)| [Go](./Tree/PathSumII.Go)| Medium| O(n)| O(n)|
+[Path Sum III](https://leetcode.com/problems/path-sum-iiI/)| [Go](./Tree/PathSumIII.Go)| Easy| O(n^2)| O(1)|
+[Bnary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)| [Go](./Tree/BnaryTreePaths.Go)| Easy| O(n)| O(n)|
+[Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees/)| [Go](./Tree/UniqueBinarySearchTrees.Go)| Medium| O(n^2)| O(n)|
+[Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/)| [Go](./Tree/RecoverBinarySearchTree.Go)| Hard| O(n)| O(1)|
+[Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees/description/) | [Go](./Tree/MergeTwoBinaryTrees.Go) | Easy | O(n) | O(n) |
+
+## Dynamic programming
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum/)| [Go](./DP/NestedListWeightSum.Go)| Easy| O(n)| O(1)|
+[Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)| [Go](./DP/ClimbingStairs.Go)| Easy| O(n)| O(1)|
+[Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/)| [Go](./DP/MinCostClimbingStairs.Go)| Easy| O(n)| O(n)|
+[Unique Paths](https://leetcode.com/problems/unique-paths/)| [Go](./DP/UniquePaths.Go)| Medium| O(mn)| O(mn)|
+[Unique Paths II](https://leetcode.com/problems/unique-paths-ii/)| [Go](./DP/UniquePathsII.Go)| Medium| O(mn)| O(mn)|
+[Decode Ways](https://leetcode.com/problems/decode-ways/)| [Go](./DP/DecodeWays.Go) | O(n)|O(n)|
+[Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/)| [Go](./DP/MinimumPathSum.Go)| Medium| O(mn)| O(mn)|
+[Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)| [Go](./DP/GenerateParentheses.Go)| Medium| O(2^n)| O(n)|
+[Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses/)| [Go](./DP/DifferentWaysAddParentheses.Go)| Medium| O(n^n)| O(n)|
+[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)| [Go](./DP/BestTimeBuySellStock.Go)| Easy| O(n)| O(1)|
+[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/)| [Go](./DP/BestTimeBuySellStockII.Go)| Medium| O(n)| O(1)|
+[Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/)| [Go](./DP/BestTimeBuySellStockIII.Go)| Hard| O(n)| O(n)|
+[Best Time to Buy and Sell Stock IV](https://leetcode.com/problems/https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/)| [Go](./DP/BestTimeBuySellStockIV.Go)| Hard| O(n^2)| O(n)|
+[Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/)| [Go](./DP/BestTimeBuySellStockCooldown.Go)| Medium| O(n^2)| O(n)|
+[Coin Change](https://leetcode.com/problems/coin-change/)| [Go](./DP/CoinChange.Go)| Medium| O(n^2)| O(n)|
+[Coin Change II](https://leetcode.com/problems/coin-change-ii/)| [Go](./DP/CoinChangeII.Go)| Medium| O(n^2)| O(n)|
+[Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)| [Go](./DP/LongestIncreasingSubsequence.Go)| Medium| O(n^2)| O(n)|
+[Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)| [Go](./DP/LongestPalindromicSubstring.Go)| Medium| O(n^2)| O(n^2)|
+[Perfect Squares](https://leetcode.com/problems/perfect-squares/)| [Go](./DP/PerfectSquares.Go)| Medium| O(n^2)| O(n)|
+[House Robber](https://leetcode.com/problems/house-robber/)| [Go](./DP/HouseRobber.Go)| Easy| O(n)| O(1)|
+[House Robber II](https://leetcode.com/problems/house-robber-ii/)| [Go](./DP/HouseRobberII.Go)| Medium| O(n)| O(1)|
+[Paint Fence](https://leetcode.com/problems/paint-fence/)| [Go](./DP/PaintFence.Go)| Easy| O(n)| O(n)|
+[Maximum Subarray](https://leetcode.com/problems/maximum-subarray/)| [Go](./DP/MaximumSubarray.Go)| Medium| O(n)| O(1)|
+[Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)| [Go](./DP/MaximumProductSubarray.Go)| Medium| O(n)| O(1)|
+[Maximal Square](https://leetcode.com/problems/maximal-square/)| [Go](./DP/MaximalSquare.Go)| Medium| O(mn)| O(mn)|
+[Edit Distance](https://leetcode.com/problems/edit-distance/)| [Go](./DP/EditDistance.Go)| Hard| O(mn)| O(mn)|
+[Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/)| [Go](./DP/CombinationSumIV.Go)| Medium| O(2^n)| O(n)|
+[Triangle](https://leetcode.com/problems/triangle/)| [Go](./DP/Triangle.Go)| Medium| O(2^n - 1)| O(m)|
+[Guess Number Higher or Lower II](https://leetcode.com/problems/guess-number-higher-or-lower-ii/)| [Go](./DP/GuessNumberHigherOrLowerII.Go)| Medium| O(nlogn)| O(n^2)|
+[Burst Ballons](https://leetcode.com/problems/burst-balloons/)| [Go](./DP/BurstBalloons.Go)| Hard| O(n^3)| O(n)|
+[Frog Jump](https://leetcode.com/problems/frog-jump/)| [Go](./DP/FrogJump.Go)| Hard| O(n^2)| O(n)|
+
+## Depth-first search
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Permutations](https://leetcode.com/problems/permutations/)| [Go](./DFS/Permutations.Go)| Medium| O(n!)| O(n)|
+[Permutations II](https://leetcode.com/problems/permutations-ii/)| [Go](./DFS/PermutationsII.Go)| Medium| O(n!)| O(n)|
+[Subsets](https://leetcode.com/problems/subsets/)| [Go](./DFS/Subsets.Go)| Medium| O(n!)| O(n)|
+[Subsets II](https://leetcode.com/problems/subsets-ii/)| [Go](./DFS/SubsetsII.Go)| Medium| O(n!)| O(n)|
+[Combinations](https://leetcode.com/problems/combinations/)| [Go](./DFS/Combinations.Go)| Medium| O(n!)| O(n)|
+[Combination Sum](https://leetcode.com/problems/combination-sum/)| [Go](./DFS/CombinationSum.Go)| Medium| O(n^n)| O(2^n - 1)|
+[Combination Sum II](https://leetcode.com/problems/combination-sum-ii/)| [Go](./DFS/CombinationSumII.Go)| Medium| O(n!)| O(2^n - 2)|
+[Combination Sum III](https://leetcode.com/problems/combination-sum-iii/)| [Go](./DFS/CombinationSumIII.Go)| Medium| O(n!)| O(nCk)|
+[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [Go](./DFS/LetterCombinationsPhoneNumber.Go)| Medium| O(mn)| O(n)|
+[Factor Combinations](https://leetcode.com/problems/factor-combinations/)| [Go](./DFS/FactorCombinations.Go)| Medium| O(n^n))| O(2^n - 1)|
+[Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation/)| [Go](./DFS/GeneralizedAbbreviation.Go)| Medium| O(n!)| O(2^n)|
+[Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning/)| [Go](./DFS/PalindromePartitioning.Go)| Medium| O(n!)| O(n)|
+[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Go](./DFS/NumberofIslands.Go)| Medium| O((mn)^2)| O(1)|
+[Walls and Gates](https://leetcode.com/problems/walls-and-gates/)| [Go](./DFS/WallsGates.Go)| Medium| O(n!)| O(2^n)|
+[Word Search](https://leetcode.com/problems/word-search/)| [Go](./DFS/WordSearch.Go)| Medium| O((n^2)!)| O(n^2)|
+[Word Search II](https://leetcode.com/problems/word-search-ii/)| [Go](./DFS/WordSearchII.Go)| Hard| O(((mn)^2))| O(n^2)|
+[Add and Search Word - Data structure design](https://leetcode.com/problems/add-and-search-word-data-structure-design/)| [Go](./DFS/WordDictionary.Go)| Medium| O(n)| O(n)|
+[N-Queens](https://leetcode.com/problems/n-queens/)| [Go](./DFS/NQueens.Go)| Hard| O((n^4))| O(n^2)|
+[N-Queens II](https://leetcode.com/problems/n-queens-ii/)| [Go](./DFS/NQueensII.Go)| Hard| O((n^3))| O(n)|
+[Sudoku Solver](https://leetcode.com/problems/sudoku-solver/)| [Go](./DFS/SudokuSolver.Go)| Hard| O(n^4)| O(1)|
+[Remove Invalid Parentheses](https://leetcode.com/problems/remove-invalid-parentheses/)| [Go](./DFS/RemoveInvalidParentheses.Go)| Hard| O(n!)| O(n)|
+[Expression Add Operators](https://leetcode.com/problems/expression-add-operators/)| [Go](./DFS/ExpressionAddOperators.Go)| Hard| O(n!)| O(n)|
+
+## Math
+
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Add Binary](https://leetcode.com/problems/add-binary/)| [Go](./Math/AddBinary.Go)| Easy| O(n)| O(n)|
+[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)| [Go](./Math/AddTwoNumbers.Go)| Medium| O(n)| O(1)|
+[Add Digits](https://leetcode.com/problems/add-digits/)| [Go](./Math/AddDigits.Go)| Easy| O(1)| O(1)|
+[Plus One](https://leetcode.com/problems/plus-one/)| [Go](./Math/PlusOne.Go)| Easy| O(n)| O(1)|
+[Divide Two Integers](https://leetcode.com/problems/divide-two-integers/)| [Go](./Math/DivideTwoIntegers.Go)| Medium| O(logn)| O(1)|
+[Number Complement](https://leetcode.com/problems/number-complement/)| [Go](./Math/NumberComplement.Go)| Easy| O(n)| O(1)|
+[Hamming Distance](https://leetcode.com/problems/hamming-distance/)| [Go](./Math/HammingDistance.Go)| Easy| O(n)| O(1)|
+[Integer Break](https://leetcode.com/problems/integer-break/)| [Go](./Math/IntegerBreak.Go)| Medium| O(logn)| O(1)|
+[Happy Number](https://leetcode.com/problems/happy-number/)| [Go](./Math/HappyNumber.Go)| Easy| O(n)| O(n)|
+[Single Number](https://leetcode.com/problems/single-number/)| [Go](./Math/SingleNumber.Go)| Medium| O(n)| O(1)|
+[Ugly Number](https://leetcode.com/problems/ugly-number/)| [Go](./Math/UglyNumber.Go)| Easy| O(logn)| O(1)|
+[Ugly Number II](https://leetcode.com/problems/ugly-number-ii/)| [Go](./Math/UglyNumberII.Go)| Medium| O(n)| O(n)|
+[Super Ugly Number](https://leetcode.com/problems/super-ugly-number/)| [Go](./Math/SuperUglyNumber.Go)| Medium| O(n^2)| O(n)|
+[Count Primes](https://leetcode.com/problems/count-primes/)| [Go](./Math/CountPrimes.Go)| Easy| O(n)| O(n)|
+[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)| [Go](./Math/Atoi.Go)| Easy| O(n)| O(1)|
+[Pow(x, n)](https://leetcode.com/problems/isomorphic-strings/)| [Go](./Math/Pow.Go)| Medium| O(logn)| O(1)|
+[Power of Two](https://leetcode.com/problems/power-of-two/)| [Go](./Math/PowerTwo.Go)| Easy| O(1)| O(1)|
+[Power of Three](https://leetcode.com/problems/power-of-three/)| [Go](./Math/PowerThree.Go)| Easy| O(1)| O(1)|
+[Super Power](https://leetcode.com/problems/super-pow/)| [Go](./Math/SuperPow.Go)| Medium| O(n)| O(1)|
+[Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/)| [Go](./Math/SumTwoIntegers.Go)| Easy| O(n)| O(1)|
+[Reverse Integer](https://leetcode.com/problems/reverse-integer/)| [Go](./Math/ReverseInteger.Go)| Easy| O(n)| O(1)|
+[Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/)| [Go](./Math/ExcelSheetColumnNumber.Go)| Easy| O(n)| O(1)|
+[Integer to Roman](https://leetcode.com/problems/integer-to-roman/)| [Go](./Math/IntegerToRoman.Go)| Medium| O(n)| O(1)|
+[Roman to Integer](https://leetcode.com/problems/roman-to-integer/)| [Go](./Math/RomanToInteger.Go)| Easy| O(n)| O(n)|
+[Integer to English Words](https://leetcode.com/problems/integer-to-english-words/)| [Go](./Math/IntegerEnglishWords.Go)| Hard| O(n)| O(1)|
+[Rectangle Area](https://leetcode.com/problems/rectangle-area/)| [Go](./Math/RectangleArea.Go)| Easy| O(1)| O(1)|
+[Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/)| [Go](./Math/TrappingRainWater.Go)| Hard| O(n)| O(n)|
+[Container With Most Water](https://leetcode.com/problems/container-with-most-water/)| [Go](./Math/ContainerMostWater.Go)| Medium| O(n)| O(1)|
+[Counting Bits](https://leetcode.com/problems/counting-bits/)| [Go](./Math/CountingBits.Go)| Medium| O(n)| O(n)|
+[K-th Smallest in Lexicographical Order](https://leetcode.com/problems/k-th-smallest-in-lexicographical-order/)| [Go](./Math/KthSmallestLexicographicalOrder.Go)| Hard| O(n)| O(1)|
+
+## Search
+
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value/)| [Go](./Search/ClosestBinarySearchTreeValue.Go)| Easy| O(logn)| O(1)|
+[Closest Binary Search Tree Value II](https://leetcode.com/problems/closest-binary-search-tree-value-ii/)| [Go](./Search/ClosestBinarySearchTreeValueII.Go)| Hard| O(n)| O(n)|
+[Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/)| [Go](./Search/SearchInRotatedSortedArray.Go)| Hard| O(logn)| O(1)|
+[Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/)| [Go](./Search/SearchInRotatedSortedArrayII.Go)| Medium| O(logn)| O(1)|
+[Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)| [Go](./Search/FindMinimumRotatedSortedArray.Go)| Medium| O(logn)| O(1)|
+[Find Minimum in Rotated Sorted Array II](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/)| [Go](./Search/FindMinimumRotatedSortedArrayII.Go)| Hard| O(logn)| O(1)|
+[Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/)| [Go](./Search/Search2DMatrix.Go)| Medium| O(log(m + n))| O(1)|
+[Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/)| [Go](./Search/Search2DMatrixII.Go)| Medium| O(m + n)| O(1)|
+[Search for a Range](https://leetcode.com/problems/search-for-a-range/)| [Go](./Search/SearchForARange.Go)| Medium| O(logn)| O(1)|
+[Search Insert Position](https://leetcode.com/problems/search-insert-position/)| [Go](./Search/SearchForARange.Go)| Medium| O(logn)| O(1)|
+[Find Peak Element](https://leetcode.com/problems/find-peak-element/)| [Go](./Search/FindPeakElement.Go)| Medium| O(logn)| O(1)|
+[Sqrt(x)](https://leetcode.com/problems/sqrtx/)| [Go](./Search/Sqrtx.Go)| Medium| O(logn)| O(1)|
+[Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/)| [Go](./Search/MedianTwoSortedArrays.Go)| Hard| O(log(m + n))| O(1)|
+
+
+## Sort (已全部做完)
+
+- 深刻的理解多路快排。第 75 题。
+- 链表的排序,插入排序(第 147 题)和归并排序(第 148 题)
+- 桶排序和基数排序。第 164 题。
+- "摆动排序"。第 324 题。
+- 两两不相邻的排序。第 767 题,第 1054 题。
+- "饼子排序"。第 969 题。
+
+| Title | Solution | Difficulty | Time | Space | 收藏 |
+| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
+|[56. Merge Intervals](https://leetcode.com/problems/merge-intervals/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0056.%20Merge%20Intervals)| Medium | O(n log n)| O(log n)||
+|[57. Insert Interval](https://leetcode.com/problems/insert-interval/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0057.%20Insert%20Interval)| Hard | O(n)| O(1)||
+|[75. Sort Colors](https://leetcode.com/problems/sort-colors/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0075.%20Sort%20Colors)| Medium| O(n)| O(1)|❤️|
+|[147. Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0147.%20Insertion%20Sort%20List)| Medium | O(n)| O(1) |❤️|
+|[148. Sort List](https://leetcode.com/problems/sort-list/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0148.%20Sort%20List)| Medium |O(n log n)| O(log n)|❤️|
+|[164. Maximum Gap](https://leetcode.com/problems/maximum-gap/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0164.%20Maximum%20Gap)| Hard | O(n log n)| O(log n) |❤️|
+|[179. Largest Number](https://leetcode.com/problems/largest-number/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0179.%20Largest%20Number)| Medium | O(n log n)| O(log n) |❤️|
+|[220. Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0220.%20Contains%20Duplicate%20III)| Medium | O(n^2)| O(1) ||
+|[242. Valid Anagram](https://leetcode.com/problems/valid-anagram/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0242.%20Valid%20Anagram)| Easy | O(n)| O(n) ||
+|[274. H-Index](https://leetcode.com/problems/h-index/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0274.%20H-Index)| Medium | O(n)| O(n) ||
+|[324. Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0324.%20Wiggle%20Sort%20II)| Medium| O(n)| O(n)|❤️|
+|[349. Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0349.%20Intersection%20of%20Two%20Arrays)| Easy | O(n)| O(n) ||
+|[350. Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0350.%20Intersection%20of%20Two%20Arrays%20II)| Easy | O(n)| O(n) ||
+|[524. Longest Word in Dictionary through Deleting](https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0524.%20Longest%20Word%20in%20Dictionary%20through%20Deleting)| Medium | O(n)| O(1) ||
+|[767. Reorganize String](https://leetcode.com/problems/reorganize-string/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0767.%20Reorganize%20String)| Medium | O(n log n)| O(log n) |❤️|
+|[853. Car Fleet](https://leetcode.com/problems/car-fleet/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0853.%20Car%20Fleet)| Medium | O(n log n)| O(log n) ||
+|[710. Random Pick with Blacklist](https://leetcode.com/problems/random-pick-with-blacklist/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0710.%20Random%20Pick%20with%20Blacklist)| Hard | O(n)| O(n) ||
+|[922. Sort Array By Parity II](https://leetcode.com/problems/sort-array-by-parity-ii/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0922.%20Sort%20Array%20By%20Parity%20II)| Easy | O(n)| O(1) ||
+|[969. Pancake Sorting](https://leetcode.com/problems/pancake-sorting/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0969.%20Pancake%20Sorting)| Medium | O(n log n)| O(log n) |❤️|
+|[973. K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0973.%20K%20Closest%20Points%20to%20Origin)| Medium | O(n log n)| O(log n) ||
+|[976. Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/0976.%20Largest%20Perimeter%20Triangle)| Easy | O(n log n)| O(log n) ||
+|[1030. Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/1030.%20Matrix%20Cells%20in%20Distance%20Order)| Easy | O(n^2)| O(1) ||
+|[1054. Distant Barcodes](https://leetcode.com/problems/distant-barcodes/)| [Go](https://github.com/halfrost/LeetCode-Go/tree/master/Algorithms/1054.%20Distant%20Barcodes)| Medium | O(n log n)| O(log n) ||
+|-----------------------------------------------------------------|-------------|-------------| --------------------------| --------------------------|-------------|
+
+
+## Union Find
+| Title | Solution | Difficulty | Time | Space |
+| ----- | -------- | ---------- | ---- | ----- |
+[Number of Connected Components in an Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/)| [Go](./UnionFind/NumberConnectedComponentsUndirectedGraph.Go)| Medium| O(nlogn)| O(n)|
+[Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree/)| [Go](./UnionFind/GraphValidTree.Go)| Medium| O(nlogn)| O(n)|
+
+## Google
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Plus One](https://leetcode.com/problems/plus-one/)| [Go](./Math/PlusOne.Go)| Easy| ★★★★★★|
+[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Go](./DFS/NumberofIslands.Go)| Medium| ★★★★|
+[Summary Ranges](https://leetcode.com/problems/summary-ranges/)| [Go](./Array/SummaryRanges.Go)| Medium| ★★★★|
+[Perfect Squares](https://leetcode.com/problems/perfect-squares/)| [Go](./DP/PerfectSquares.Go)| Medium| ★★★★|
+[Merge Intervals](https://leetcode.com/problems/merge-intervals/)| [Go](./Sort/MergeIntervals.Go)| Hard| ★★★|
+[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)| [Go](./Stack/ValidParentheses.Go)| Easy| ★★★|
+[Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/)| [Go](./Math/TrappingRainWater.Go)| Hard| ★★|
+[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)| [Go](./LinkedList/MergeKSortedLists.Go)| Hard| ★★|
+[Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/)| [Go](./Array/LongestConsecutiveSequence.Go)| Hard| ★★|
+[Find Peak Element](https://leetcode.com/problems/find-peak-element/)| [Go](./Search/FindPeakElement.Go)| Medium| ★★|
+[Power of Two](https://leetcode.com/problems/power-of-two/)| [Go](./Math/PowerTwo.Go)| Easy| ★★|
+[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)| [Go](./Array/SpiralMatrix.Go)| Medium| ★★|
+[Sliding Window Maximum ](https://leetcode.com/problems/sliding-window-maximum/)| [Go](./Array/SlidingWindowMaximum.Go)| Hard| ★★|
+[Pow(x, n)](https://leetcode.com/problems/isomorphic-strings/)| [Go](./Math/Pow.Go)| Medium| ★★|
+[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [Go](./DFS/LetterCombinationsPhoneNumber.Go)| Medium| ★★|
+[Heaters](https://leetcode.com/problems/heaters/)| [Go](./Array/Heaters.Go)| Easy| ★|
+
+## Facebook
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[3Sum](https://leetcode.com/problems/3sum/)| [Go](./Array/ThreeSum.Go)| Medium| ★★★★★★|
+[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)| [Go](./String/ValidPalindrome.Go)| Easy| ★★★★★★|
+[Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii/)| [Go](./String/ValidPalindromeII.Go)| Easy| ★★★★★★|
+[Move Zeroes](https://leetcode.com/problems/move-zeroes/)| [Go](./Array/MoveZeroes.Go)| Easy| ★★★★★★|
+[Remove Invalid Parentheses](https://leetcode.com/problems/remove-invalid-parentheses/)| [Go](./DFS/RemoveInvalidParentheses.Go)| Hard| ★★★★★★|
+[Add Binary](https://leetcode.com/problems/add-binary/)| [Go](./Math/AddBinary.Go)| Easy| ★★★★★|
+[Two Sum](https://leetcode.com/problems/two-sum/)| [Go](./Array/TwoSum.Go)| Easy| ★★★★★|
+[Bnary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)| [Go](./Tree/BnaryTreePaths.Go)| Easy| ★★★★|
+[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [Go](./DFS/LetterCombinationsPhoneNumber.Go)| Medium| ★★★★|
+[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)| [Go](./LinkedList/MergeKSortedLists.Go)| Hard| ★★★★|
+[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Go](./LinkedList/ReverseLinkedList.Go)| Easy| ★★★|
+[Merge Intervals](https://leetcode.com/problems/merge-intervals/)| [Go](./Sort/MergeIntervals.Go)| Hard| ★★★|
+[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Go](./DFS/NumberofIslands.Go)| Medium| ★★★|
+[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Go](./LinkedList/ReverseLinkedList.Go)| Easy| ★★★|
+[Expression Add Operators](https://leetcode.com/problems/expression-add-operators/)| [Go](./DFS/ExpressionAddOperators.Go)| Hard| ★★★|
+[Subsets](https://leetcode.com/problems/subsets/)| [Go](./DFS/Subsets.Go)| Medium| ★★★|
+[Sort Colors](https://leetcode.com/problems/sort-colors/)| [Go](./Sort/SortColors.Go)| Medium| ★★|
+
+## Snapchat
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Game of Life](https://leetcode.com/problems/game-of-life/) | [Go](./Array/GameLife.Go)| Medium| ★★★★★★|
+[Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/)| [Go](./Sort/MeetingRoomsII.Go)| Medium| ★★★★★★|
+[Valid Sudoku](https://leetcode.com/problems/valid-sudoku/)| [Go](./Array/ValidSudoku.Go)| Easy| ★★★★★|
+[Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/)| [Go](./Tree/BinaryTreeVerticalOrderTraversal.Go)| Medium| ★★★★|
+[Alien Dictionary](https://leetcode.com/problems/alien-dictionary/)| [Go](./Sort/AlienDictionary.Go)| Hard| ★★★★|
+[One Edit Distance](https://leetcode.com/problems/one-edit-distance/)| [Go](./String/OneEditDistance.Go)| Medium| ★★★|
+[Sudoku Solver](https://leetcode.com/problems/sudoku-solver/)| [Go](./Math/SudokuSolver.Go)| Hard| ★★★|
+[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Go](./LinkedList/ReverseLinkedList.Go)| Easy| ★★|
+[Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees/)| [Go](./Tree/UniqueBinarySearchTrees.Go)| Medium| ★★|
+[Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)| [Go](./Array/MinimumWindowSubstring.Go)| Hard| ★★|
+[Remove K Digits](https://leetcode.com/problems/remove-k-digits/)| [Go](./Stack/RemoveKDigits.Go)| Medium| ★|
+[Ternary Expression Parser](https://leetcode.com/problems/ternary-expression-parser/)| [Go](./Stack/TernaryExpressionParser.Go)| Medium| ★|
+
+## Uber
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Valid Sudoku](https://leetcode.com/problems/valid-sudoku/)| [Go](./Array/ValidSudoku.Go)| Easy| ★★★★|
+[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)| [Go](./Array/SpiralMatrix.Go)| Medium| ★★★★|
+[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [Go](./DFS/LetterCombinationsPhoneNumber.Go)| Medium| ★★★★|
+[Group Anagrams](https://leetcode.com/problems/anagrams/)| [Go](./String/GroupAnagrams.Go)| Medium| ★★★★|
+[Word Pattern](https://leetcode.com/problems/word-pattern/)| [Go](./String/WordPattern.Go)| Easy| ★★★|
+[Roman to Integer](https://leetcode.com/problems/roman-to-integer/)| [Go](./Math/RomanToInteger.Go)| Easy| ★★★|
+[Combination Sum](https://leetcode.com/problems/combination-sum/)| [Go](./DFS/CombinationSum.Go)| Medium| ★★|
+
+## Airbnb
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Two Sum](https://leetcode.com/problems/two-sum/)| [Go](./Array/TwoSum.Go)| Easy| ★★★★★|
+[Text Justification](https://leetcode.com/problems/text-justification/)| [Go](./String/TextJustification.Go)| Hard| ★★★★|
+[House Robber](https://leetcode.com/problems/house-robber/)| [Go](./DP/HouseRobber.Go)| Easy| ★★|
+[Single Number](https://leetcode.com/problems/single-number/)| [Go](./Math/SingleNumber.Go)| Medium| ★★|
+[Word Search II](https://leetcode.com/problems/word-search-ii/)| [Go](./DFS/WordSearchII.Go)| Hard| ★★|
+[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)| [Go](./Math/AddTwoNumbers.Go)| Medium| ★★|
+
+## LinkedIn
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Maximum Subarray](https://leetcode.com/problems/maximum-subarray/)| [Go](./DP/MaximumSubarray.Go)| Medium| ★★★★★★|
+[Pow(x, n)](https://leetcode.com/problems/isomorphic-strings/)| [Go](./Math/Pow.Go)| Medium| ★★★★★★|
+[Merge Intervals](https://leetcode.com/problems/merge-intervals/)| [Go](./Sort/MergeIntervals.Go)| Hard| ★★★★★★|
+[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)| [Go](./String/IsomorphicStrings.Go)| Easy| ★★★★★★|
+[Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/)| [Go](./Search/SearchInRotatedSortedArray.Go)| Hard| ★★★★★|
+[Search for a Range](https://leetcode.com/problems/search-for-a-range/)| [Go](./Search/SearchForARange.Go)| Medium| ★★★★★|
+[Two Sum](https://leetcode.com/problems/two-sum/)| [Go](./Array/TwoSum.Go)| Easy| ★★★★|
+[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)| [Go](./Tree/BinaryTreeLevelOrderTraversal.Go)| Easy| ★★★★|
+[Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/)| [Go](./Stack/EvaluateReversePolishNotation.Go)| Medium| ★★★|
+[Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)| [Go](./DP/MaximumProductSubarray.Go)| Medium| ★★★|
+[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)| [Go](./Array/ProductExceptSelf.Go)| Medium| ★★★|
+[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [Go](./Tree/SymmetricTree.Go)| Easy| ★★|
+
+## Amazon
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Two Sum](https://leetcode.com/problems/two-sum/)| [Go](./Array/TwoSum.Go)| Easy| ★★★★★★|
+[Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/)| [Go](./DP/MinCostClimbingStairs.Go)| Easy| ★★★★|
+[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Go](./DFS/NumberofIslands.Go)| Medium| ★★|
+[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)| [Go](./Math/AddTwoNumbers.Go)| Medium| ★★|
+[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Go](./LinkedList/ReverseLinkedList.Go)| Easy| ★★|
+[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)| [Go](./Stack/ValidParentheses.Go)| Easy| ★★|
+[Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)| [Go](./DP/LongestPalindromicSubstring.Go)| Medium| ★★|
+[Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/)| [Go](./Math/TrappingRainWater.Go)| Hard| ★★|
+[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [Go](./String/LongestSubstringWithoutRepeatingCharacters.Go)| Medium| ★★|
+[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [Go](./DFS/LetterCombinationsPhoneNumber.Go)| Medium| ★★|
+[Valid Anagram](https://leetcode.com/problems/valid-anagram/)| [Go](./String/ValidAnagram.Go)| Easy| ★★|
+[Rotate Image](https://leetcode.com/problems/rotate-image/)| [Go](./Array/RotateImage.Go)| Medium| ★★|
+[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)| [Go](./DP/BestTimeBuySellStock.Go)| Easy| ★★|
+[3Sum](https://leetcode.com/problems/3sum/)| [Go](./Array/ThreeSum.Go)| Medium| ★★|
+[Sliding Window Maximum ](https://leetcode.com/problems/sliding-window-maximum/)| [Go](./Array/SlidingWindowMaximum.Go)| Hard| ★★|
+
+## Microsoft
+| Title | Solution | Difficulty | Frequency |
+| ----- | -------- | ---------- | --------- |
+[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Go](./LinkedList/ReverseLinkedList.Go)| Easy| ★★★★★★|
+[Two Sum](https://leetcode.com/problems/two-sum/)| [Go](./Array/TwoSum.Go)| Easy| ★★★★★|
+[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)| [Go](./Math/Atoi.Go)| Easy| ★★★★|
+[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)| [Go](./Math/AddTwoNumbers.Go)| Medium| ★★★★|
+[Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/)| [Go](./Math/ExcelSheetColumnNumber.Go)| Easy| ★★★★|
+[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)| [Go](./Tree/ValidateBinarySearchTree.Go)| Medium| ★★★|
+[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)| [Go](./LinkedList/MergeTwoSortedLists.Go)| Easy| ★★★|
\ No newline at end of file
diff --git a/ctl/README.md b/ctl/README.md
new file mode 100644
index 00000000..cbbc8327
--- /dev/null
+++ b/ctl/README.md
@@ -0,0 +1,20 @@
+# LeetCode-Go ctl
+
+## 配置方法
+
+1. 在`.gitignore`中,添加一行`*.toml`
+2. 在`LeetCode-Go`目录下,添加文本文件`config.toml`。
+3. 把以下内容复制到`config.toml`中。
+4. 把`config.toml`中的`test`分别修改为你的 leetcode `用户名`和`密码`。
+5. 去 leetcode 登录后,把网站 cookie 复制 (需要复制 csrftoken 和 LEETCODE_SESSION) 并替换 `config.toml`中的`Cookie`。
+
+```toml
+Username="test"
+Password="test"
+Cookie="csrftoken=XXXXXXXXX; LEETCODE_SESSION=YYYYYYYY;"
+CSRFtoken="ZZZZZZZZ"
+```
+
+## PDF 生成
+
+用 `leetcode-go pdf` 命令先生成书籍内容的合并版本 pdf.md,再用 vscode 或者其他支持 toc 目录生成的工具,生成 toc。最后用 Typora 把 md 文件转换成 pdf。就可以发布 release 新版本了。
\ No newline at end of file
diff --git a/ctl/command.go b/ctl/command.go
new file mode 100644
index 00000000..a440a571
--- /dev/null
+++ b/ctl/command.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/spf13/cobra"
+)
+
+var rootCmd = &cobra.Command{
+ Use: "leetcode-go",
+ Short: "A simple command line client for leetcode-go.",
+}
+
+func execute() {
+ if err := rootCmd.Execute(); err != nil {
+ fmt.Println(err)
+ os.Exit(-1)
+ }
+}
+
+func init() {
+ rootCmd.AddCommand(
+ versionCmd,
+ newBuildCommand(),
+ newLabelCommand(),
+ newPDFCommand(),
+ newRefresh(),
+ )
+}
diff --git a/ctl/config.go b/ctl/config.go
new file mode 100644
index 00000000..4288c3d2
--- /dev/null
+++ b/ctl/config.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/BurntSushi/toml"
+)
+
+const (
+ configTOML = "config.toml"
+)
+
+type config struct {
+ Username string
+ Password string
+ Cookie string
+ CSRFtoken string
+}
+
+func (c config) String() string {
+ return fmt.Sprintf("Username: %s, Password: %s", c.Username, c.Password)
+}
+
+func getConfig() *config {
+ cfg := new(config)
+ if _, err := toml.DecodeFile(configTOML, &cfg); err != nil {
+ log.Panicf(err.Error())
+ }
+ // log.Printf("get config: %s", cfg)
+ return cfg
+}
diff --git a/ctl/error.go b/ctl/error.go
new file mode 100644
index 00000000..903460a8
--- /dev/null
+++ b/ctl/error.go
@@ -0,0 +1,21 @@
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+const (
+ // ExitSuccess define
+ ExitSuccess = iota
+ // ExitError define
+ ExitError
+ // ExitBadArgs define
+ ExitBadArgs
+)
+
+// ExitWithError define
+func ExitWithError(code int, err error) {
+ fmt.Fprintln(os.Stderr, "Error: ", err)
+ os.Exit(code)
+}
diff --git a/ctl/label.go b/ctl/label.go
new file mode 100644
index 00000000..112a721c
--- /dev/null
+++ b/ctl/label.go
@@ -0,0 +1,324 @@
+package main
+
+import (
+ "bufio"
+ "errors"
+ "fmt"
+ "github.com/halfrost/LeetCode-Go/ctl/util"
+ "github.com/spf13/cobra"
+ "io"
+ "io/ioutil"
+ "os"
+ "regexp"
+ "strings"
+)
+
+var (
+ chapterOneFileOrder = []string{"_index", "Data_Structure", "Algorithm"}
+ chapterOneMenuOrder = []string{"_index", "#关于作者", "Data_Structure", "Algorithm"}
+ chapterTwoFileOrder = []string{"_index", "Array", "String", "Two_Pointers", "Linked_List", "Stack", "Tree", "Dynamic_Programming", "Backtracking", "Depth_First_Search", "Breadth_First_Search",
+ "Binary_Search", "Math", "Hash_Table", "Sort", "Bit_Manipulation", "Union_Find", "Sliding_Window", "Segment_Tree", "Binary_Indexed_Tree"}
+ chapterThreeFileOrder = []string{"_index", "Segment_Tree", "UnionFind", "LRUCache", "LFUCache"}
+ preNextHeader = "----------------------------------------------\n\n"
+ preNextFotter = "
"
+ delLine = "----------------------------------------------\n"
+ delHeader = ""
+ delLabel = "<[a-zA-Z]+.*?>([\\s\\S]*?)[a-zA-Z]*?>"
+ delFooter = "
"
+
+ //ErrNoFilename is thrown when the path the the file to tail was not given
+ ErrNoFilename = errors.New("You must provide the path to a file in the \"-file\" flag.")
+
+ //ErrInvalidLineCount is thrown when the user provided 0 (zero) as the value for number of lines to tail
+ ErrInvalidLineCount = errors.New("You cannot tail zero lines.")
+
+ chapterMap = map[string]map[string]string{
+ "ChapterOne": {
+ "_index": "第一章 序章",
+ "#关于作者": "1.1 关于作者",
+ "Data_Structure": "1.2 数据结构知识",
+ "Algorithm": "1.3 算法知识",
+ },
+ "ChapterTwo": {
+ "_index": "第二章 算法专题",
+ "Array": "2.01 Array",
+ "String": "2.02 String",
+ "Two_Pointers": "2.03 ✅ Two Pointers",
+ "Linked_List": "2.04 ✅ Linked List",
+ "Stack": "2.05 ✅ Stack",
+ "Tree": "2.06 Tree",
+ "Dynamic_Programming": "2.07 Dynamic Programming",
+ "Backtracking": "2.08 ✅ Backtracking",
+ "Depth_First_Search": "2.09 Depth First Search",
+ "Breadth_First_Search": "2.10 Breadth First Search",
+ "Binary_Search": "2.11 Binary Search",
+ "Math": "2.12 Math",
+ "Hash_Table": "2.13 Hash Table",
+ "Sort": "2.14 ✅ Sort",
+ "Bit_Manipulation": "2.15 ✅ Bit Manipulation",
+ "Union_Find": "2.16 ✅ Union Find",
+ "Sliding_Window": "2.17 ✅ Sliding Window",
+ "Segment_Tree": "2.18 ✅ Segment Tree",
+ "Binary_Indexed_Tree": "2.19 ✅ Binary Indexed Tree",
+ },
+ "ChapterThree": {
+ "_index": "第三章 一些模板",
+ "Segment_Tree": "3.1 Segment Tree",
+ "UnionFind": "3.2 UnionFind",
+ "LRUCache": "3.3 LRUCache",
+ "LFUCache": "3.4 LFUCache",
+ },
+ "ChapterFour": {
+ "_index": "第四章 Leetcode 题解",
+ },
+ }
+)
+
+func getChapterFourFileOrder() []string {
+ solutions := util.LoadChapterFourDir()
+ chapterFourFileOrder := []string{"_index"}
+ chapterFourFileOrder = append(chapterFourFileOrder, solutions...)
+ fmt.Printf("ChapterFour 中包括 _index 有 %v 个文件\n", len(chapterFourFileOrder))
+ return chapterFourFileOrder
+}
+
+func newLabelCommand() *cobra.Command {
+ mc := &cobra.Command{
+ Use: "label ",
+ Short: "Label related commands",
+ }
+ //mc.PersistentFlags().StringVar(&logicEndpoint, "endpoint", "localhost:5880", "endpoint of logic service")
+ mc.AddCommand(
+ newAddPreNext(),
+ newDeletePreNext(),
+ )
+ return mc
+}
+
+func newAddPreNext() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "add-pre-next",
+ Short: "Add pre-next label",
+ Run: func(cmd *cobra.Command, args []string) {
+ addPreNext()
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func newDeletePreNext() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "del-pre-next",
+ Short: "Delete pre-next label",
+ Run: func(cmd *cobra.Command, args []string) {
+ delPreNext()
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func addPreNext() {
+ // Chpater one add pre-next
+ addPreNextLabel(chapterOneFileOrder, []string{}, "", "ChapterOne", "ChapterTwo")
+ // Chpater two add pre-next
+ addPreNextLabel(chapterTwoFileOrder, chapterOneFileOrder, "ChapterOne", "ChapterTwo", "ChapterThree")
+ // Chpater three add pre-next
+ addPreNextLabel(chapterThreeFileOrder, chapterTwoFileOrder, "ChapterTwo", "ChapterThree", "ChapterFour")
+ // Chpater four add pre-next
+ //fmt.Printf("%v\n", getChapterFourFileOrder())
+ addPreNextLabel(getChapterFourFileOrder(), chapterThreeFileOrder, "ChapterThree", "ChapterFour", "")
+}
+
+func addPreNextLabel(order, preOrder []string, preChapter, chapter, nextChapter string) {
+ var (
+ exist bool
+ err error
+ res []byte
+ count int
+ )
+ for index, v := range order {
+ tmp := ""
+ if index == 0 {
+ if chapter == "ChapterOne" {
+ // 第一页不需要“上一章”
+ tmp = "\n\n" + delLine + fmt.Sprintf("下一页➡️
\n", chapter, order[index+1])
+ } else {
+ tmp = "\n\n" + preNextHeader + fmt.Sprintf("⬅️上一章
\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("下一页➡️
\n", chapter, order[index+1]) + preNextFotter
+ }
+ } else if index == len(order)-1 {
+ if chapter == "ChapterFour" {
+ // 最后一页不需要“下一页”
+ tmp = "\n\n" + delLine + fmt.Sprintf("⬅️上一页
\n", chapter, order[index-1])
+ } else {
+ tmp = "\n\n" + preNextHeader + fmt.Sprintf("⬅️上一页
\n", chapter, order[index-1]) + fmt.Sprintf("下一章➡️
\n", nextChapter) + preNextFotter
+ }
+ } else if index == 1 {
+ tmp = "\n\n" + preNextHeader + fmt.Sprintf("⬅️上一页
\n", chapter) + fmt.Sprintf("下一页➡️
\n", chapter, order[index+1]) + preNextFotter
+ } else {
+ tmp = "\n\n" + preNextHeader + fmt.Sprintf("⬅️上一页
\n", chapter, order[index-1]) + fmt.Sprintf("下一页➡️
\n", chapter, order[index+1]) + preNextFotter
+ }
+ exist, err = needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, v))
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ // 当前没有上一页和下一页,才添加
+ if !exist && err == nil {
+ res, err = eofAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, v), tmp)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ util.WriteFile(fmt.Sprintf("../website/content/%v/%v.md", chapter, v), res)
+ count++
+ }
+ }
+ fmt.Printf("添加了 %v 个文件的 pre-next\n", count)
+}
+
+func eofAdd(filePath string, labelString string) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ output = append(output, []byte(labelString)...)
+ output = append(output, []byte("\n")...)
+ return output, nil
+ }
+ return nil, err
+ }
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+}
+
+func delPreNext() {
+ // Chpater one del pre-next
+ delPreNextLabel(chapterOneFileOrder, "ChapterOne")
+ // Chpater two del pre-next
+ delPreNextLabel(chapterTwoFileOrder, "ChapterTwo")
+ // Chpater three del pre-next
+ delPreNextLabel(chapterThreeFileOrder, "ChapterThree")
+ // Chpater four del pre-next
+ delPreNextLabel(getChapterFourFileOrder(), "ChapterFour")
+}
+
+func delPreNextLabel(order []string, chapter string) {
+ count := 0
+ for index, v := range order {
+ lineNum := 5
+ if index == 0 && chapter == "ChapterOne" || index == len(order)-1 && chapter == "ChapterFour" {
+ lineNum = 3
+ }
+ exist, err := needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, v))
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ // 存在才删除
+ if exist && err == nil {
+ removeLine(fmt.Sprintf("../website/content/%v/%v.md", chapter, v), lineNum+1)
+ count++
+ }
+ }
+ fmt.Printf("删除了 %v 个文件的 pre-next\n", count)
+ // 另外一种删除方法
+ // res, err := eofDel(fmt.Sprintf("../website/content/ChapterOne/%v.md", v))
+ // if err != nil {
+ // fmt.Println(err)
+ // return
+ // }
+ // util.WriteFile(fmt.Sprintf("../website/content/ChapterOne/%v.md", v), res)
+}
+
+func needAdd(filePath string) (bool, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return false, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return false, nil
+ }
+ return false, err
+ }
+ if ok, _ := regexp.Match(delHeader, line); ok {
+ return true, nil
+ } else if ok, _ := regexp.Match(delLabel, line); ok {
+ return true, nil
+ } else {
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+ }
+}
+
+func eofDel(filePath string) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return output, nil
+ }
+ return nil, err
+ }
+ if ok, _ := regexp.Match(delLine, line); ok {
+ reg := regexp.MustCompile(delLine)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match(delHeader, line); ok {
+ reg := regexp.MustCompile(delHeader)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match(delLabel, line); ok {
+ reg := regexp.MustCompile(delLabel)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match(delFooter, line); ok {
+ reg := regexp.MustCompile(delFooter)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else {
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+ }
+}
+
+func removeLine(path string, lineNumber int) {
+ file, err := ioutil.ReadFile(path)
+ if err != nil {
+ panic(err)
+ }
+ info, _ := os.Stat(path)
+ mode := info.Mode()
+ array := strings.Split(string(file), "\n")
+ array = array[:len(array)-lineNumber-1]
+ ioutil.WriteFile(path, []byte(strings.Join(array, "\n")), mode)
+ //fmt.Println("remove line successful")
+}
diff --git a/ctl/main.go b/ctl/main.go
new file mode 100644
index 00000000..f7d07b01
--- /dev/null
+++ b/ctl/main.go
@@ -0,0 +1,5 @@
+package main
+
+func main() {
+ execute()
+}
diff --git a/ctl/meta/Array b/ctl/meta/Array
new file mode 100644
index 00000000..6611e480
--- /dev/null
+++ b/ctl/meta/Array
@@ -0,0 +1,52 @@
+|1. Two Sum| [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)||
+|11. Container With Most Water| [Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})| Medium | O(n)| O(1)||
+|15. 3Sum | [Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|16. 3Sum Closest | [Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})| Medium | O(n^2)| O(1)|❤️|
+|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
+|26. Remove Duplicates from Sorted Array | [Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
+|27. Remove Element | [Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})| Easy | O(n)| O(1)||
+|39. Combination Sum | [Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})| Medium | O(n log n)| O(n)||
+|40. Combination Sum II | [Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})| Medium | O(n log n)| O(n)||
+|41. First Missing Positive | [Go]({{< relref "/ChapterFour/0041.First-Missing-Positive.md" >}})| Hard | O(n)| O(n)||
+|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
+|48. Rotate Image | [Go]({{< relref "/ChapterFour/0048.Rotate-Image.md" >}})| Medium | O(n)| O(1)||
+|53. Maximum Subarray| [Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})| Easy | O(n)| O(n)||
+|54. Spiral Matrix| [Go]({{< relref "/ChapterFour/0054.Spiral-Matrix.md" >}})| Medium | O(n)| O(n^2)||
+|56. Merge Intervals | [Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})| Medium | O(n log n)| O(1)||
+|57. Insert Interval | [Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})| Hard | O(n)| O(1)||
+|59. Spiral Matrix II | [Go]({{< relref "/ChapterFour/0059.Spiral-Matrix-II.md" >}})| Medium | O(n)| O(n^2)||
+|62. Unique Paths | [Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})| Medium | O(n^2)| O(n^2)||
+|63. Unique Paths II | [Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})| Medium | O(n^2)| O(n^2)||
+|64. Minimum Path Sum | [Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})| Medium | O(n^2)| O(n^2)||
+|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
+|78. Subsets| [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|79. Word Search | [Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
+|80. Remove Duplicates from Sorted Array II| [Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})| Medium | O(n)| O(1||
+|84. Largest Rectangle in Histogram | [Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})| Medium | O(n)| O(n)|❤️|
+|88. Merge Sorted Array | [Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})| Easy | O(n)| O(1)|❤️|
+|90. Subsets II | [Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|120. Triangle | [Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})| Medium | O(n^2)| O(n)||
+|121. Best Time to Buy and Sell Stock | [Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})| Easy | O(n)| O(1)||
+|122. Best Time to Buy and Sell Stock II | [Go]({{< relref "/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md" >}})| Easy | O(n)| O(1)||
+|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
+|152. Maximum Product Subarray | [Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})| Medium | O(n)| O(1)||
+|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
+|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
+|216. Combination Sum III | [Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})| Medium | O(n)| O(1)|❤️|
+|217. Contains Duplicate | [Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})| Easy | O(n)| O(n)||
+|219. Contains Duplicate II | [Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})| Easy | O(n)| O(n)||
+|283. Move Zeroes | [Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})| Easy | O(n)| O(1)||
+|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
+|532. K-diff Pairs in an Array | [Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})| Easy | O(n)| O(n)||
+|566. Reshape the Matrix | [Go]({{< relref "/ChapterFour/0566.Reshape-the-Matrix.md" >}})| Easy | O(n^2)| O(n^2)||
+|628. Maximum Product of Three Numbers | [Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})| Easy | O(n)| O(1)||
+|713. Subarray Product Less Than K | [Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})| Medium | O(n)| O(1)||
+|714. Best Time to Buy and Sell Stock with Transaction Fee| [Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})| Medium | O(n)| O(1)||
+|746. Min Cost Climbing Stairs | [Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})| Easy | O(n)| O(1)||
+|766. Toeplitz Matrix | [Go]({{< relref "/ChapterFour/0766.Toeplitz-Matrix.md" >}})| Easy | O(n)| O(1)||
+|867. Transpose Matrix | [Go]({{< relref "/ChapterFour/0867.Transpose-Matrix.md" >}})| Easy | O(n)| O(1)||
+|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
+|907. Sum of Subarray Minimums | [Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})| Medium | O(n)| O(n)|❤️|
+|922. Sort Array By Parity II | [Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})| Medium | O(n)| O(1)||
+|969. Pancake Sorting | [Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})| Medium | O(n)| O(1)|❤️|
+|977. Squares of a Sorted Array | [Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Backtracking b/ctl/meta/Backtracking
new file mode 100644
index 00000000..b3c611fc
--- /dev/null
+++ b/ctl/meta/Backtracking
@@ -0,0 +1,30 @@
+|17. Letter Combinations of a Phone Number | [Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})| Medium | O(log n)| O(1)||
+|22. Generate Parentheses| [Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})| Medium | O(log n)| O(1)||
+|37. Sudoku Solver | [Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
+|39. Combination Sum | [Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})| Medium | O(n log n)| O(n)||
+|40. Combination Sum II | [Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})| Medium | O(n log n)| O(n)||
+|46. Permutations | [Go]({{< relref "/ChapterFour/0046.Permutations.md" >}})| Medium | O(n)| O(n)|❤️|
+|47. Permutations II | [Go]({{< relref "/ChapterFour/0047.Permutations-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|51. N-Queens | [Go]({{< relref "/ChapterFour/0051.N-Queens.md" >}})| Hard | O(n^2)| O(n)|❤️|
+|52. N-Queens II | [Go]({{< relref "/ChapterFour/0052.N-Queens-II.md" >}})| Hard | O(n^2)| O(n)|❤️|
+|60. Permutation Sequence | [Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})| Medium | O(n log n)| O(1)||
+|77. Combinations | [Go]({{< relref "/ChapterFour/0077.Combinations.md" >}})| Medium | O(n)| O(n)|❤️|
+|78. Subsets | [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|79. Word Search | [Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
+|89. Gray Codes | [Go]({{< relref "/ChapterFour/0089.Gray-Code.md" >}})| Medium | O(n)| O(1)||
+|90. Subsets II | [Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|93. Restore IP Addresses | [Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})| Medium | O(n)| O(n)|❤️|
+|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
+|131. Palindrome Partitioning | [Go]({{< relref "/ChapterFour/0131.Palindrome-Partitioning.md" >}})| Medium | O(n)| O(n^2)|❤️|
+|211. Add and Search Word - Data structure design | [Go]({{< relref "/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md" >}})| Medium | O(n)| O(n)|❤️|
+|212. Word Search II | [Go]({{< relref "/ChapterFour/0212.Word-Search-II.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
+|216. Combination Sum III | [Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})| Medium | O(n)| O(1)|❤️|
+|306. Additive Number | [Go]({{< relref "/ChapterFour/0306.Additive-Number.md" >}})| Medium | O(n^2)| O(1)|❤️|
+|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
+|401. Binary Watch | [Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})| Easy | O(1)| O(1)||
+|526. Beautiful Arrangement | [Go]({{< relref "/ChapterFour/0526.Beautiful-Arrangement.md" >}})| Medium | O(n^2)| O(1)|❤️|
+|784. Letter Case Permutation | [Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})| Easy | O(n)| O(n)||
+|842. Split Array into Fibonacci Sequence | [Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})| Medium | O(n^2)| O(1)|❤️|
+|980. Unique Paths III | [Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})| Hard | O(n log n)| O(n)||
+|996. Number of Squareful Arrays | [Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})| Hard | O(n log n)| O(n) ||
+|1079. Letter Tile Possibilities | [Go]({{< relref "/ChapterFour/1079.Letter-Tile-Possibilities.md" >}})| Medium | O(n^2)| O(1)|❤️|
\ No newline at end of file
diff --git a/ctl/meta/Binary_Indexed_Tree b/ctl/meta/Binary_Indexed_Tree
new file mode 100644
index 00000000..e69de29b
diff --git a/ctl/meta/Binary_Search b/ctl/meta/Binary_Search
new file mode 100644
index 00000000..42792418
--- /dev/null
+++ b/ctl/meta/Binary_Search
@@ -0,0 +1,13 @@
+|50. Pow(x, n) | [Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})| Medium | O(log n)| O(1)||
+|69. Sqrt(x) | [Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})| Easy | O(log n)| O(1)||
+|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
+|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
+|222. Count Complete Tree Nodes | [Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})| Medium | O(n)| O(1)||
+|230. Kth Smallest Element in a BST | [Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})| Medium | O(n)| O(1)||
+|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
+|300. Longest Increasing Subsequence | [Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})| Medium | O(n log n)| O(n)||
+|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
+|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
+|392. Is Subsequence | [Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})| Medium | O(n)| O(1)||
+|454. 4Sum II | [Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})| Medium | O(n^2)| O(n) ||
+|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
\ No newline at end of file
diff --git a/ctl/meta/Bit_Manipulation b/ctl/meta/Bit_Manipulation
new file mode 100644
index 00000000..5043dbf0
--- /dev/null
+++ b/ctl/meta/Bit_Manipulation
@@ -0,0 +1,29 @@
+|78. Subsets | [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|136. Single Number | [Go]({{< relref "/ChapterFour/0136.Single-Number.md" >}})| Easy | O(n)| O(1)||
+|137. Single Number II | [Go]({{< relref "/ChapterFour/0137.Single-Number-II.md" >}})| Medium | O(n)| O(1)|❤️|
+|169. Majority Element | [Go]({{< relref "/ChapterFour/0169.Majority-Element.md" >}})| Easy | O(n)| O(1)|❤️|
+|187. Repeated DNA Sequences | [Go]({{< relref "/ChapterFour/0187.Repeated-DNA-Sequences.md" >}})| Medium | O(n)| O(1)||
+|190. Reverse Bits | [Go]({{< relref "/ChapterFour/0190.Reverse-Bits.md" >}})| Easy | O(n)| O(1)|❤️|
+|191. Number of 1 Bits | [Go]({{< relref "/ChapterFour/0191.Number-of-1-Bits.md" >}})| Easy | O(n)| O(1)||
+|201. Bitwise AND of Numbers Range | [Go]({{< relref "/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md" >}})| Medium | O(n)| O(1)|❤️|
+|231. Power of Two | [Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})| Easy | O(1)| O(1)||
+|260. Single Number III | [Go]({{< relref "/ChapterFour/0260.Single-Number-III.md" >}})| Medium | O(n)| O(1)|❤️|
+|268. Missing Number | [Go]({{< relref "/ChapterFour/0268.Missing-Number.md" >}})| Easy | O(n)| O(1)||
+|318. Maximum Product of Word Lengths | [Go]({{< relref "/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md" >}})| Medium | O(n)| O(1)||
+|338. Counting Bits | [Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})| Medium | O(n)| O(n)||
+|342. Power of Four | [Go]({{< relref "/ChapterFour/0342.Power-of-Four.md" >}})| Easy | O(n)| O(1)||
+|371. Sum of Two Integers | [Go]({{< relref "/ChapterFour/0371.Sum-of-Two-Integers.md" >}})| Easy | O(n)| O(1)||
+|389. Find the Difference | [Go]({{< relref "/ChapterFour/0389.Find-the-Difference.md" >}})| Easy | O(n)| O(1)||
+|393. UTF-8 Validation | [Go]({{< relref "/ChapterFour/0393.UTF-8-Validation.md" >}})| Medium | O(n)| O(1)||
+|397. Integer Replacement | [Go]({{< relref "/ChapterFour/0397.Integer-Replacement.md" >}})| Medium | O(n)| O(1)||
+|401. Binary Watch | [Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})| Easy | O(1)| O(1)||
+|405. Convert a Number to Hexadecimal | [Go]({{< relref "/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md" >}})| Easy | O(n)| O(1)||
+|421. Maximum XOR of Two Numbers in an Array | [Go]({{< relref "/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md" >}})| Medium | O(n)| O(1)|❤️|
+|461. Hamming Distance | [Go]({{< relref "/ChapterFour/0461.Hamming-Distance.md" >}})| Easy | O(n)| O(1)||
+|476. Number Complement | [Go]({{< relref "/ChapterFour/0476.Number-Complement.md" >}})| Easy | O(n)| O(1)||
+|477. Total Hamming Distance | [Go]({{< relref "/ChapterFour/0477.Total-Hamming-Distance.md" >}})| Medium | O(n)| O(1)||
+|693. Binary Number with Alternating Bits | [Go]({{< relref "/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md" >}})| Easy | O(n)| O(1)|❤️|
+|756. Pyramid Transition Matrix | [Go]({{< relref "/ChapterFour/0756.Pyramid-Transition-Matrix.md" >}})| Medium | O(n log n)| O(n)||
+|762. Prime Number of Set Bits in Binary Representation | [Go]({{< relref "/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md" >}})| Easy | O(n)| O(1)||
+|784. Letter Case Permutation | [Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})| Easy | O(n)| O(1)||
+|898. Bitwise ORs of Subarrays | [Go]({{< relref "/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md" >}})| Medium | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Breadth_First_Search b/ctl/meta/Breadth_First_Search
new file mode 100644
index 00000000..4eb99cfe
--- /dev/null
+++ b/ctl/meta/Breadth_First_Search
@@ -0,0 +1,14 @@
+|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
+|102. Binary Tree Level Order Traversal | [Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})| Medium | O(n)| O(1)||
+|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
+|107. Binary Tree Level Order Traversal II | [Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})| Easy | O(n)| O(1)||
+|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
+|127. Word Ladder | [Go]({{< relref "/ChapterFour/0127.Word-Ladder.md" >}})| Medium | O(n)| O(n)||
+|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
+|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(n^2)| O(n^2)||
+|207. Course Schedule | [Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})| Medium | O(n^2)| O(n^2)||
+|210. Course Schedule II | [Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})| Medium | O(n^2)| O(n^2)||
+|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
+|542. 01 Matrix | [Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})| Medium | O(n)| O(1)||
+|993. Cousins in Binary Tree | [Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Depth_First_Search b/ctl/meta/Depth_First_Search
new file mode 100644
index 00000000..9bf247b1
--- /dev/null
+++ b/ctl/meta/Depth_First_Search
@@ -0,0 +1,23 @@
+|98. Validate Binary Search Tree | [Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})| Medium | O(n)| O(1)||
+|99. Recover Binary Search Tree | [Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})| Hard | O(n)| O(1)||
+|100. Same Tree | [Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})| Easy | O(n)| O(1)||
+|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
+|104. Maximum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|108. Convert Sorted Array to Binary Search Tree | [Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
+|109. Convert Sorted List to Binary Search Tree | [Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})| Medium | O(log n)| O(n)||
+|110. Balanced Binary Tree | [Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|112. Path Sum | [Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})| Easy | O(n)| O(1)||
+|113. Path Sum II | [Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})| Medium | O(n)| O(1)||
+|114. Flatten Binary Tree to Linked List | [Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})| Medium | O(n)| O(1)||
+|124. Binary Tree Maximum Path Sum | [Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})| Hard | O(n)| O(1)||
+|129. Sum Root to Leaf Numbers | [Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})| Medium | O(n)| O(1)||
+|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
+|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(n^2)| O(n^2)||
+|207. Course Schedule | [Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})| Medium | O(n^2)| O(n^2)||
+|210. Course Schedule II | [Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})| Medium | O(n^2)| O(n^2)||
+|257. Binary Tree Paths | [Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})| Easy | O(n)| O(1)||
+|394. Decode String | [Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})| Medium | O(n)| O(n)||
+|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
+|542. 01 Matrix | [Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})| Medium | O(n)| O(1)||
+|980. Unique Paths III | [Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})| Hard | O(n log n)| O(n)||
\ No newline at end of file
diff --git a/ctl/meta/Dynamic_Programming b/ctl/meta/Dynamic_Programming
new file mode 100644
index 00000000..0f937f91
--- /dev/null
+++ b/ctl/meta/Dynamic_Programming
@@ -0,0 +1,26 @@
+|53. Maximum Subarray| [Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})| Easy | O(n)| O(n)||
+|62. Unique Paths | [Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})| Medium | O(n^2)| O(n^2)||
+|63. Unique Paths II | [Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})| Medium | O(n^2)| O(n^2)||
+|64. Minimum Path Sum | [Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})| Medium | O(n^2)| O(n^2)||
+|70. Climbing Stairs | [Go]({{< relref "/ChapterFour/0070.Climbing-Stairs.md" >}})| Easy | O(n)| O(n)||
+|91. Decode Ways | [Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})| Medium | O(n)| O(n)||
+|96. Unique Binary Search Trees | [Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})| Medium | O(n)| O(n)||
+|120. Triangle | [Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})| Medium | O(n^2)| O(n)||
+|121. Best Time to Buy and Sell Stock | [Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})| Easy | O(n)| O(1)||
+|152. Maximum Product Subarray | [Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})| Medium | O(n)| O(1)||
+|198. House Robber | [Go]({{< relref "/ChapterFour/0198.House-Robber.md" >}})| Easy | O(n)| O(n)||
+|213. House Robber II | [Go]({{< relref "/ChapterFour/0213.House-Robber-II.md" >}})| Medium | O(n)| O(n)||
+|300. Longest Increasing Subsequence | [Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})| Medium | O(n log n)| O(n)||
+|309. Best Time to Buy and Sell Stock with Cooldown | [Go]({{< relref "/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md" >}})| Medium | O(n)| O(n)||
+|322. Coin Change | [Go]({{< relref "/ChapterFour/0322.Coin-Change.md" >}})| Medium | O(n)| O(n)||
+|338. Counting Bits | [Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})| Medium | O(n)| O(n)||
+|343. Integer Break | [Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})| Medium | O(n^2)| O(n)||
+|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
+|392. Is Subsequence | [Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})| Medium | O(n)| O(1)||
+|416. Partition Equal Subset Sum | [Go]({{< relref "/ChapterFour/0416.Partition-Equal-Subset-Sum.md" >}})| Medium | O(n^2)| O(n)||
+|714. Best Time to Buy and Sell Stock with Transaction Fee | [Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})| Medium | O(n)| O(1)||
+|746. Min Cost Climbing Stairs | [Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})| Easy | O(n)| O(1)||
+|838. Push Dominoes | [Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})| Medium | O(n)| O(n)||
+|1025. Divisor Game | [Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})| Easy | O(1)| O(1)||
+|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
+|942. DI String Match | [Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})| Easy | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Hash_Table b/ctl/meta/Hash_Table
new file mode 100644
index 00000000..56a6bde0
--- /dev/null
+++ b/ctl/meta/Hash_Table
@@ -0,0 +1,33 @@
+|1. Two Sum | [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)||
+|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
+|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
+|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
+|36. Valid Sudoku | [Go]({{< relref "/ChapterFour/0036.Valid-Sudoku.md" >}})| Medium | O(n^2)| O(n^2)||
+|37. Sudoku Solver | [Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
+|49. Group Anagrams | [Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})| Medium | O(n log n)| O(n)||
+|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
+|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
+|138. Copy List with Random Pointer | [Go]()| Medium | O(n)| O(1)||
+|202. Happy Number | [Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})| Easy | O(log n)| O(1)||
+|205. Isomorphic Strings | [Go]({{< relref "/ChapterFour/0205.Isomorphic-Strings.md" >}})| Easy | O(log n)| O(n)||
+|217. Contains Duplicate | [Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})| Easy | O(n)| O(n)||
+|219. Contains Duplicate II | [Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})| Easy | O(n)| O(n)||
+|242. Valid Anagram | [Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})| Easy | O(n)| O(n) ||
+|274. H-Index | [Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})| Medium | O(n)| O(n) ||
+|290. Word Pattern | [Go]({{< relref "/ChapterFour/0290.Word-Pattern.md" >}})| Easy | O(n)| O(n) ||
+|347. Top K Frequent Elements | [Go]({{< relref "/ChapterFour/0347.Top-K-Frequent-Elements.md" >}})| Medium | O(n)| O(n) ||
+|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
+|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
+|438. Find All Anagrams in a String | [Go]({{< relref "/ChapterFour/0438.Find-All-Anagrams-in-a-String.md" >}})| Easy | O(n)| O(1) ||
+|447. Number of Boomerangs | [Go]({{< relref "/ChapterFour/0447.Number-of-Boomerangs.md" >}})| Easy | O(n)| O(1) ||
+|451. Sort Characters By Frequency | [Go]({{< relref "/ChapterFour/0451.Sort-Characters-By-Frequency.md" >}})| Medium | O(n log n)| O(1) ||
+|454. 4Sum II | [Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})| Medium | O(n^2)| O(n) ||
+|648. Replace Words | [Go]({{< relref "/ChapterFour/0648.Replace-Words.md" >}})| Medium | O(n)| O(n) ||
+|676. Implement Magic Dictionary | [Go]({{< relref "/ChapterFour/0676.Implement-Magic-Dictionary.md" >}})| Medium | O(n)| O(n) ||
+|720. Longest Word in Dictionary | [Go]({{< relref "/ChapterFour/0720.Longest-Word-in-Dictionary.md" >}})| Easy | O(n)| O(n) ||
+|726. Number of Atoms | [Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})| Hard | O(n)| O(n) |❤️|
+|739. Daily Temperatures | [Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})| Medium | O(n)| O(n) ||
+|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
+|895. Maximum Frequency Stack | [Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})| Hard | O(n)| O(n) ||
+|930. Binary Subarrays With Sum | [Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})| Medium | O(n)| O(n) |❤️|
+|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n) |❤️|
\ No newline at end of file
diff --git a/ctl/meta/Linked_List b/ctl/meta/Linked_List
new file mode 100644
index 00000000..326edc57
--- /dev/null
+++ b/ctl/meta/Linked_List
@@ -0,0 +1,29 @@
+|2. Add Two Numbers | [Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})| Medium | O(n)| O(1)||
+|19. Remove Nth Node From End of List | [Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})| Medium | O(n)| O(1)||
+|21. Merge Two Sorted Lists | [Go]({{< relref "/ChapterFour/0021.Merge-Two-Sorted-Lists.md" >}})| Easy | O(log n)| O(1)||
+|23. Merge k Sorted Lists| [Go]({{< relref "/ChapterFour/0023.Merge-k-Sorted-Lists.md" >}})| Hard | O(log n)| O(1)|❤️|
+|24. Swap Nodes in Pairs | [Go]({{< relref "/ChapterFour/0024.Swap-Nodes-in-Pairs.md" >}})| Medium | O(n)| O(1)||
+|25. Reverse Nodes in k-Group | [Go]({{< relref "/ChapterFour/0025.Reverse-Nodes-in-k-Group.md" >}})| Hard | O(log n)| O(1)|❤️|
+|61. Rotate List | [Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})| Medium | O(n)| O(1)||
+|82. Remove Duplicates from Sorted List II | [Go]({{< relref "/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md" >}})| Medium | O(n)| O(1)||
+|83. Remove Duplicates from Sorted List | [Go]({{< relref "/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md" >}})| Easy | O(n)| O(1)||
+|86. Partition List | [Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})| Medium | O(n)| O(1)|❤️|
+|92. Reverse Linked List II | [Go]({{< relref "/ChapterFour/0092.Reverse-Linked-List-II.md" >}})| Medium | O(n)| O(1)|❤️|
+|109. Convert Sorted List to Binary Search Tree | [Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})| Medium | O(log n)| O(n)||
+|141. Linked List Cycle | [Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})| Easy | O(n)| O(1)|❤️|
+|142. Linked List Cycle II | [Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})| Medium | O(n)| O(1)|❤️|
+|143. Reorder List | [Go]({{< relref "/ChapterFour/0143.Reorder-List.md" >}})| Medium | O(n)| O(1)|❤️|
+|147. Insertion Sort List | [Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})| Medium | O(n)| O(1)|❤️|
+|148. Sort List | [Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})| Medium | O(n log n)| O(n)|❤️|
+|160. Intersection of Two Linked Lists | [Go]({{< relref "/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md" >}})| Easy | O(n)| O(1)|❤️|
+|203. Remove Linked List Elements | [Go]({{< relref "/ChapterFour/0203.Remove-Linked-List-Elements.md" >}})| Easy | O(n)| O(1)||
+|206. Reverse Linked List | [Go]({{< relref "/ChapterFour/0206.Reverse-Linked-List.md" >}})| Easy | O(n)| O(1)||
+|234. Palindrome Linked List | [Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})| Easy | O(n)| O(1)||
+|237. Delete Node in a Linked List | [Go]({{< relref "/ChapterFour/0237.Delete-Node-in-a-Linked-List.md" >}})| Easy | O(n)| O(1)||
+|328. Odd Even Linked List | [Go]({{< relref "/ChapterFour/0328.Odd-Even-Linked-List.md" >}})| Medium | O(n)| O(1)||
+|445. Add Two Numbers II | [Go]({{< relref "/ChapterFour/0445.Add-Two-Numbers-II.md" >}})| Medium | O(n)| O(n)||
+|725. Split Linked List in Parts | [Go]({{< relref "/ChapterFour/0725.Split-Linked-List-in-Parts.md" >}})| Medium | O(n)| O(1)||
+|817. Linked List Components | [Go]({{< relref "/ChapterFour/0817.Linked-List-Components.md" >}})| Medium | O(n)| O(1)||
+|707. Design Linked List | [Go]({{< relref "/ChapterFour/0707.Design-Linked-List.md" >}})| Easy | O(n)| O(1)||
+|876. Middle of the Linked List | [Go]({{< relref "/ChapterFour/0876.Middle-of-the-Linked-List.md" >}})| Easy | O(n)| O(1)|❤️|
+|1019. Next Greater Node In Linked List | [Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})| Medium | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Math b/ctl/meta/Math
new file mode 100644
index 00000000..e7850955
--- /dev/null
+++ b/ctl/meta/Math
@@ -0,0 +1,18 @@
+|2. Add Two Numbers | [Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})| Medium | O(n)| O(1)||
+|50. Pow(x, n) | [Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})| Medium | O(log n)| O(1)||
+|60. Permutation Sequence | [Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})| Medium | O(n log n)| O(1)||
+|69. Sqrt(x) | [Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})| Easy | O(log n)| O(1)||
+|202. Happy Number | [Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})| Easy | O(log n)| O(1)||
+|224. Basic Calculator | [Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})| Hard | O(n)| O(n)||
+|231. Power of Two | [Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})| Easy | O(1)| O(1)||
+|263. Ugly Number | [Go]({{< relref "/ChapterFour/0263.Ugly-Number.md" >}})| Easy | O(log n)| O(1)||
+|326. Power of Three | [Go]({{< relref "/ChapterFour/0326.Power-of-Three.md" >}})| Easy | O(1)| O(1)||
+|343. Integer Break | [Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})| Medium | O(n^2)| O(n)||
+|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
+|628. Maximum Product of Three Numbers | [Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})| Easy | O(n)| O(1)||
+|885. Spiral Matrix III | [Go]({{< relref "/ChapterFour/0885.Spiral-Matrix-III.md" >}})| Medium | O(n^2)| O(1)||
+|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
+|942. DI String Match | [Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})| Easy | O(n)| O(1)||
+|976. Largest Perimeter Triangle | [Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})| Easy | O(n log n)| O(log n) ||
+|996. Number of Squareful Arrays | [Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})| Hard | O(n log n)| O(n) ||
+|1025. Divisor Game | [Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})| Easy | O(1)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/PDFPreface b/ctl/meta/PDFPreface
new file mode 100644
index 00000000..24bc7a3b
--- /dev/null
+++ b/ctl/meta/PDFPreface
@@ -0,0 +1,12 @@
+
+
+
+# 说明
+
+此版本是 https://books.halfrost.com/leetcode 网页的离线版,由于网页版实时会更新,所以此 PDF 版难免会有一些排版或者错别字。如果读者遇到了,可以到网页版相应页面,点击页面 edit 按钮,提交 pr 进行更改。此 PDF 版本号是 V1.5.20。PDF 永久更新地址是 https://github.com/halfrost/LeetCode-Go/releases/,以版本号区分不同版本。笔者还是强烈推荐看在线版,有任何错误都会立即更新。如果觉得此书对刷题有一点点帮助,可以给此书点一个 star,鼓励一下笔者早点更新更多题解。
+
+> 版本号说明,V1.5.20,1 是大版本号,5 代表当前题解中有几百题,目前是 520 题,所以第二个版本号是 5,20 代表当前题解中有几十题,目前是 520 题,所以第三个版本号是 20 。
+
+# 目录
+
+[toc]
\ No newline at end of file
diff --git a/ctl/meta/Segment_Tree b/ctl/meta/Segment_Tree
new file mode 100644
index 00000000..0e7f9c74
--- /dev/null
+++ b/ctl/meta/Segment_Tree
@@ -0,0 +1,10 @@
+|218. The Skyline Problem | [Go]({{< relref "/ChapterFour/0218.The-Skyline-Problem.md" >}})| Hard | O(n log n)| O(n)|❤️|
+|307. Range Sum Query - Mutable | [Go]({{< relref "/ChapterFour/0307.Range-Sum-Query---Mutable.md" >}})| Hard | O(1)| O(n)||
+|315. Count of Smaller Numbers After Self | [Go]({{< relref "/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md" >}})| Hard | O(n log n)| O(n)||
+|327. Count of Range Sum | [Go]({{< relref "/ChapterFour/0327.Count-of-Range-Sum.md" >}})| Hard | O(n log n)| O(n)|❤️|
+|493. Reverse Pairs | [Go]({{< relref "/ChapterFour/0493.Reverse-Pairs.md" >}})| Hard | O(n log n)| O(n)||
+|699. Falling Squares | [Go]({{< relref "/ChapterFour/0699.Falling-Squares.md" >}})| Hard | O(n log n)| O(n)|❤️|
+|715. Range Module | [Go]({{< relref "/ChapterFour/0715.Range-Module.md" >}})| Hard | O(log n)| O(n)|❤️|
+|732. My Calendar III | [Go]({{< relref "/ChapterFour/0732.My-Calendar-III.md" >}})| Hard | O(log n)| O(n)|❤️|
+|850. Rectangle Area II | [Go]({{< relref "/ChapterFour/0850.Rectangle-Area-II.md" >}})| Hard | O(n log n)| O(n)|❤️|
+|1157. Online Majority Element In Subarray | [Go]({{< relref "/ChapterFour/1157.Online-Majority-Element-In-Subarray.md" >}})| Hard | O(log n)| O(n)|❤️|
\ No newline at end of file
diff --git a/ctl/meta/Sliding_Window b/ctl/meta/Sliding_Window
new file mode 100644
index 00000000..e3ec8c4a
--- /dev/null
+++ b/ctl/meta/Sliding_Window
@@ -0,0 +1,13 @@
+|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
+|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
+|239. Sliding Window Maximum | [Go]({{< relref "/ChapterFour/0239.Sliding-Window-Maximum.md" >}})| Hard | O(n * k)| O(n)|❤️|
+|424. Longest Repeating Character Replacement | [Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})| Medium | O(n)| O(1) ||
+|480. Sliding Window Median | [Go]({{< relref "/ChapterFour/0480.Sliding-Window-Median.md" >}})| Hard | O(n * log k)| O(k)|❤️|
+|567. Permutation in String | [Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})| Medium | O(n)| O(1)|❤️|
+|978. Longest Turbulent Subarray | [Go]({{< relref "/ChapterFour/0978.Longest-Turbulent-Subarray.md" >}})| Medium | O(n)| O(1)|❤️|
+|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n)|❤️|
+|995. Minimum Number of K Consecutive Bit Flips | [Go]({{< relref "/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md" >}})| Hard | O(n)| O(1)|❤️|
+|1004. Max Consecutive Ones III | [Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})| Medium | O(n)| O(1) ||
+|1040. Moving Stones Until Consecutive II | [Go]({{< relref "/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md" >}})| Medium | O(n log n)| O(1) |❤️|
+|1052. Grumpy Bookstore Owner | [Go]({{< relref "/ChapterFour/1052.Grumpy-Bookstore-Owner.md" >}})| Medium | O(n log n)| O(1) ||
+|1074. Number of Submatrices That Sum to Target | [Go]({{< relref "/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})| Hard | O(n^3)| O(n) |❤️|
\ No newline at end of file
diff --git a/ctl/meta/Sort b/ctl/meta/Sort
new file mode 100644
index 00000000..cf944272
--- /dev/null
+++ b/ctl/meta/Sort
@@ -0,0 +1,23 @@
+|56. Merge Intervals | [Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})| Medium | O(n log n)| O(log n)||
+|57. Insert Interval | [Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})| Hard | O(n)| O(1)||
+|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
+|147. Insertion Sort List | [Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})| Medium | O(n)| O(1) |❤️|
+|148. Sort List | [Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})| Medium |O(n log n)| O(log n)|❤️|
+|164. Maximum Gap | [Go]({{< relref "/ChapterFour/0164.Maximum-Gap.md" >}})| Hard | O(n log n)| O(log n) |❤️|
+|179. Largest Number | [Go]({{< relref "/ChapterFour/0179.Largest-Number.md" >}})| Medium | O(n log n)| O(log n) |❤️|
+|220. Contains Duplicate III | [Go]({{< relref "/ChapterFour/0220.Contains-Duplicate-III.md" >}})| Medium | O(n log n)| O(1) |❤️|
+|242. Valid Anagram | [Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})| Easy | O(n)| O(n) ||
+|274. H-Index | [Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})| Medium | O(n)| O(n) ||
+|324. Wiggle Sort II | [Go]({{< relref "/ChapterFour/0324.Wiggle-Sort-II.md" >}})| Medium| O(n)| O(n)|❤️|
+|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
+|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
+|524. Longest Word in Dictionary through Deleting | [Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})| Medium | O(n)| O(1) ||
+|767. Reorganize String | [Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})| Medium | O(n log n)| O(log n) |❤️|
+|853. Car Fleet | [Go]({{< relref "/ChapterFour/0853.Car-Fleet.md" >}})| Medium | O(n log n)| O(log n) ||
+|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
+|922. Sort Array By Parity II | [Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})| Easy | O(n)| O(1) ||
+|969. Pancake Sorting | [Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})| Medium | O(n log n)| O(log n) |❤️|
+|973. K Closest Points to Origin | [Go]({{< relref "/ChapterFour/0973.K-Closest-Points-to-Origin.md" >}})| Medium | O(n log n)| O(log n) ||
+|976. Largest Perimeter Triangle | [Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})| Easy | O(n log n)| O(log n) ||
+|1030. Matrix Cells in Distance Order | [Go]({{< relref "/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md" >}})| Easy | O(n^2)| O(1) ||
+|1054. Distant Barcodes | [Go]({{< relref "/ChapterFour/1054.Distant-Barcodes.md" >}})| Medium | O(n log n)| O(log n) |❤️|
\ No newline at end of file
diff --git a/ctl/meta/Stack b/ctl/meta/Stack
new file mode 100644
index 00000000..a145368c
--- /dev/null
+++ b/ctl/meta/Stack
@@ -0,0 +1,37 @@
+|20. Valid Parentheses | [Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})| Easy | O(log n)| O(1)||
+|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
+|71. Simplify Path | [Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})| Medium | O(n)| O(n)|❤️|
+|84. Largest Rectangle in Histogram | [Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})| Medium | O(n)| O(n)|❤️|
+|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
+|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
+|144. Binary Tree Preorder Traversal | [Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})| Medium | O(n)| O(1)||
+|145. Binary Tree Postorder Traversal | [Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})| Hard | O(n)| O(1)||
+|150. Evaluate Reverse Polish Notation | [Go]({{< relref "/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md" >}})| Medium | O(n)| O(1)||
+|155. Min Stack | [Go]({{< relref "/ChapterFour/0155.Min-Stack.md" >}})| Easy | O(n)| O(n)||
+|173. Binary Search Tree Iterator | [Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})| Medium | O(n)| O(1)||
+|224. Basic Calculator | [Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})| Hard | O(n)| O(n)||
+|225. Implement Stack using Queues | [Go]({{< relref "/ChapterFour/0225.Implement-Stack-using-Queues.md" >}})| Easy | O(n)| O(n)||
+|232. Implement Queue using Stacks | [Go]({{< relref "/ChapterFour/0232.Implement-Queue-using-Stacks.md" >}})| Easy | O(n)| O(n)||
+|331. Verify Preorder Serialization of a Binary Tree | [Go]({{< relref "/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md" >}})| Medium | O(n)| O(1)||
+|394. Decode String | [Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})| Medium | O(n)| O(n)||
+|402. Remove K Digits | [Go]({{< relref "/ChapterFour/0402.Remove-K-Digits.md" >}})| Medium | O(n)| O(1)||
+|456. 132 Pattern | [Go]({{< relref "/ChapterFour/0456.132-Pattern.md" >}})| Medium | O(n)| O(n)||
+|496. Next Greater Element I | [Go]({{< relref "/ChapterFour/0496.Next-Greater-Element-I.md" >}})| Easy | O(n)| O(n)||
+|503. Next Greater Element II | [Go]({{< relref "/ChapterFour/0503.Next-Greater-Element-II.md" >}})| Medium | O(n)| O(n)||
+|636. Exclusive Time of Functions | [Go]({{< relref "/ChapterFour/0636.Exclusive-Time-of-Functions.md" >}})| Medium | O(n)| O(n)||
+|682. Baseball Game | [Go]({{< relref "/ChapterFour/0682.Baseball-Game.md" >}})| Easy | O(n)| O(n)||
+|726. Number of Atoms | [Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})| Hard | O(n)| O(n) |❤️|
+|735. Asteroid Collision | [Go]({{< relref "/ChapterFour/0735.Asteroid-Collision.md" >}})| Medium | O(n)| O(n) ||
+|739. Daily Temperatures | [Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})| Medium | O(n)| O(n) ||
+|844. Backspace String Compare | [Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})| Easy | O(n)| O(n) ||
+|856. Score of Parentheses | [Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})| Medium | O(n)| O(n)||
+|880. Decoded String at Index | [Go]({{< relref "/ChapterFour/0880.Decoded-String-at-Index.md" >}})| Medium | O(n)| O(n)||
+|895. Maximum Frequency Stack | [Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})| Hard | O(n)| O(n) ||
+|901. Online Stock Span | [Go]({{< relref "/ChapterFour/0901.Online-Stock-Span.md" >}})| Medium | O(n)| O(n) ||
+|907. Sum of Subarray Minimums | [Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})| Medium | O(n)| O(n)|❤️|
+|921. Minimum Add to Make Parentheses Valid | [Go]({{< relref "/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md" >}})| Medium | O(n)| O(n)||
+|946. Validate Stack Sequences | [Go]({{< relref "/ChapterFour/0946.Validate-Stack-Sequences.md" >}})| Medium | O(n)| O(n)||
+|1003. Check If Word Is Valid After Substitutions | [Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})| Medium | O(n)| O(1)||
+|1019. Next Greater Node In Linked List | [Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})| Medium | O(n)| O(1)||
+|1021. Remove Outermost Parentheses | [Go]({{< relref "/ChapterFour/1021.Remove-Outermost-Parentheses.md" >}})| Medium | O(n)| O(1)||
+|1047. Remove All Adjacent Duplicates In String | [Go]({{< relref "/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md" >}})| Medium | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/String b/ctl/meta/String
new file mode 100644
index 00000000..e2d905f7
--- /dev/null
+++ b/ctl/meta/String
@@ -0,0 +1,20 @@
+|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
+|17. Letter Combinations of a Phone Number | [Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})| Medium | O(log n)| O(1)||
+|20. Valid Parentheses | [Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})| Easy | O(log n)| O(1)||
+|22. Generate Parentheses | [Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})| Medium | O(log n)| O(1)||
+|28. Implement strStr() | [Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})| Easy | O(n)| O(1)||
+|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
+|49. Group Anagrams | [Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})| Medium | O(n log n)| O(n)||
+|71. Simplify Path | [Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})| Medium | O(n)| O(n)||
+|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
+|91. Decode Ways | [Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})| Medium | O(n)| O(n)||
+|93. Restore IP Addresses | [Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})| Medium | O(n)| O(n)|❤️|
+|125. Valid Palindrome | [Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})| Easy | O(n)| O(1)||
+|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
+|344. Reverse String | [Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})| Easy | O(n)| O(1)||
+|345. Reverse Vowels of a String | [Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})| Easy | O(n)| O(1)||
+|767. Reorganize String | [Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})| Medium | O(n log n)| O(log n) |❤️|
+|842. Split Array into Fibonacci Sequence | [Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})| Medium | O(n^2)| O(1)|❤️|
+|856. Score of Parentheses | [Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})| Medium | O(n)| O(n)||
+|925. Long Pressed Name | [Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})| Easy | O(n)| O(1)||
+|1003. Check If Word Is Valid After Substitutions | [Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})| Medium | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Tree b/ctl/meta/Tree
new file mode 100644
index 00000000..ce2a837b
--- /dev/null
+++ b/ctl/meta/Tree
@@ -0,0 +1,33 @@
+|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
+|96. Unique Binary Search Trees | [Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})| Medium | O(n^2)| O(n)||
+|98. Validate Binary Search Tree | [Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})| Medium | O(n)| O(1)||
+|99. Recover Binary Search Tree | [Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})| Hard | O(n)| O(1)||
+|100. Same Tree | [Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})| Easy | O(n)| O(1)||
+|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
+|102. Binary Tree Level Order Traversal | [Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})| Medium | O(n)| O(1)||
+|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
+|104. Maximum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|107. Binary Tree Level Order Traversal II | [Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})| Easy | O(n)| O(1)||
+|108. Convert Sorted Array to Binary Search Tree | [Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
+|110. Balanced Binary Tree | [Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|112. Path Sum | [Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})| Easy | O(n)| O(1)||
+|113. Path Sum II | [Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})| Medium | O(n)| O(1)||
+|114. Flatten Binary Tree to Linked List | [Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})| Medium | O(n)| O(1)||
+|124. Binary Tree Maximum Path Sum | [Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})| Hard | O(n)| O(1)||
+|129. Sum Root to Leaf Numbers | [Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})| Medium | O(n)| O(1)||
+|144. Binary Tree Preorder Traversal | [Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})| Medium | O(n)| O(1)||
+|145. Binary Tree Postorder Traversal | [Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})| Hard | O(n)| O(1)||
+|173. Binary Search Tree Iterator | [Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})| Medium | O(n)| O(1)||
+|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
+|222. Count Complete Tree Nodes | [Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})| Medium | O(n)| O(1)||
+|226. Invert Binary Tree | [Go]({{< relref "/ChapterFour/0226.Invert-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
+|230. Kth Smallest Element in a BST | [Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})| Medium | O(n)| O(1)||
+|235. Lowest Common Ancestor of a Binary Search Tree | [Go]({{< relref "/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
+|236. Lowest Common Ancestor of a Binary Tree | [Go]({{< relref "/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md" >}})| Medium | O(n)| O(1)||
+|257. Binary Tree Paths | [Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})| Easy | O(n)| O(1)||
+|404. Sum of Left Leaves | [Go]({{< relref "/ChapterFour/0404.Sum-of-Left-Leaves.md" >}})| Easy | O(n)| O(1)||
+|437. Path Sum III | [Go]({{< relref "/ChapterFour/0437.Path-Sum-III.md" >}})| Easy | O(n)| O(1)||
+|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
+|637. Average of Levels in Binary Tree | [Go]({{< relref "/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md" >}})| Easy | O(n)| O(n)||
+|993. Cousins in Binary Tree | [Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
\ No newline at end of file
diff --git a/ctl/meta/Two_Pointers b/ctl/meta/Two_Pointers
new file mode 100644
index 00000000..2c238556
--- /dev/null
+++ b/ctl/meta/Two_Pointers
@@ -0,0 +1,50 @@
+|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
+|11. Container With Most Water | [Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})| Medium | O(n)| O(1)||
+|15. 3Sum | [Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})| Medium | O(n^2)| O(n)|❤️|
+|16. 3Sum Closest | [Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})| Medium | O(n^2)| O(1)|❤️|
+|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
+|19. Remove Nth Node From End of List | [Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})| Medium | O(n)| O(1)||
+|26. Remove Duplicates from Sorted Array | [Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
+|27. Remove Element | [Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})| Easy | O(n)| O(1)||
+|28. Implement strStr() | [Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})| Easy | O(n)| O(1)||
+|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
+|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
+|61. Rotate List | [Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})| Medium | O(n)| O(1)||
+|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
+|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
+|80. Remove Duplicates from Sorted Array II | [Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})| Medium | O(n)| O(1||
+|86. Partition List | [Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})| Medium | O(n)| O(1)|❤️|
+|88. Merge Sorted Array | [Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})| Easy | O(n)| O(1)|❤️|
+|125. Valid Palindrome | [Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})| Easy | O(n)| O(1)||
+|141. Linked List Cycle | [Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})| Easy | O(n)| O(1)|❤️|
+|142. Linked List Cycle II | [Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})| Medium | O(n)| O(1)|❤️|
+|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
+|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
+|234. Palindrome Linked List | [Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})| Easy | O(n)| O(1)||
+|283. Move Zeroes | [Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})| Easy | O(n)| O(1)||
+|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
+|344. Reverse String | [Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})| Easy | O(n)| O(1)||
+|345. Reverse Vowels of a String | [Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})| Easy | O(n)| O(1)||
+|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
+|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
+|424. Longest Repeating Character Replacement | [Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})| Medium | O(n)| O(1) ||
+|524. Longest Word in Dictionary through Deleting | [Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})| Medium | O(n)| O(1) ||
+|532. K-diff Pairs in an Array | [Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})| Easy | O(n)| O(n)||
+|567. Permutation in String | [Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})| Medium | O(n)| O(1)|❤️|
+|713. Subarray Product Less Than K | [Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})| Medium | O(n)| O(1)||
+|763. Partition Labels | [Go]({{< relref "/ChapterFour/0763.Partition-Labels.md" >}})| Medium | O(n)| O(1)|❤️|
+|826. Most Profit Assigning Work | [Go]({{< relref "/ChapterFour/0826.Most-Profit-Assigning-Work.md" >}})| Medium | O(n log n)| O(n)||
+|828. Count Unique Characters of All Substrings of a Given String | [Go]({{< relref "/ChapterFour/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.md" >}})| Hard | O(n)| O(1)|❤️|
+|838. Push Dominoes | [Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})| Medium | O(n)| O(n)||
+|844. Backspace String Compare | [Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})| Easy | O(n)| O(n) ||
+|845. Longest Mountain in Array | [Go]({{< relref "/ChapterFour/0845.Longest-Mountain-in-Array.md" >}})| Medium | O(n)| O(1) ||
+|881. Boats to Save People | [Go]({{< relref "/ChapterFour/0881.Boats-to-Save-People.md" >}})| Medium | O(n log n)| O(1) ||
+|904. Fruit Into Baskets | [Go]({{< relref "/ChapterFour/0904.Fruit-Into-Baskets.md" >}})| Medium | O(n log n)| O(1) ||
+|923. 3Sum With Multiplicity | [Go]({{< relref "/ChapterFour/0923.3Sum-With-Multiplicity.md" >}})| Medium | O(n^2)| O(n) ||
+|925. Long Pressed Name | [Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})| Easy | O(n)| O(1)||
+|930. Binary Subarrays With Sum | [Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})| Medium | O(n)| O(n) |❤️|
+|977. Squares of a Sorted Array | [Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
+|986. Interval List Intersections | [Go]({{< relref "/ChapterFour/0986.Interval-List-Intersections.md" >}})| Medium | O(n)| O(1)||
+|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n)|❤️|
+|1004. Max Consecutive Ones III | [Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})| Medium | O(n)| O(1) ||
+|1093. Statistics from a Large Sample | [Go]({{< relref "/ChapterFour/1093.Statistics-from-a-Large-Sample.md" >}})| Medium | O(n)| O(1) ||
\ No newline at end of file
diff --git a/ctl/meta/Union_Find b/ctl/meta/Union_Find
new file mode 100644
index 00000000..66424cf4
--- /dev/null
+++ b/ctl/meta/Union_Find
@@ -0,0 +1,18 @@
+|128. Longest Consecutive Sequence | [Go]({{< relref "/ChapterFour/0128.Longest-Consecutive-Sequence.md" >}})| Hard | O(n)| O(n)|❤️|
+|130. Surrounded Regions | [Go]({{< relref "/ChapterFour/0130.Surrounded-Regions.md" >}})| Medium | O(m\*n)| O(m\*n)||
+|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(m\*n)| O(m\*n)||
+|399. Evaluate Division | [Go]({{< relref "/ChapterFour/0399.Evaluate-Division.md" >}})| Medium | O(n)| O(n)||
+|547. Number of Provinces | [Go]({{< relref "/ChapterFour/0547.Number-of-Provinces.md" >}})| Medium | O(n^2)| O(n)||
+|684. Redundant Connection | [Go]({{< relref "/ChapterFour/0684.Redundant-Connection.md" >}})| Medium | O(n)| O(n)||
+|685. Redundant Connection II | [Go]({{< relref "/ChapterFour/0685.Redundant-Connection-II.md" >}})| Hard | O(n)| O(n)||
+|721. Accounts Merge | [Go]({{< relref "/ChapterFour/0721.Accounts-Merge.md" >}})| Medium | O(n)| O(n)|❤️|
+|765. Couples Holding Hands | [Go]({{< relref "/ChapterFour/0765.Couples-Holding-Hands.md" >}})| Hard | O(n)| O(n)|❤️|
+|778. Swim in Rising Water | [Go]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})| Hard | O(n^2)| O(n)|❤️|
+|803. Bricks Falling When Hit | [Go]({{< relref "/ChapterFour/0803.Bricks-Falling-When-Hit.md" >}})| Hard | O(n^2)| O(n)|❤️|
+|839. Similar String Groups | [Go]({{< relref "/ChapterFour/0839.Similar-String-Groups.md" >}})| Hard | O(n^2)| O(n)||
+|924. Minimize Malware Spread | [Go]({{< relref "/ChapterFour/0924.Minimize-Malware-Spread.md" >}})| Hard | O(m\*n)| O(n)||
+|928. Minimize Malware Spread II | [Go]({{< relref "/ChapterFour/0928.Minimize-Malware-Spread-II.md" >}})| Hard | O(m\*n)| O(n)|❤️|
+|947. Most Stones Removed with Same Row or Column | [Go]({{< relref "/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md" >}})| Medium | O(n)| O(n)||
+|952. Largest Component Size by Common Factor | [Go]({{< relref "/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md" >}})| Hard | O(n)| O(n)|❤️|
+|959. Regions Cut By Slashes | [Go]({{< relref "/ChapterFour/0959.Regions-Cut-By-Slashes.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
+|990. Satisfiability of Equality Equations | [Go]({{< relref "/ChapterFour/0990.Satisfiability-of-Equality-Equations.md" >}})| Medium | O(n)| O(n)||
\ No newline at end of file
diff --git a/ctl/meta/meta b/ctl/meta/meta
new file mode 100644
index 00000000..a28e1a67
--- /dev/null
+++ b/ctl/meta/meta
@@ -0,0 +1,2 @@
+| Title | Solution | Difficulty | Time | Space |收藏|
+| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
\ No newline at end of file
diff --git a/ctl/models/lcproblems.go b/ctl/models/lcproblems.go
new file mode 100644
index 00000000..3851eea3
--- /dev/null
+++ b/ctl/models/lcproblems.go
@@ -0,0 +1,103 @@
+package models
+
+import (
+ "fmt"
+)
+
+// LeetCodeProblemAll define
+type LeetCodeProblemAll struct {
+ UserName string `json:"user_name"`
+ NumSolved int32 `json:"num_solved"`
+ NumTotal int32 `json:"num_total"`
+ AcEasy int32 `json:"ac_easy"`
+ AcMedium int32 `json:"ac_medium"`
+ AcHard int32 `json:"ac_hard"`
+ StatStatusPairs []StatStatusPairs `json:"stat_status_pairs"`
+ FrequencyHigh int32 `json:"frequency_high"`
+ FrequencyMid int32 `json:"frequency_mid"`
+ CategorySlug string `json:"category_slug"`
+ AcEasyTotal int32
+ AcMediumTotal int32
+ AcHardTotal int32
+}
+
+// ConvertUserInfoModel define
+func ConvertUserInfoModel(lpa LeetCodeProblemAll) UserInfo {
+ info := UserInfo{}
+ info.UserName = lpa.UserName
+ info.NumSolved = lpa.NumSolved
+ info.NumTotal = lpa.NumTotal
+ info.AcEasy = lpa.AcEasy
+ info.AcMedium = lpa.AcMedium
+ info.AcHard = lpa.AcHard
+ info.FrequencyHigh = lpa.FrequencyHigh
+ info.FrequencyMid = lpa.FrequencyMid
+ info.CategorySlug = lpa.CategorySlug
+ return info
+}
+
+// StatStatusPairs define
+type StatStatusPairs struct {
+ Stat Stat `json:"stat"`
+ Status string `json:"status"`
+ Difficulty Difficulty `json:"difficulty"`
+ PaidOnly bool `json:"paid_only"`
+ IsFavor bool `json:"is_favor"`
+ Frequency float64 `json:"frequency"`
+ Progress float64 `json:"progress"`
+}
+
+// ConvertMdModelFromSsp define
+func ConvertMdModelFromSsp(problems []StatStatusPairs) []Mdrow {
+ mdrows := []Mdrow{}
+ for _, problem := range problems {
+ res := Mdrow{}
+ res.FrontendQuestionID = problem.Stat.FrontendQuestionID
+ res.QuestionTitle = problem.Stat.QuestionTitle
+ res.QuestionTitleSlug = problem.Stat.QuestionTitleSlug
+ res.Acceptance = fmt.Sprintf("%.1f%%", (problem.Stat.TotalAcs/problem.Stat.TotalSubmitted)*100)
+ res.Difficulty = DifficultyMap[problem.Difficulty.Level]
+ res.Frequency = fmt.Sprintf("%f", problem.Frequency)
+ mdrows = append(mdrows, res)
+ }
+ return mdrows
+}
+
+// ConvertMdModelFromIds define
+func ConvertMdModelFromIds(problemsMap map[int]StatStatusPairs, ids []int) []Mdrow {
+ mdrows := []Mdrow{}
+ for _, v := range ids {
+ res, problem := Mdrow{}, problemsMap[v]
+ res.FrontendQuestionID = problem.Stat.FrontendQuestionID
+ res.QuestionTitle = problem.Stat.QuestionTitle
+ res.QuestionTitleSlug = problem.Stat.QuestionTitleSlug
+ res.Acceptance = fmt.Sprintf("%.1f%%", (problem.Stat.TotalAcs/problem.Stat.TotalSubmitted)*100)
+ res.Difficulty = DifficultyMap[problem.Difficulty.Level]
+ res.Frequency = fmt.Sprintf("%f", problem.Frequency)
+ mdrows = append(mdrows, res)
+ }
+ return mdrows
+}
+
+// Stat define
+type Stat struct {
+ QuestionTitle string `json:"question__title"`
+ QuestionTitleSlug string `json:"question__title_slug"`
+ TotalAcs float64 `json:"total_acs"`
+ TotalSubmitted float64 `json:"total_submitted"`
+ Acceptance string
+ Difficulty string
+ FrontendQuestionID int32 `json:"frontend_question_id"`
+}
+
+// Difficulty define
+type Difficulty struct {
+ Level int32 `json:"level"`
+}
+
+// DifficultyMap define
+var DifficultyMap = map[int32]string{
+ 1: "Easy",
+ 2: "Medium",
+ 3: "Hard",
+}
diff --git a/ctl/models/mdrow.go b/ctl/models/mdrow.go
new file mode 100644
index 00000000..ba200889
--- /dev/null
+++ b/ctl/models/mdrow.go
@@ -0,0 +1,67 @@
+package models
+
+import (
+ "fmt"
+ "strings"
+)
+
+// Mdrow define
+type Mdrow struct {
+ FrontendQuestionID int32 `json:"question_id"`
+ QuestionTitle string `json:"question__title"`
+ QuestionTitleSlug string `json:"question__title_slug"`
+ SolutionPath string `json:"solution_path"`
+ Acceptance string `json:"acceptance"`
+ Difficulty string `json:"difficulty"`
+ Frequency string `json:"frequency"`
+}
+
+// GenerateMdRows define
+func GenerateMdRows(solutionIds []int, mdrows []Mdrow) {
+ for i := 0; i < len(solutionIds); i++ {
+ id := mdrows[solutionIds[i]-1].FrontendQuestionID
+ if solutionIds[i] == int(id) {
+ //fmt.Printf("id = %v i = %v solutionIds = %v\n", id, i, solutionIds[i])
+ mdrows[id-1].SolutionPath = fmt.Sprintf("[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/%v)", fmt.Sprintf("%04d.%v", id, strings.Replace(mdrows[id-1].QuestionTitle, " ", "-", -1)))
+ } else {
+ fmt.Printf("序号出错了 solutionIds = %v id = %v\n", solutionIds[i], id)
+ }
+ }
+}
+
+// | 0001 | Two Sum | [Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0001.Two-Sum)| 45.6% | Easy | |
+func (m Mdrow) tableLine() string {
+ return fmt.Sprintf("|%04d|%v|%v|%v|%v||\n", m.FrontendQuestionID, m.QuestionTitle, m.SolutionPath, m.Acceptance, m.Difficulty)
+}
+
+// SortByQuestionID define
+type SortByQuestionID []Mdrow
+
+func (a SortByQuestionID) Len() int { return len(a) }
+func (a SortByQuestionID) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+func (a SortByQuestionID) Less(i, j int) bool {
+ return a[i].FrontendQuestionID < a[j].FrontendQuestionID
+}
+
+// Mdrows define
+type Mdrows struct {
+ Mdrows []Mdrow
+}
+
+// | No. | Title | Solution | Acceptance | Difficulty | Frequency |
+// |:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
+func (mds Mdrows) table() string {
+ res := "| No. | Title | Solution | Acceptance | Difficulty | Frequency |\n"
+ res += "|:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|\n"
+ for _, p := range mds.Mdrows {
+ res += p.tableLine()
+ }
+ // 加这一行是为了撑开整个表格
+ res += "|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|"
+ return res
+}
+
+// AvailableTable define
+func (mds Mdrows) AvailableTable() string {
+ return mds.table()
+}
diff --git a/ctl/models/tagproblem.go b/ctl/models/tagproblem.go
new file mode 100644
index 00000000..f5cfbd5b
--- /dev/null
+++ b/ctl/models/tagproblem.go
@@ -0,0 +1,254 @@
+package models
+
+import (
+ "encoding/json"
+ "fmt"
+ "github.com/halfrost/LeetCode-Go/ctl/util"
+ "strconv"
+ "strings"
+)
+
+// Graphql define
+type Graphql struct {
+ OperationName string `json:"operationName"`
+ Variables struct {
+ TitleSlug string `json:"titleSlug"`
+ } `json:"variables"`
+ Query string `json:"query"`
+}
+
+// GraphQLResp define
+type GraphQLResp struct {
+ Data struct {
+ TopicTag TopicTag `json:"topicTag"`
+ FavoritesLists FavoritesLists `json:"favoritesLists"`
+ } `json:"data"`
+}
+
+// TopicTag define
+type TopicTag struct {
+ Name string `json:"name"`
+ TranslatedName string `json:"translatedName"`
+ Slug string `json:"slug"`
+ Questions []Question `json:"questions"`
+ Frequencies float64 `json:"frequencies"`
+ Typename string `json:"__typename"`
+}
+
+// Question define
+type Question struct {
+ Status string `json:"status"`
+ QuestionID string `json:"questionId"`
+ QuestionFrontendID string `json:"questionFrontendId"`
+ Title string `json:"title"`
+ TitleSlug string `json:"titleSlug"`
+ TranslatedTitle string `json:"translatedTitle"`
+ Stats string `json:"stats"`
+ Difficulty string `json:"difficulty"`
+ TopicTags []TopicTags `json:"topicTags"`
+ CompanyTags interface{} `json:"companyTags"`
+ Typename string `json:"__typename"`
+}
+
+// TopicTags define
+type TopicTags struct {
+ Name string `json:"name"`
+ TranslatedName string `json:"translatedName"`
+ Slug string `json:"slug"`
+ Typename string `json:"__typename"`
+}
+
+func (q Question) generateTagStatus() (TagStatus, error) {
+ var ts TagStatus
+ err := json.Unmarshal([]byte(q.Stats), &ts)
+ if err != nil {
+ fmt.Println(err)
+ return ts, err
+ }
+ return ts, nil
+}
+
+// TagStatus define
+type TagStatus struct {
+ TotalAccepted string `json:"totalAccepted"`
+ TotalSubmission string `json:"totalSubmission"`
+ TotalAcceptedRaw int32 `json:"totalAcceptedRaw"`
+ TotalSubmissionRaw int32 `json:"totalSubmissionRaw"`
+ AcRate string `json:"acRate"`
+}
+
+// ConvertMdModelFromQuestions define
+func ConvertMdModelFromQuestions(questions []Question) []Mdrow {
+ mdrows := []Mdrow{}
+ for _, question := range questions {
+ res := Mdrow{}
+ v, _ := strconv.Atoi(question.QuestionFrontendID)
+ res.FrontendQuestionID = int32(v)
+ res.QuestionTitle = question.Title
+ res.QuestionTitleSlug = question.TitleSlug
+ q, err := question.generateTagStatus()
+ if err != nil {
+ fmt.Println(err)
+ }
+ res.Acceptance = q.AcRate
+ res.Difficulty = question.Difficulty
+ mdrows = append(mdrows, res)
+ }
+ return mdrows
+}
+
+// TagList define
+type TagList struct {
+ FrontendQuestionID int32 `json:"question_id"`
+ QuestionTitle string `json:"question__title"`
+ SolutionPath string `json:"solution_path"`
+ Acceptance string `json:"acceptance"`
+ Difficulty string `json:"difficulty"`
+ TimeComplexity string `json:"time_complexity"`
+ SpaceComplexity string `json:"space_complexity"`
+ Favorite string `json:"favorite"`
+}
+
+// | 0001 | Two Sum | [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)|❤️|50%|
+func (t TagList) tableLine() string {
+ return fmt.Sprintf("|%04d|%v|%v|%v|%v|%v|%v|%v|\n", t.FrontendQuestionID, t.QuestionTitle, t.SolutionPath, t.Difficulty, t.TimeComplexity, t.SpaceComplexity, t.Favorite, t.Acceptance)
+}
+
+// GenerateTagMdRows define
+func GenerateTagMdRows(solutionIds []int, metaMap map[int]TagList, mdrows []Mdrow, internal bool) []TagList {
+ tl := []TagList{}
+ for _, row := range mdrows {
+ if util.BinarySearch(solutionIds, int(row.FrontendQuestionID)) != -1 {
+ tmp := TagList{}
+ tmp.FrontendQuestionID = row.FrontendQuestionID
+ tmp.QuestionTitle = row.QuestionTitle
+ s1 := strings.Replace(row.QuestionTitle, " ", "-", -1)
+ s2 := strings.Replace(s1, "'", "", -1)
+ s3 := strings.Replace(s2, "%", "", -1)
+ s4 := strings.Replace(s3, "(", "", -1)
+ s5 := strings.Replace(s4, ")", "", -1)
+ s6 := strings.Replace(s5, ",", "", -1)
+ s7 := strings.Replace(s6, "?", "", -1)
+ if internal {
+ tmp.SolutionPath = fmt.Sprintf("[Go]({{< relref \"/ChapterFour/%v.md\" >}})", fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7))
+ } else {
+ tmp.SolutionPath = fmt.Sprintf("[Go](https://books.halfrost.com/leetcode/ChapterFour/%v)", fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7))
+ }
+ tmp.Acceptance = row.Acceptance
+ tmp.Difficulty = row.Difficulty
+ tmp.TimeComplexity = metaMap[int(row.FrontendQuestionID)].TimeComplexity
+ tmp.SpaceComplexity = metaMap[int(row.FrontendQuestionID)].SpaceComplexity
+ tmp.Favorite = metaMap[int(row.FrontendQuestionID)].Favorite
+ tl = append(tl, tmp)
+ }
+ }
+ return tl
+}
+
+// TagLists define
+type TagLists struct {
+ TagLists []TagList
+}
+
+//| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+//|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+func (tls TagLists) table() string {
+ res := "| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |\n"
+ res += "|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |\n"
+ for _, p := range tls.TagLists {
+ res += p.tableLine()
+ }
+ // 加这一行是为了撑开整个表格
+ res += "|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|"
+ return res
+}
+
+// AvailableTagTable define
+func (tls TagLists) AvailableTagTable() string {
+ return tls.table()
+}
+
+// FavoritesLists define
+type FavoritesLists struct {
+ PublicFavorites []int `json:"publicFavorites"`
+ PrivateFavorites []struct {
+ IDHash string `json:"idHash"`
+ ID string `json:"id"`
+ Name string `json:"name"`
+ IsPublicFavorite bool `json:"isPublicFavorite"`
+ ViewCount int `json:"viewCount"`
+ Creator string `json:"creator"`
+ IsWatched bool `json:"isWatched"`
+ Questions []struct {
+ QuestionID string `json:"questionId"`
+ Title string `json:"title"`
+ TitleSlug string `json:"titleSlug"`
+ Typename string `json:"__typename"`
+ } `json:"questions"`
+ Typename string `json:"__typename"`
+ } `json:"privateFavorites"`
+ Typename string `json:"__typename"`
+}
+
+// Gproblem define
+type Gproblem struct {
+ QuestionID string `json:"questionId"`
+ QuestionFrontendID string `json:"questionFrontendId"`
+ BoundTopicID int `json:"boundTopicId"`
+ Title string `json:"title"`
+ TitleSlug string `json:"titleSlug"`
+ Content string `json:"content"`
+ TranslatedTitle string `json:"translatedTitle"`
+ TranslatedContent string `json:"translatedContent"`
+ IsPaidOnly bool `json:"isPaidOnly"`
+ Difficulty string `json:"difficulty"`
+ Likes int `json:"likes"`
+ Dislikes int `json:"dislikes"`
+ IsLiked interface{} `json:"isLiked"`
+ SimilarQuestions string `json:"similarQuestions"`
+ Contributors []interface{} `json:"contributors"`
+ LangToValidPlayground string `json:"langToValidPlayground"`
+ TopicTags []struct {
+ Name string `json:"name"`
+ Slug string `json:"slug"`
+ TranslatedName string `json:"translatedName"`
+ Typename string `json:"__typename"`
+ } `json:"topicTags"`
+ CompanyTagStats interface{} `json:"companyTagStats"`
+ CodeSnippets []GcodeSnippet `json:"codeSnippets"`
+ Stats string `json:"stats"`
+ Hints []interface{} `json:"hints"`
+ Solution interface{} `json:"solution"`
+ Status interface{} `json:"status"`
+ SampleTestCase string `json:"sampleTestCase"`
+ MetaData string `json:"metaData"`
+ JudgerAvailable bool `json:"judgerAvailable"`
+ JudgeType string `json:"judgeType"`
+ MysqlSchemas []interface{} `json:"mysqlSchemas"`
+ EnableRunCode bool `json:"enableRunCode"`
+ EnableTestMode bool `json:"enableTestMode"`
+ EnvInfo string `json:"envInfo"`
+ Typename string `json:"__typename"`
+}
+
+// Gstat define
+type Gstat struct {
+ TotalAcs int `json:"total_acs"`
+ QuestionTitle string `json:"question__title"`
+ IsNewQuestion bool `json:"is_new_question"`
+ QuestionArticleSlug string `json:"question__article__slug"`
+ TotalSubmitted int `json:"total_submitted"`
+ FrontendQuestionID int `json:"frontend_question_id"`
+ QuestionTitleSlug string `json:"question__title_slug"`
+ QuestionArticleLive bool `json:"question__article__live"`
+ QuestionHide bool `json:"question__hide"`
+ QuestionID int `json:"question_id"`
+}
+
+// GcodeSnippet define
+type GcodeSnippet struct {
+ Lang string `json:"lang"`
+ LangSlug string `json:"langSlug"`
+ Code string `json:"code"`
+ Typename string `json:"__typename"`
+}
diff --git a/ctl/models/user.go b/ctl/models/user.go
new file mode 100644
index 00000000..2f296458
--- /dev/null
+++ b/ctl/models/user.go
@@ -0,0 +1,44 @@
+package models
+
+import (
+ "fmt"
+)
+
+// UserInfo define
+type UserInfo struct {
+ UserName string `json:"user_name"`
+ NumSolved int32 `json:"num_solved"`
+ NumTotal int32 `json:"num_total"`
+ AcEasy int32 `json:"ac_easy"`
+ AcMedium int32 `json:"ac_medium"`
+ AcHard int32 `json:"ac_hard"`
+ EasyTotal int32
+ MediumTotal int32
+ HardTotal int32
+ OptimizingEasy int32
+ OptimizingMedium int32
+ OptimizingHard int32
+ FrequencyHigh int32 `json:"frequency_high"`
+ FrequencyMid int32 `json:"frequency_mid"`
+ CategorySlug string `json:"category_slug"`
+}
+
+// | | Easy | Medium | Hard | Total | optimizing |
+// |:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
+func (ui UserInfo) table() string {
+ res := "| | Easy | Medium | Hard | Total |\n"
+ res += "|:--------:|:--------:|:--------:|:--------:|:--------:|\n"
+ res += fmt.Sprintf("|Optimizing|%v|%v|%v|%v|\n", ui.OptimizingEasy, ui.OptimizingMedium, ui.OptimizingHard, ui.OptimizingEasy+ui.OptimizingMedium+ui.OptimizingHard)
+ res += fmt.Sprintf("|Accepted|**%v**|**%v**|**%v**|**%v**|\n", ui.AcEasy, ui.AcMedium, ui.AcHard, ui.AcEasy+ui.AcMedium+ui.AcHard)
+ res += fmt.Sprintf("|Total|%v|%v|%v|%v|\n", ui.EasyTotal, ui.MediumTotal, ui.HardTotal, ui.EasyTotal+ui.MediumTotal+ui.HardTotal)
+ res += fmt.Sprintf("|Perfection Rate|%.1f%%|%.1f%%|%.1f%%|%.1f%%|\n", (1-float64(ui.OptimizingEasy)/float64(ui.AcEasy))*100, (1-float64(ui.OptimizingMedium)/float64(ui.AcMedium))*100, (1-float64(ui.OptimizingHard)/float64(ui.AcHard))*100, (1-float64(ui.OptimizingEasy+ui.OptimizingMedium+ui.OptimizingHard)/float64(ui.AcEasy+ui.AcMedium+ui.AcHard))*100)
+ res += fmt.Sprintf("|Completion Rate|%.1f%%|%.1f%%|%.1f%%|%.1f%%|\n", float64(ui.AcEasy)/float64(ui.EasyTotal)*100, float64(ui.AcMedium)/float64(ui.MediumTotal)*100, float64(ui.AcHard)/float64(ui.HardTotal)*100, float64(ui.AcEasy+ui.AcMedium+ui.AcHard)/float64(ui.EasyTotal+ui.MediumTotal+ui.HardTotal)*100)
+ // 加这一行是为了撑开整个表格
+ res += "|------------|----------------------------|----------------------------|----------------------------|----------------------------|"
+ return res
+}
+
+// PersonalData define
+func (ui UserInfo) PersonalData() string {
+ return ui.table()
+}
diff --git a/ctl/pdf.go b/ctl/pdf.go
new file mode 100644
index 00000000..9c2b432b
--- /dev/null
+++ b/ctl/pdf.go
@@ -0,0 +1,212 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "github.com/halfrost/LeetCode-Go/ctl/util"
+ "github.com/spf13/cobra"
+ "io"
+ "io/ioutil"
+ "os"
+ "regexp"
+ "strings"
+)
+
+var (
+ cleanString1 = "{{< columns >}}"
+ cleanString2 = "<--->"
+ cleanString3 = "{{< /columns >}}"
+ cleanString4 = " "
+ pdfPreface = `
+
+
+# 说明
+
+此版本是 https://books.halfrost.com/leetcode 网页的离线版,由于网页版实时会更新,所以此 PDF 版难免会有一些排版或者错别字。如果读者遇到了,可以到网页版相应页面,点击页面 edit 按钮,提交 pr 进行更改。此 PDF 版本号是 V%v.%v.%v。PDF 永久更新地址是 https://github.com/halfrost/LeetCode-Go/releases/,以版本号区分不同版本。笔者还是强烈推荐看在线版,有任何错误都会立即更新。如果觉得此书对刷题有一点点帮助,可以给此书点一个 star,鼓励一下笔者早点更新更多题解。
+
+> 版本号说明,V%v.%v.%v,%v 是大版本号,%v 代表当前题解中有几百题,目前是 %v 题,所以第二个版本号是 %v,%v 代表当前题解中有几十题,目前是 %v 题,所以第三个版本号是 %v 。
+
+# 目录
+
+[toc]
+
+`
+
+ majorVersion = 1
+ midVersion = 0
+ lastVersion = 0
+ totalSolutions = 0
+)
+
+func newPDFCommand() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "pdf",
+ Short: "PDF related commands",
+ Run: func(cmd *cobra.Command, args []string) {
+ generatePDF()
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func generatePDF() {
+ var (
+ pdf, tmp []byte
+ err error
+ )
+ // 先删除 pre-next
+ delPreNext()
+
+ chapterFourFileOrder := util.LoadChapterFourDir()
+ totalSolutions = len(chapterFourFileOrder)
+ midVersion = totalSolutions / 100
+ lastVersion = totalSolutions % 100
+ fmt.Printf("[当前的版本号是 V%v.%v.%v]\n", majorVersion, midVersion, lastVersion)
+ // 删除原始文档中的头部,并创建临时文件夹
+ prepare(fmt.Sprintf("../PDF v%v.%v.%v.md", majorVersion, midVersion, lastVersion))
+ // PDF 前言
+ pdf = append(pdf, []byte(fmt.Sprintf(pdfPreface, majorVersion, midVersion, lastVersion, majorVersion, midVersion, lastVersion, majorVersion, midVersion, totalSolutions, midVersion, lastVersion, totalSolutions, lastVersion))...)
+ // PDF 第一章
+ tmp, err = loadChapter(chapterOneFileOrder, "./pdftemp", "ChapterOne")
+ pdf = append(pdf, tmp...)
+ // PDF 第二章
+ tmp, err = loadChapter(chapterTwoFileOrder, "./pdftemp", "ChapterTwo")
+ pdf = append(pdf, tmp...)
+ // PDF 第三章
+ tmp, err = loadChapter(chapterThreeFileOrder, "./pdftemp", "ChapterThree")
+ pdf = append(pdf, tmp...)
+ // PDF 第四章
+ tmp, err = util.LoadFile("./pdftemp/ChapterFour/_index.md")
+ pdf = append(pdf, tmp...)
+ tmp, err = loadChapter(chapterFourFileOrder, "../website/content", "ChapterFour")
+ pdf = append(pdf, tmp...)
+ if err != nil {
+ fmt.Println(err)
+ }
+ // 生成 PDF
+ util.WriteFile(fmt.Sprintf("../PDF v%v.%v.%v.md", majorVersion, midVersion, lastVersion), pdf)
+ // 还原现场
+ addPreNext()
+ util.DestoryDir("./pdftemp")
+}
+
+func loadChapter(order []string, path, chapter string) ([]byte, error) {
+ var (
+ res, tmp []byte
+ err error
+ )
+ for index, v := range order {
+ if chapter == "ChapterOne" && index == 0 {
+ // 清理不支持的特殊 MarkDown 语法
+ tmp, err = clean(fmt.Sprintf("%v/%v/%v.md", path, chapter, v))
+ } else {
+ tmp, err = util.LoadFile(fmt.Sprintf("%v/%v/%v.md", path, chapter, v))
+ }
+ if err != nil {
+ fmt.Println(err)
+ return []byte{}, err
+ }
+ res = append(res, tmp...)
+ }
+ return res, err
+}
+
+func prepare(path string) {
+ err := os.Remove(path)
+ if err != nil {
+ fmt.Println("pdf 还没有创建")
+ fmt.Println(err)
+ }
+ fmt.Println("pdf 删除成功,开始构建全新版本")
+
+ err = os.MkdirAll("./pdftemp/ChapterOne", os.ModePerm)
+ if err != nil {
+ fmt.Println(err)
+ }
+ for _, v := range chapterOneFileOrder {
+ removeHeader(fmt.Sprintf("../website/content/ChapterOne/%v.md", v), fmt.Sprintf("./pdftemp/ChapterOne/%v.md", v), 4)
+ }
+
+ err = os.MkdirAll("./pdftemp/ChapterTwo", os.ModePerm)
+ if err != nil {
+ fmt.Println(err)
+ }
+ // 生成外部链接的 ChapterTwo
+ buildChapterTwo(false)
+ util.CopyFile("./pdftemp/ChapterTwo/_index.md", "../website/content/ChapterTwo/_index.md")
+
+ for _, v := range chapterTwoFileOrder {
+ removeHeader(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), 4)
+ }
+
+ err = os.MkdirAll("./pdftemp/ChapterThree", os.ModePerm)
+ if err != nil {
+ fmt.Println(err)
+ }
+ for _, v := range chapterThreeFileOrder {
+ removeHeader(fmt.Sprintf("../website/content/ChapterThree/%v.md", v), fmt.Sprintf("./pdftemp/ChapterThree/%v.md", v), 4)
+ }
+
+ err = os.MkdirAll("./pdftemp/ChapterFour", os.ModePerm)
+ if err != nil {
+ fmt.Println(err)
+ }
+ removeHeader(fmt.Sprintf("../website/content/ChapterFour/_index.md"), fmt.Sprintf("./pdftemp/ChapterFour/_index.md"), 4)
+}
+
+func clean(filePath string) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return output, nil
+ }
+ return nil, err
+ }
+ if ok, _ := regexp.Match(cleanString1, line); ok {
+ reg := regexp.MustCompile(cleanString1)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match(cleanString2, line); ok {
+ reg := regexp.MustCompile(cleanString2)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match(cleanString3, line); ok {
+ reg := regexp.MustCompile(cleanString3)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match(cleanString4, line); ok {
+ reg := regexp.MustCompile(cleanString4)
+ newByte := reg.ReplaceAll(line, []byte(""))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else {
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+ }
+}
+
+func removeHeader(path, newPath string, lineNumber int) {
+ file, err := ioutil.ReadFile(path)
+ if err != nil {
+ panic(err)
+ }
+ info, _ := os.Stat(path)
+ mode := info.Mode()
+ array := strings.Split(string(file), "\n")
+ array = array[lineNumber:]
+ ioutil.WriteFile(newPath, []byte(strings.Join(array, "\n")), mode)
+ //fmt.Println("remove line successful")
+}
diff --git a/ctl/rangking.go b/ctl/rangking.go
new file mode 100644
index 00000000..3e819691
--- /dev/null
+++ b/ctl/rangking.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+)
+
+// getRanking 让这个方法优雅一点
+func getRanking() int {
+ // 获取网页数据
+ URL := fmt.Sprintf("https://leetcode.com/%s/", getConfig().Username)
+ data := getRaw(URL)
+ str := string(data)
+ // 通过不断裁剪 str 获取排名信息
+ fmt.Println(str)
+ i := strings.Index(str, "ng-init")
+ j := i + strings.Index(str[i:], "ng-cloak")
+ str = str[i:j]
+ i = strings.Index(str, "(")
+ j = strings.Index(str, ")")
+ str = str[i:j]
+ // fmt.Println("2\n", str)
+ strs := strings.Split(str, ",")
+ str = strs[6]
+ // fmt.Println("1\n", str)
+ i = strings.Index(str, "'")
+ j = 2 + strings.Index(str[2:], "'")
+ // fmt.Println("0\n", str)
+ str = str[i+1 : j]
+ r, err := strconv.Atoi(str)
+ if err != nil {
+ fmt.Printf("无法把 %s 转换成数字Ranking", str)
+ }
+ return r
+}
diff --git a/ctl/refresh.go b/ctl/refresh.go
new file mode 100644
index 00000000..9db1784a
--- /dev/null
+++ b/ctl/refresh.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "github.com/spf13/cobra"
+)
+
+func newRefresh() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "refresh",
+ Short: "Refresh all document",
+ Run: func(cmd *cobra.Command, args []string) {
+ refresh()
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func refresh() {
+ buildBookMenu()
+ delPreNext()
+ buildREADME()
+ buildChapterTwo(true)
+ addPreNext()
+}
diff --git a/ctl/render.go b/ctl/render.go
new file mode 100644
index 00000000..fe1f375b
--- /dev/null
+++ b/ctl/render.go
@@ -0,0 +1,349 @@
+package main
+
+import (
+ "bufio"
+ "encoding/json"
+ "fmt"
+ m "github.com/halfrost/LeetCode-Go/ctl/models"
+ "github.com/halfrost/LeetCode-Go/ctl/util"
+ "github.com/spf13/cobra"
+ "io"
+ "os"
+ "regexp"
+ "sort"
+ "strconv"
+ "strings"
+)
+
+var (
+ chapterTwoList = []string{"Array", "String", "Two Pointers", "Linked List", "Stack", "Tree", "Dynamic Programming", "Backtracking", "Depth First Search", "Breadth First Search",
+ "Binary Search", "Math", "Hash Table", "Sort", "Bit Manipulation", "Union Find", "Sliding Window", "Segment Tree", "Binary Indexed Tree"}
+ chapterTwoFileName = []string{"Array", "String", "Two_Pointers", "Linked_List", "Stack", "Tree", "Dynamic_Programming", "Backtracking", "Depth_First_Search", "Breadth_First_Search",
+ "Binary_Search", "Math", "Hash_Table", "Sort", "Bit_Manipulation", "Union_Find", "Sliding_Window", "Segment_Tree", "Binary_Indexed_Tree"}
+ chapterTwoSlug = []string{"array", "string", "two-pointers", "linked-list", "stack", "tree", "dynamic-programming", "backtracking", "depth-first-search", "breadth-first-search",
+ "binary-search", "math", "hash-table", "sort", "bit-manipulation", "union-find", "sliding-window", "segment-tree", "binary-indexed-tree"}
+)
+
+func newBuildCommand() *cobra.Command {
+ mc := &cobra.Command{
+ Use: "build ",
+ Short: "Build doc related commands",
+ }
+ //mc.PersistentFlags().StringVar(&logicEndpoint, "endpoint", "localhost:5880", "endpoint of logic service")
+ mc.AddCommand(
+ newBuildREADME(),
+ newBuildChapterTwo(),
+ newBuildMenu(),
+ )
+ return mc
+}
+
+func newBuildREADME() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "readme",
+ Short: "Build readme.md commands",
+ Run: func(cmd *cobra.Command, args []string) {
+ buildREADME()
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func newBuildChapterTwo() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "chapter-two",
+ Short: "Build Chapter Two commands",
+ Run: func(cmd *cobra.Command, args []string) {
+ buildChapterTwo(true)
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func newBuildMenu() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "menu",
+ Short: "Build Menu commands",
+ Run: func(cmd *cobra.Command, args []string) {
+ buildBookMenu()
+ },
+ }
+ // cmd.Flags().StringVar(&alias, "alias", "", "alias")
+ // cmd.Flags().StringVar(&appId, "appid", "", "appid")
+ return cmd
+}
+
+func buildREADME() {
+ var (
+ problems []m.StatStatusPairs
+ lpa m.LeetCodeProblemAll
+ info m.UserInfo
+ )
+ // 请求所有题目信息
+ body := getProblemAllList()
+ problemsMap, optimizingIds := map[int]m.StatStatusPairs{}, []int{}
+ err := json.Unmarshal(body, &lpa)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ //writeFile("leetcode_problem.json", body)
+
+ // 拼凑 README 需要渲染的数据
+ problems = lpa.StatStatusPairs
+ info = m.ConvertUserInfoModel(lpa)
+ for _, v := range problems {
+ problemsMap[int(v.Stat.FrontendQuestionID)] = v
+ }
+ mdrows := m.ConvertMdModelFromSsp(problems)
+ sort.Sort(m.SortByQuestionID(mdrows))
+ solutionIds, _, try := util.LoadSolutionsDir()
+ m.GenerateMdRows(solutionIds, mdrows)
+ info.EasyTotal, info.MediumTotal, info.HardTotal, info.OptimizingEasy, info.OptimizingMedium, info.OptimizingHard, optimizingIds = statisticalData(problemsMap, solutionIds)
+ omdrows := m.ConvertMdModelFromIds(problemsMap, optimizingIds)
+ sort.Sort(m.SortByQuestionID(omdrows))
+
+ // 按照模板渲染 README
+ res, err := renderReadme("./template/template.markdown", len(solutionIds), try, m.Mdrows{Mdrows: mdrows}, m.Mdrows{Mdrows: omdrows}, info)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ util.WriteFile("../README.md", res)
+ fmt.Println("write file successful")
+ //makeReadmeFile(mds)
+}
+
+func renderReadme(filePath string, total, try int, mdrows, omdrows m.Mdrows, user m.UserInfo) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return output, nil
+ }
+ return nil, err
+ }
+ if ok, _ := regexp.Match("{{.AvailableTable}}", line); ok {
+ reg := regexp.MustCompile("{{.AvailableTable}}")
+ newByte := reg.ReplaceAll(line, []byte(mdrows.AvailableTable()))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match("{{.TotalNum}}", line); ok {
+ reg := regexp.MustCompile("{{.TotalNum}}")
+ newByte := reg.ReplaceAll(line, []byte(fmt.Sprintf("以下已经收录了 %v 道题的题解,还有 %v 道题在尝试优化到 beats 100%%", total, try)))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match("{{.PersonalData}}", line); ok {
+ reg := regexp.MustCompile("{{.PersonalData}}")
+ newByte := reg.ReplaceAll(line, []byte(user.PersonalData()))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else if ok, _ := regexp.Match("{{.OptimizingTable}}", line); ok {
+ reg := regexp.MustCompile("{{.OptimizingTable}}")
+ newByte := reg.ReplaceAll(line, []byte(fmt.Sprintf("以下 %v 道题还需要优化到 100%% 的题目列表\n\n%v", (user.OptimizingEasy+user.OptimizingMedium+user.OptimizingHard), omdrows.AvailableTable())))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else {
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+ }
+}
+
+// internal: true 渲染的链接都是 hugo 内部链接,用户生成 hugo web
+// false 渲染的链接是外部 HTTPS 链接,用于生成 PDF
+func buildChapterTwo(internal bool) {
+ var (
+ gr m.GraphQLResp
+ questions []m.Question
+ count int
+ )
+ for index, tag := range chapterTwoSlug {
+ body := getTagProblemList(tag)
+ // fmt.Printf("%v\n", string(body))
+ err := json.Unmarshal(body, &gr)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ questions = gr.Data.TopicTag.Questions
+ mdrows := m.ConvertMdModelFromQuestions(questions)
+ sort.Sort(m.SortByQuestionID(mdrows))
+ solutionIds, _, _ := util.LoadSolutionsDir()
+ tl, err := loadMetaData(fmt.Sprintf("./meta/%v", chapterTwoFileName[index]))
+ if err != nil {
+ fmt.Printf("err = %v\n", err)
+ }
+ tls := m.GenerateTagMdRows(solutionIds, tl, mdrows, internal)
+ //fmt.Printf("tls = %v\n", tls)
+ // 按照模板渲染 README
+ res, err := renderChapterTwo(fmt.Sprintf("./template/%v.md", chapterTwoFileName[index]), m.TagLists{TagLists: tls})
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ if internal {
+ util.WriteFile(fmt.Sprintf("../website/content/ChapterTwo/%v.md", chapterTwoFileName[index]), res)
+ } else {
+ util.WriteFile(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", chapterTwoFileName[index]), res)
+ }
+
+ count++
+ }
+ fmt.Printf("write %v files successful", count)
+}
+
+func loadMetaData(filePath string) (map[int]m.TagList, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, metaMap := bufio.NewReader(f), map[int]m.TagList{}
+
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return metaMap, nil
+ }
+ return nil, err
+ }
+ s := strings.Split(string(line), "|")
+ v, _ := strconv.Atoi(strings.Split(s[1], ".")[0])
+ // v[0] 是题号,s[4] time, s[5] space, s[6] favorite
+ metaMap[v] = m.TagList{
+ FrontendQuestionID: int32(v),
+ Acceptance: "",
+ Difficulty: "",
+ TimeComplexity: s[4],
+ SpaceComplexity: s[5],
+ Favorite: s[6],
+ }
+ }
+}
+
+func renderChapterTwo(filePath string, tls m.TagLists) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return output, nil
+ }
+ return nil, err
+ }
+ if ok, _ := regexp.Match("{{.AvailableTagTable}}", line); ok {
+ reg := regexp.MustCompile("{{.AvailableTagTable}}")
+ newByte := reg.ReplaceAll(line, []byte(tls.AvailableTagTable()))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else {
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+ }
+}
+
+func buildBookMenu() {
+ solutionIds, soName, _ := util.LoadSolutionsDir()
+ ch4Ids, _ := util.LoadChapterFourIds()
+
+ needCopy := []string{}
+ for i := 0; i < len(solutionIds); i++ {
+ if util.BinarySearch(ch4Ids, solutionIds[i]) == -1 {
+ needCopy = append(needCopy, soName[i])
+ }
+ }
+ if len(needCopy) > 0 {
+ fmt.Printf("有 %v 道题需要拷贝到第四章中\n", len(needCopy))
+ for i := 0; i < len(needCopy); i++ {
+ util.CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v.md", needCopy[i]), fmt.Sprintf("../leetcode/%v/README.md", needCopy[i]))
+ }
+ } else {
+ fmt.Printf("【第四章没有需要添加的题解,已经完整了】\n")
+ }
+
+ // 按照模板重新渲染 Menu
+ res, err := renderBookMenu("./template/menu.md")
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ util.WriteFile("../website/content/menu/index.md", res)
+ fmt.Println("generate Menu successful")
+}
+
+func generateMenu() string {
+ res := ""
+ res += menuLine(chapterOneMenuOrder, "ChapterOne")
+ res += menuLine(chapterTwoFileOrder, "ChapterTwo")
+ res += menuLine(chapterThreeFileOrder, "ChapterThree")
+ res += menuLine(getChapterFourFileOrder(), "ChapterFour")
+ return res
+}
+
+func menuLine(order []string, chapter string) string {
+ res := ""
+ for i := 0; i < len(order); i++ {
+ if i == 1 && chapter == "ChapterOne" {
+ res += fmt.Sprintf(" - [%v]({{< relref \"/%v/%v\" >}})\n", chapterMap[chapter][order[i]], chapter, order[i])
+ continue
+ }
+ if i == 0 {
+ res += fmt.Sprintf("- [%v]({{< relref \"/%v/%v.md\" >}})\n", chapterMap[chapter][order[i]], chapter, order[i])
+ } else {
+ if chapter == "ChapterFour" {
+ res += fmt.Sprintf(" - [%v]({{< relref \"/%v/%v.md\" >}})\n", order[i], chapter, order[i])
+ } else {
+ res += fmt.Sprintf(" - [%v]({{< relref \"/%v/%v.md\" >}})\n", chapterMap[chapter][order[i]], chapter, order[i])
+ }
+ }
+ }
+ return res
+}
+
+func renderBookMenu(filePath string) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return output, nil
+ }
+ return nil, err
+ }
+ if ok, _ := regexp.Match("{{.BookMenu}}", line); ok {
+ reg := regexp.MustCompile("{{.BookMenu}}")
+ newByte := reg.ReplaceAll(line, []byte(generateMenu()))
+ output = append(output, newByte...)
+ output = append(output, []byte("\n")...)
+ } else {
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+ }
+}
diff --git a/ctl/request.go b/ctl/request.go
new file mode 100644
index 00000000..056d5e14
--- /dev/null
+++ b/ctl/request.go
@@ -0,0 +1,109 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "github.com/mozillazg/request"
+ "io/ioutil"
+ "net/http"
+)
+
+const (
+ // AllProblemURL define
+ AllProblemURL = "https://leetcode.com/api/problems/all/"
+ // QraphqlURL define
+ QraphqlURL = "https://leetcode.com/graphql"
+ // LoginPageURL define
+ LoginPageURL = "https://leetcode.com/accounts/login/"
+ // AlgorithmsURL define
+ AlgorithmsURL = "https://leetcode.com/api/problems/Algorithms/"
+
+ // ArrayProblemURL define
+ ArrayProblemURL = "https://leetcode.com/tag/array/"
+)
+
+var req *request.Request
+
+func newReq() *request.Request {
+ if req == nil {
+ req = signin()
+ }
+ return req
+}
+
+func signin() *request.Request {
+ cfg := getConfig()
+ req := request.NewRequest(new(http.Client))
+ req.Headers = map[string]string{
+ "Content-Type": "application/json",
+ "Accept-Encoding": "",
+ "cookie": cfg.Cookie,
+ "x-csrftoken": cfg.CSRFtoken,
+ "Referer": "https://leetcode.com/accounts/login/",
+ "origin": "https://leetcode.com",
+ }
+ return req
+}
+
+func getRaw(URL string) []byte {
+ req := newReq()
+ resp, err := req.Get(URL)
+ if err != nil {
+ fmt.Printf("getRaw: Get Error: " + err.Error())
+ return []byte{}
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Printf("getRaw: Read Error: " + err.Error())
+ return []byte{}
+ }
+ if resp.StatusCode == 200 {
+ fmt.Println("Get problem Success!")
+ }
+ return body
+}
+
+func getProblemAllList() []byte {
+ return getRaw(AllProblemURL)
+}
+
+// Variables define
+type Variables struct {
+ slug string
+}
+
+func getQraphql(payload string) []byte {
+ req := newReq()
+ resp, err := req.PostForm(QraphqlURL, bytes.NewBuffer([]byte(payload)))
+ if err != nil {
+ fmt.Printf("getRaw: Get Error: " + err.Error())
+ return []byte{}
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Printf("getRaw: Read Error: " + err.Error())
+ return []byte{}
+ }
+ if resp.StatusCode == 200 {
+ fmt.Println("Get problem Success!")
+ }
+ return body
+}
+
+func getTopicTag(variable string) string {
+ return fmt.Sprintf(`{
+ "operationName": "getTopicTag",
+ "variables": {
+ "slug": "%s"
+ },
+ "query": "query getTopicTag($slug: String!) { topicTag(slug: $slug) { name translatedName slug questions { status questionId questionFrontendId title titleSlug translatedTitle stats difficulty isPaidOnly topicTags { name translatedName slug __typename } companyTags { name translatedName slug __typename } __typename } frequencies __typename } favoritesLists { publicFavorites { ...favoriteFields __typename } privateFavorites { ...favoriteFields __typename } __typename }}fragment favoriteFields on FavoriteNode { idHash id name isPublicFavorite viewCount creator isWatched questions { questionId title titleSlug __typename } __typename}"
+ }`, variable)
+}
+
+func getTagProblemList(tag string) []byte {
+ return getQraphql(getTopicTag(tag))
+}
diff --git a/ctl/statistic.go b/ctl/statistic.go
new file mode 100644
index 00000000..c796dc44
--- /dev/null
+++ b/ctl/statistic.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ m "github.com/halfrost/LeetCode-Go/ctl/models"
+ "github.com/halfrost/LeetCode-Go/ctl/util"
+ "sort"
+)
+
+func statisticalData(problemsMap map[int]m.StatStatusPairs, solutionIds []int) (easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard int32, optimizingIds []int) {
+ easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard, optimizingIds = 0, 0, 0, 0, 0, 0, []int{}
+ for _, v := range problemsMap {
+ switch m.DifficultyMap[v.Difficulty.Level] {
+ case "Easy":
+ {
+ easyTotal++
+ if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
+ optimizingEasy++
+ optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
+ }
+ }
+ case "Medium":
+ {
+ mediumTotal++
+ if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
+ optimizingMedium++
+ optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
+ }
+ }
+ case "Hard":
+ {
+ hardTotal++
+ if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
+ optimizingHard++
+ optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
+ }
+ }
+ }
+ }
+ sort.Ints(optimizingIds)
+ return easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard, optimizingIds
+}
diff --git a/ctl/template/Array.md b/ctl/template/Array.md
new file mode 100644
index 00000000..87164757
--- /dev/null
+++ b/ctl/template/Array.md
@@ -0,0 +1,8 @@
+---
+title: Array
+type: docs
+---
+
+# Array
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Backtracking.md b/ctl/template/Backtracking.md
new file mode 100644
index 00000000..abbd8a52
--- /dev/null
+++ b/ctl/template/Backtracking.md
@@ -0,0 +1,100 @@
+---
+title: Backtracking
+type: docs
+---
+
+# Backtracking
+
+
+
+- 排列问题 Permutations。第 46 题,第 47 题。第 60 题,第 526 题,第 996 题。
+- 组合问题 Combination。第 39 题,第 40 题,第 77 题,第 216 题。
+- 排列和组合杂交问题。第 1079 题。
+- N 皇后终极解法(二进制解法)。第 51 题,第 52 题。
+- 数独问题。第 37 题。
+- 四个方向搜索。第 79 题,第 212 题,第 980 题。
+- 子集合问题。第 78 题,第 90 题。
+- Trie。第 208 题,第 211 题。
+- BFS 优化。第 126 题,第 127 题。
+- DFS 模板。(只是一个例子,不对应任何题)
+
+```go
+func combinationSum2(candidates []int, target int) [][]int {
+ if len(candidates) == 0 {
+ return [][]int{}
+ }
+ c, res := []int{}, [][]int{}
+ sort.Ints(candidates)
+ findcombinationSum2(candidates, target, 0, c, &res)
+ return res
+}
+
+func findcombinationSum2(nums []int, target, index int, c []int, res *[][]int) {
+ if target == 0 {
+ b := make([]int, len(c))
+ copy(b, c)
+ *res = append(*res, b)
+ return
+ }
+ for i := index; i < len(nums); i++ {
+ if i > index && nums[i] == nums[i-1] { // 这里是去重的关键逻辑
+ continue
+ }
+ if target >= nums[i] {
+ c = append(c, nums[i])
+ findcombinationSum2(nums, target-nums[i], i+1, c, res)
+ c = c[:len(c)-1]
+ }
+ }
+}
+```
+- BFS 模板。(只是一个例子,不对应任何题)
+
+```go
+func updateMatrix_BFS(matrix [][]int) [][]int {
+ res := make([][]int, len(matrix))
+ if len(matrix) == 0 || len(matrix[0]) == 0 {
+ return res
+ }
+ queue := make([][]int, 0)
+ for i, _ := range matrix {
+ res[i] = make([]int, len(matrix[0]))
+ for j, _ := range res[i] {
+ if matrix[i][j] == 0 {
+ res[i][j] = -1
+ queue = append(queue, []int{i, j})
+ }
+ }
+ }
+ level := 1
+ for len(queue) > 0 {
+ size := len(queue)
+ for size > 0 {
+ size -= 1
+ node := queue[0]
+ queue = queue[1:]
+ i, j := node[0], node[1]
+ for _, direction := range [][]int{{-1, 0}, {1, 0}, {0, 1}, {0, -1}} {
+ x := i + direction[0]
+ y := j + direction[1]
+ if x < 0 || x >= len(matrix) || y < 0 || y >= len(matrix[0]) || res[x][y] < 0 || res[x][y] > 0 {
+ continue
+ }
+ res[x][y] = level
+ queue = append(queue, []int{x, y})
+ }
+ }
+ level++
+ }
+ for i, row := range res {
+ for j, cell := range row {
+ if cell == -1 {
+ res[i][j] = 0
+ }
+ }
+ }
+ return res
+}
+```
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Binary_Indexed_Tree.md b/ctl/template/Binary_Indexed_Tree.md
new file mode 100644
index 00000000..0632403a
--- /dev/null
+++ b/ctl/template/Binary_Indexed_Tree.md
@@ -0,0 +1,10 @@
+---
+title: Binary Indexed Tree
+type: docs
+---
+
+# Binary Indexed Tree
+
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Binary_Search.md b/ctl/template/Binary_Search.md
new file mode 100644
index 00000000..033ca9da
--- /dev/null
+++ b/ctl/template/Binary_Search.md
@@ -0,0 +1,131 @@
+---
+title: Binary Search
+type: docs
+---
+
+# Binary Search
+
+- 二分搜索的经典写法。需要注意的三点:
+ 1. 循环退出条件,注意是 low <= high,而不是 low < high。
+ 2. mid 的取值,mid := low + (high-low)>>1
+ 3. low 和 high 的更新。low = mid + 1,high = mid - 1。
+
+```go
+func binarySearchMatrix(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + (high-low)>>1
+ if nums[mid] == target {
+ return mid
+ } else if nums[mid] > target {
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ }
+ return -1
+}
+```
+
+- 二分搜索的变种写法。有 4 个基本变种:
+ 1. 查找第一个与 target 相等的元素,时间复杂度 O(logn)
+ 2. 查找最后一个与 target 相等的元素,时间复杂度 O(logn)
+ 3. 查找第一个大于等于 target 的元素,时间复杂度 O(logn)
+ 4. 查找最后一个小于等于 target 的元素,时间复杂度 O(logn)
+
+```go
+// 二分查找第一个与 target 相等的元素,时间复杂度 O(logn)
+func searchFirstEqualElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] > target {
+ high = mid - 1
+ } else if nums[mid] < target {
+ low = mid + 1
+ } else {
+ if (mid == 0) || (nums[mid-1] != target) { // 找到第一个与 target 相等的元素
+ return mid
+ }
+ high = mid - 1
+ }
+ }
+ return -1
+}
+
+// 二分查找最后一个与 target 相等的元素,时间复杂度 O(logn)
+func searchLastEqualElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] > target {
+ high = mid - 1
+ } else if nums[mid] < target {
+ low = mid + 1
+ } else {
+ if (mid == len(nums)-1) || (nums[mid+1] != target) { // 找到最后一个与 target 相等的元素
+ return mid
+ }
+ low = mid + 1
+ }
+ }
+ return -1
+}
+
+// 二分查找第一个大于等于 target 的元素,时间复杂度 O(logn)
+func searchFirstGreaterElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] >= target {
+ if (mid == 0) || (nums[mid-1] < target) { // 找到第一个大于等于 target 的元素
+ return mid
+ }
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ }
+ return -1
+}
+
+// 二分查找最后一个小于等于 target 的元素,时间复杂度 O(logn)
+func searchLastLessElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] <= target {
+ if (mid == len(nums)-1) || (nums[mid+1] > target) { // 找到最后一个小于等于 target 的元素
+ return mid
+ }
+ low = mid + 1
+ } else {
+ high = mid - 1
+ }
+ }
+ return -1
+}
+```
+
+- 在基本有序的数组中用二分搜索。经典解法可以解,变种写法也可以写,常见的题型,在山峰数组中找山峰,在旋转有序数组中找分界点。第 33 题,第 81 题,第 153 题,第 154 题,第 162 题,第 852 题
+
+```go
+func peakIndexInMountainArray(A []int) int {
+ low, high := 0, len(A)-1
+ for low < high {
+ mid := low + (high-low)>>1
+ // 如果 mid 较大,则左侧存在峰值,high = m,如果 mid + 1 较大,则右侧存在峰值,low = mid + 1
+ if A[mid] > A[mid+1] {
+ high = mid
+ } else {
+ low = mid + 1
+ }
+ }
+ return low
+}
+```
+
+- max-min 最大值最小化问题。求在最小满足条件的情况下的最大值。第 410 题,第 875 题,第 1011 题,第 1283 题。
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Bit_Manipulation.md b/ctl/template/Bit_Manipulation.md
new file mode 100644
index 00000000..3d568f31
--- /dev/null
+++ b/ctl/template/Bit_Manipulation.md
@@ -0,0 +1,44 @@
+---
+title: Bit Manipulation
+type: docs
+---
+
+# Bit Manipulation
+
+
+
+- 异或的特性。第 136 题,第 268 题,第 389 题,第 421 题,
+
+```go
+x ^ 0 = x
+x ^ 11111……1111 = ~x
+x ^ (~x) = 11111……1111
+x ^ x = 0
+a ^ b = c => a ^ c = b => b ^ c = a (交换律)
+a ^ b ^ c = a ^ (b ^ c) = (a ^ b)^ c (结合律)
+```
+
+- 构造特殊 Mask,将特殊位置放 0 或 1。
+
+```go
+将 x 最右边的 n 位清零, x & ( ~0 << n )
+获取 x 的第 n 位值(0 或者 1),(x >> n) & 1
+获取 x 的第 n 位的幂值,x & (1 << (n - 1))
+仅将第 n 位置为 1,x | (1 << n)
+仅将第 n 位置为 0,x & (~(1 << n))
+将 x 最高位至第 n 位(含)清零,x & ((1 << n) - 1)
+将第 n 位至第 0 位(含)清零,x & (~((1 << (n + 1)) - 1))
+```
+
+- 有特殊意义的 & 位操作运算。第 260 题,第 201 题,第 318 题,第 371 题,第 397 题,第 461 题,第 693 题,
+
+```go
+X & 1 == 1 判断是否是奇数(偶数)
+X & = (X - 1) 将最低位(LSB)的 1 清零
+X & -X 得到最低位(LSB)的 1
+X & ~X = 0
+```
+
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Breadth_First_Search.md b/ctl/template/Breadth_First_Search.md
new file mode 100644
index 00000000..230a3ea7
--- /dev/null
+++ b/ctl/template/Breadth_First_Search.md
@@ -0,0 +1,9 @@
+---
+title: Breadth First Search
+type: docs
+---
+
+# Breadth First Search
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Depth_First_Search.md b/ctl/template/Depth_First_Search.md
new file mode 100644
index 00000000..016d6798
--- /dev/null
+++ b/ctl/template/Depth_First_Search.md
@@ -0,0 +1,9 @@
+---
+title: Depth First Search
+type: docs
+---
+
+# Depth First Search
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Dynamic_Programming.md b/ctl/template/Dynamic_Programming.md
new file mode 100644
index 00000000..d3384ecb
--- /dev/null
+++ b/ctl/template/Dynamic_Programming.md
@@ -0,0 +1,9 @@
+---
+title: Dynamic Programming
+type: docs
+---
+
+# Dynamic Programming
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Hash_Table.md b/ctl/template/Hash_Table.md
new file mode 100644
index 00000000..7677f9bd
--- /dev/null
+++ b/ctl/template/Hash_Table.md
@@ -0,0 +1,9 @@
+---
+title: Hash Table
+type: docs
+---
+
+# Hash Table
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Linked_List.md b/ctl/template/Linked_List.md
new file mode 100644
index 00000000..fd332903
--- /dev/null
+++ b/ctl/template/Linked_List.md
@@ -0,0 +1,23 @@
+---
+title: Linked List
+type: docs
+---
+
+# Linked List
+
+
+
+
+- 巧妙的构造虚拟头结点。可以使遍历处理逻辑更加统一。
+- 灵活使用递归。构造递归条件,使用递归可以巧妙的解题。不过需要注意有些题目不能使用递归,因为递归深度太深会导致超时和栈溢出。
+- 链表区间逆序。第 92 题。
+- 链表寻找中间节点。第 876 题。链表寻找倒数第 n 个节点。第 19 题。只需要一次遍历就可以得到答案。
+- 合并 K 个有序链表。第 21 题,第 23 题。
+- 链表归类。第 86 题,第 328 题。
+- 链表排序,时间复杂度要求 O(n * log n),空间复杂度 O(1)。只有一种做法,归并排序,至顶向下归并。第 148 题。
+- 判断链表是否存在环,如果有环,输出环的交叉点的下标;判断 2 个链表是否有交叉点,如果有交叉点,输出交叉点。第 141 题,第 142 题,第 160 题。
+
+
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Math.md b/ctl/template/Math.md
new file mode 100644
index 00000000..8ecedf58
--- /dev/null
+++ b/ctl/template/Math.md
@@ -0,0 +1,9 @@
+---
+title: Math
+type: docs
+---
+
+# Math
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Segment_Tree.md b/ctl/template/Segment_Tree.md
new file mode 100644
index 00000000..37f04d32
--- /dev/null
+++ b/ctl/template/Segment_Tree.md
@@ -0,0 +1,37 @@
+---
+title: Segment Tree
+type: docs
+---
+
+# Segment Tree
+
+
+
+- 线段树的经典数组实现写法。将合并两个节点 pushUp 逻辑抽象出来了,可以实现任意操作(常见的操作有:加法,取 max,min 等等)。第 218 题,第 303 题,第 307 题,第 699 题。
+- 计数线段树的经典写法。第 315 题,第 327 题,第 493 题。
+- 线段树的树的实现写法。第 715 题,第 732 题。
+- 区间懒惰更新。第 218 题,第 699 题。
+- 离散化。离散化需要注意一个特殊情况:假如三个区间为 [1,10] [1,4] [6,10],离散化后 x[1]=1,x[2]=4,x[3]=6,x[4]=10。第一个区间为 [1,4],第二个区间为 [1,2],第三个区间为 [3,4],这样一来,区间一 = 区间二 + 区间三,这和离散前的模型不符,离散前,很明显,区间一 > 区间二 + 区间三。正确的做法是:在相差大于 1 的数间加一个数,例如在上面 1 4 6 10 中间加 5,即可 x[1]=1,x[2]=4,x[3]=5,x[4]=6,x[5]=10。这样处理之后,区间一是 1-5 ,区间二是 1-2 ,区间三是 4-5 。
+- 灵活构建线段树。线段树节点可以存储多条信息,合并两个节点的 pushUp 操作也可以是多样的。第 850 题,第 1157 题。
+
+
+线段树[题型](https://blog.csdn.net/xuechelingxiao/article/details/38313105)从简单到困难:
+
+1. 单点更新:
+ [HDU 1166 敌兵布阵](http://acm.hdu.edu.cn/showproblem.php?pid=1166) update:单点增减 query:区间求和
+ [HDU 1754 I Hate It](http://acm.hdu.edu.cn/showproblem.php?pid=1754) update:单点替换 query:区间最值
+ [HDU 1394 Minimum Inversion Number](http://acm.hdu.edu.cn/showproblem.php?pid=1394) update:单点增减 query:区间求和
+ [HDU 2795 Billboard](http://acm.hdu.edu.cn/showproblem.php?pid=2795) query:区间求最大值的位子(直接把update的操作在query里做了)
+2. 区间更新:
+ [HDU 1698 Just a Hook](http://acm.hdu.edu.cn/showproblem.php?pid=1698) update:成段替换 (由于只query一次总区间,所以可以直接输出 1 结点的信息)
+ [POJ 3468 A Simple Problem with Integers](http://poj.org/problem?id=3468) update:成段增减 query:区间求和
+ [POJ 2528 Mayor’s posters](http://poj.org/problem?id=2528) 离散化 + update:成段替换 query:简单hash
+ [POJ 3225 Help with Intervals](http://poj.org/problem?id=3225) update:成段替换,区间异或 query:简单hash
+3. 区间合并(这类题目会询问区间中满足条件的连续最长区间,所以PushUp的时候需要对左右儿子的区间进行合并):
+ [POJ 3667 Hotel](http://poj.org/problem?id=3667) update:区间替换 query:询问满足条件的最左端点
+4. 扫描线(这类题目需要将一些操作排序,然后从左到右用一根扫描线扫过去最典型的就是矩形面积并,周长并等题):
+ [HDU 1542 Atlantis](http://acm.hdu.edu.cn/showproblem.php?pid=1542) update:区间增减 query:直接取根节点的值
+ [HDU 1828 Picture](http://acm.hdu.edu.cn/showproblem.php?pid=1828) update:区间增减 query:直接取根节点的值
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Sliding_Window.md b/ctl/template/Sliding_Window.md
new file mode 100644
index 00000000..a4fdca5c
--- /dev/null
+++ b/ctl/template/Sliding_Window.md
@@ -0,0 +1,29 @@
+---
+title: Sliding Window
+type: docs
+---
+
+# Sliding Window
+
+
+
+- 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
+
+```c
+ left, right := 0, -1
+
+ for left < len(s) {
+ if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
+ freq[s[right+1]-'a']++
+ right++
+ } else {
+ freq[s[left]-'a']--
+ left++
+ }
+ result = max(result, right-left+1)
+ }
+```
+- 滑动窗口经典题。第 239 题,第 480 题。
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Sort.md b/ctl/template/Sort.md
new file mode 100644
index 00000000..9e68d7dd
--- /dev/null
+++ b/ctl/template/Sort.md
@@ -0,0 +1,18 @@
+---
+title: Sort
+type: docs
+---
+
+# Sort
+
+
+
+- 深刻的理解多路快排。第 75 题。
+- 链表的排序,插入排序(第 147 题)和归并排序(第 148 题)
+- 桶排序和基数排序。第 164 题。
+- "摆动排序"。第 324 题。
+- 两两不相邻的排序。第 767 题,第 1054 题。
+- "饼子排序"。第 969 题。
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Stack.md b/ctl/template/Stack.md
new file mode 100644
index 00000000..3f1658e4
--- /dev/null
+++ b/ctl/template/Stack.md
@@ -0,0 +1,17 @@
+---
+title: Stack
+type: docs
+---
+
+# Stack
+
+
+
+- 括号匹配问题及类似问题。第 20 题,第 921 题,第 1021 题。
+- 栈的基本 pop 和 push 操作。第 71 题,第 150 题,第 155 题,第 224 题,第 225 题,第 232 题,第 946 题,第 1047 题。
+- 利用栈进行编码问题。第 394 题,第 682 题,第 856 题,第 880 题。
+- **单调栈**。**利用栈维护一个单调递增或者递减的下标数组**。第 84 题,第 456 题,第 496 题,第 503 题,第 739 题,第 901 题,第 907 题,第 1019 题。
+
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/String.md b/ctl/template/String.md
new file mode 100644
index 00000000..87afd108
--- /dev/null
+++ b/ctl/template/String.md
@@ -0,0 +1,9 @@
+---
+title: String
+type: docs
+---
+
+# String
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Tree.md b/ctl/template/Tree.md
new file mode 100644
index 00000000..c62c5398
--- /dev/null
+++ b/ctl/template/Tree.md
@@ -0,0 +1,9 @@
+---
+title: Tree
+type: docs
+---
+
+# Tree
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Two_Pointers.md b/ctl/template/Two_Pointers.md
new file mode 100644
index 00000000..80af5330
--- /dev/null
+++ b/ctl/template/Two_Pointers.md
@@ -0,0 +1,32 @@
+---
+title: Two Pointers
+type: docs
+---
+
+# Two Pointers
+
+
+
+- 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
+
+```c
+ left, right := 0, -1
+
+ for left < len(s) {
+ if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
+ freq[s[right+1]-'a']++
+ right++
+ } else {
+ freq[s[left]-'a']--
+ left++
+ }
+ result = max(result, right-left+1)
+ }
+```
+
+- 快慢指针可以查找重复数字,时间复杂度 O(n),第 287 题。
+- 替换字母以后,相同字母能出现连续最长的长度。第 424 题。
+- SUM 问题集。第 1 题,第 15 题,第 16 题,第 18 题,第 167 题,第 923 题,第 1074 题。
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/Union_Find.md b/ctl/template/Union_Find.md
new file mode 100644
index 00000000..752a5727
--- /dev/null
+++ b/ctl/template/Union_Find.md
@@ -0,0 +1,19 @@
+---
+title: Union Find
+type: docs
+---
+
+# Union Find
+
+
+
+- 灵活使用并查集的思想,熟练掌握并查集的[模板]({{< relref "/ChapterThree/UnionFind.md" >}}),模板中有两种并查集的实现方式,一种是路径压缩 + 秩优化的版本,另外一种是计算每个集合中元素的个数 + 最大集合元素个数的版本,这两种版本都有各自使用的地方。能使用第一类并查集模板的题目有:第 128 题,第 130 题,第 547 题,第 684 题,第 721 题,第 765 题,第 778 题,第 839 题,第 924 题,第 928 题,第 947 题,第 952 题,第 959 题,第 990 题。能使用第二类并查集模板的题目有:第 803 题,第 952 题。第 803 题秩优化和统计集合个数这些地方会卡时间,如果不优化,会 TLE。
+- 并查集是一种思想,有些题需要灵活使用这种思想,而不是死套模板,如第 399 题,这一题是 stringUnionFind,利用并查集思想实现的。这里每个节点是基于字符串和 map 的,而不是单纯的用 int 节点编号实现的。
+- 有些题死套模板反而做不出来,比如第 685 题,这一题不能路径压缩和秩优化,因为题目中涉及到有向图,需要知道节点的前驱节点,如果路径压缩了,这一题就没法做了。这一题不需要路径压缩和秩优化。
+- 灵活的抽象题目给的信息,将给定的信息合理的编号,使用并查集解题,并用 map 降低时间复杂度,如第 721 题,第 959 题。
+- 关于地图,砖块,网格的题目,可以新建一个特殊节点,将四周边缘的砖块或者网格都 union() 到这个特殊节点上。第 130 题,第 803 题。
+- 能用并查集的题目,一般也可以用 DFS 和 BFS 解答,只不过时间复杂度会高一点。
+
+
+
+{{.AvailableTagTable}}
\ No newline at end of file
diff --git a/ctl/template/menu.md b/ctl/template/menu.md
new file mode 100644
index 00000000..ed8c5180
--- /dev/null
+++ b/ctl/template/menu.md
@@ -0,0 +1,9 @@
+---
+headless: true
+---
+
+
+
+{{.BookMenu}}
+
+
diff --git a/ctl/template/template.markdown b/ctl/template/template.markdown
new file mode 100644
index 00000000..34939dea
--- /dev/null
+++ b/ctl/template/template.markdown
@@ -0,0 +1,644 @@
+
+# LeetCode in Go
+[LeetCode Online Judge](https://leetcode.com/) is a website containing many **algorithm questions**. Most of them are real interview questions of **Google, Facebook, LinkedIn, Apple**, etc. and it always help to sharp our algorithm Skills. Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. This repo shows my solutions in Go with the code style strictly follows the [Google Golang Style Guide](https://github.com/golang/go/wiki/CodeReviewComments). Please feel free to reference and **STAR** to support this repo, thank you!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+支持 Progressive Web Apps 和 Dark Mode 的题解电子书《LeetCode Cookbook》 Online Reading
+
+
+
+
+
+
+离线版本的电子书《LeetCode Cookbook》PDF Download here
+
+
+
+
+
+通过 iOS / Android 浏览器安装 PWA 版《LeetCode Cookbook》至设备桌面随时学习
+
+
+
+
+
+
+
+
+## Data Structures
+
+> 标识了 ✅ 的专题是完成所有题目了的,没有标识的是还没有做完所有题目的
+
+
+
+* [Array](#array)
+* [String](#string)
+* [✅ Two Pointers](#two-pointers)
+* [✅ Linked List](#linked-list)
+* [✅ Stack](#stack)
+* [Tree](#tree)
+* [Dynamic programming](#dynamic-programming)
+* [✅ Backtracking](#backtracking)
+* [Depth First Search](#depth-first-search)
+* [Breadth First Search](#breadth-first-search)
+* [Binary Search](#binary-search)
+* [Math](#math)
+* [Hash Table](#hash-table)
+* [✅ Sort](#sort)
+* [✅ Bit Manipulation](#bit-manipulation)
+* [✅ Union Find](#union-find)
+* [✅ Sliding Window](#sliding-window)
+* [✅ Segment Tree](#segment-tree)
+* [✅ Binary Indexed Tree](#binary-indexed-tree)
+
+
+
+
+| 数据结构 | 变种 | 相关题目 | 讲解文章 |
+|:-------:|:-------|:------|:------|
+|顺序线性表:向量||||
+|单链表|1. 双向链表 2. 静态链表 3. 对称矩阵 4. 稀疏矩阵|||
+|哈希表|1. 散列函数 2. 解决碰撞/填充因子 |||
+|栈和队列|1. 广义栈 2. 双端队列 |||
+|队列|1. 链表实现 2. 循环数组实现 3. 双端队列|||
+|字符串|1. KMP算法 2. 有限状态自动机 3. 模式匹配有限状态自动机 4. BM 模式匹配算法 5. BM-KMP 算法 6. BF 算法|||
+|树|1. 二叉树 2. 并查集 3. Huffman 树|||
+|数组实现的堆|1. 极大堆和极小堆 2. 极大极小堆 3. 双端堆 4. d 叉堆|||
+|树实现的堆|1. 左堆 2. 扁堆 3. 二项式堆 4. 斐波那契堆 5. 配对堆|||
+|查找|1. 哈希表 2. 跳跃表 3. 排序二叉树 4. AVL 树 5. B 树 / B+ 树 / B* 树 6. AA 树 7. 红黑树 8. 排序二叉堆 9. Splay 树 10. 双链树 11. Trie 树 12. R 树|||
+|--------------------------------------------|--------------------------------------------------------------------------------------------|---------------------------|-----------------------------------|
+
+
+## Algorithm
+
+
+| 算法 | 具体类型 | 相关题目 | 讲解文章 |
+|:-------:|:-------|:------|:------|
+|排序算法|1. 冒泡排序 2. 插入排序 3. 选择排序 4. 希尔 Shell 排序 5. 快速排序 6. 归并排序 7. 堆排序 8. 线性排序算法 9. 自省排序 10. 间接排序 11. 计数排序 12. 基数排序 13. 桶排序 14. 外部排序 - k 路归并败者树 15. 外部排序 - 最佳归并树|||
+|递归与分治||1. 二分搜索/查找 2. 大整数的乘法 3. Strassen 矩阵乘法 4. 棋盘覆盖 5. 合并排序 6. 快速排序 7. 线性时间选择 8. 最接近点对问题 9. 循环赛日程表 ||
+|动态规划||1. 矩阵连乘问题 2. 最长公共子序列 3. 最大子段和 4. 凸多边形最优三角剖分 5. 多边形游戏 6. 图像压缩 7. 电路布线 8. 流水作业调度 9. 0-1 背包问题/背包九讲 10. 最优二叉搜索树 11. 动态规划加速原理 12. 树型 DP ||
+|贪心||1. 活动安排问题 2. 最优装载 3. 哈夫曼编码 4. 单源最短路径 5. 最小生成树 6. 多机调度问题 ||
+|回溯法||1. 装载问题 2. 批处理作业调度 3. 符号三角形问题 4. n 后问题 5. 0-1 背包问题 6. 最大团问题 7. 图的 m 着色问题 8. 旅行售货员问题 9. 圆排列问题 10. 电路板排列问题 11. 连续邮资问题 ||
+|搜索|1. 枚举 2. DFS 3. BFS 4. 启发式搜索 |||
+|随机化|1. 随机数 2. 数值随机化算法 3. Sherwood 舍伍德算法 4. Las Vegas 拉斯维加斯算法 5. Monte Carlo 蒙特卡罗算法 |1. 计算 π 值 2. 计算定积分 3. 解非线性方程组 4. 线性时间选择算法 5. 跳跃表 6. n 后问题 7. 整数因子分解 8. 主元素问题 9. 素数测试 ||
+|图论|1. 遍历 DFS / BFS 2. AOV / AOE 网络 3. Kruskal 算法(最小生成树) 4. Prim 算法(最小生成树) 5. Boruvka 算法(最小生成树) 6. Dijkstra 算法(单源最短路径) 7. Bellman-Ford 算法(单源最短路径) 8. SPFA 算法(单源最短路径) 9. Floyd 算法(多源最短路径) 10. Johnson 算法(多源最短路径) 11. Fleury 算法(欧拉回路) 12. Ford-Fulkerson 算法(最大网络流增广路) 13. Edmonds-Karp 算法(最大网络流) 14. Dinic 算法(最大网络流) 15. 一般预流推进算法 16. 最高标号预流推进 HLPP 算法 17. Primal-Dual 原始对偶算法(最小费用流)18. Kosaraju 算法(有向图强连通分量) 19. Tarjan 算法(有向图强连通分量) 20. Gabow 算法(有向图强连通分量) 21. 匈牙利算法(二分图匹配) 22. Hopcroft-Karp 算法(二分图匹配) 23. kuhn munkras 算法(二分图最佳匹配) 24. Edmonds’ Blossom-Contraction 算法(一般图匹配) |1. 图遍历 2. 有向图和无向图的强弱连通性 3. 割点/割边 3. AOV 网络和拓扑排序 4. AOE 网络和关键路径 5. 最小代价生成树/次小生成树 6. 最短路径问题/第 K 短路问题 7. 最大网络流问题 8. 最小费用流问题 9. 图着色问题 10. 差分约束系统 11. 欧拉回路 12. 中国邮递员问题 13. 汉密尔顿回路 14. 最佳边割集/最佳点割集/最小边割集/最小点割集/最小路径覆盖/最小点集覆盖 15. 边覆盖集 16. 二分图完美匹配和最大匹配问题 17. 仙人掌图 18. 弦图 19. 稳定婚姻问题 20. 最大团问题 ||
+|数论||1. 最大公约数 2. 最小公倍数 3. 分解质因数 4. 素数判定 5. 进制转换 6. 高精度计算 7. 整除问题 8. 同余问题 9. 欧拉函数 10. 扩展欧几里得 11. 置换群 12. 母函数 13. 离散变换 14. 康托展开 15. 矩阵 16. 向量 17. 线性方程组 18. 线性规划 ||
+|几何||1. 凸包 - Gift wrapping 2. 凸包 - Graham scan 3. 线段问题 4. 多边形和多面体相关问题 ||
+|NP 完全|1. 计算模型 2. P 类与 NP 类问题 3. NP 完全问题 4. NP 完全问题的近似算法 |1. 随机存取机 RAM 2. 随机存取存储程序机 RASP 3. 图灵机 4. 非确定性图灵机 5. P 类与 NP 类语言 6. 多项式时间验证 7. 多项式时间变换 8. Cook定理 9. 合取范式的可满足性问题 CNF-SAT 10. 3 元合取范式的可满足性问题 3-SAT 11. 团问题 CLIQUE 12. 顶点覆盖问题 VERTEX-COVER 13. 子集和问题 SUBSET-SUM 14. 哈密顿回路问题 HAM-CYCLE 15. 旅行售货员问题 TSP 16. 顶点覆盖问题的近似算法 17. 旅行售货员问题近似算法 18. 具有三角不等式性质的旅行售货员问题 19. 一般的旅行售货员问题 20. 集合覆盖问题的近似算法 21. 子集和问题的近似算法 22. 子集和问题的指数时间算法 23. 子集和问题的多项式时间近似格式 ||
+|------------|------------------------------------------------------------------|-----------------------------------------------------------------|--------------------|
+
+
+## LeetCode Problems
+
+## 一. 个人数据
+
+{{.PersonalData}}
+
+## 二. 目录
+
+{{.TotalNum}}
+
+{{.AvailableTable}}
+
+------------------------------------------------------------------
+
+下面这些是免费的算法题,但是暂时还不能使用 Go 解答的:
+
+暂无
+
+------------------------------------------------------------------
+
+
+## 三.分类
+
+## Array
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Array/)
+
+
+
+## String
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/String/)
+
+
+## Two Pointers
+
+
+
+- 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
+
+```c
+ left, right := 0, -1
+
+ for left < len(s) {
+ if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
+ freq[s[right+1]-'a']++
+ right++
+ } else {
+ freq[s[left]-'a']--
+ left++
+ }
+ result = max(result, right-left+1)
+ }
+```
+
+- 快慢指针可以查找重复数字,时间复杂度 O(n),第 287 题。
+- 替换字母以后,相同字母能出现连续最长的长度。第 424 题。
+- SUM 问题集。第 1 题,第 15 题,第 16 题,第 18 题,第 167 题,第 923 题,第 1074 题。
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Two_Pointers/)
+
+
+## Linked List
+
+
+
+
+- 巧妙的构造虚拟头结点。可以使遍历处理逻辑更加统一。
+- 灵活使用递归。构造递归条件,使用递归可以巧妙的解题。不过需要注意有些题目不能使用递归,因为递归深度太深会导致超时和栈溢出。
+- 链表区间逆序。第 92 题。
+- 链表寻找中间节点。第 876 题。链表寻找倒数第 n 个节点。第 19 题。只需要一次遍历就可以得到答案。
+- 合并 K 个有序链表。第 21 题,第 23 题。
+- 链表归类。第 86 题,第 328 题。
+- 链表排序,时间复杂度要求 O(n * log n),空间复杂度 O(1)。只有一种做法,归并排序,至顶向下归并。第 148 题。
+- 判断链表是否存在环,如果有环,输出环的交叉点的下标;判断 2 个链表是否有交叉点,如果有交叉点,输出交叉点。第 141 题,第 142 题,第 160 题。
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Linked_List/)
+
+
+
+
+## Stack
+
+
+
+- 括号匹配问题及类似问题。第 20 题,第 921 题,第 1021 题。
+- 栈的基本 pop 和 push 操作。第 71 题,第 150 题,第 155 题,第 224 题,第 225 题,第 232 题,第 946 题,第 1047 题。
+- 利用栈进行编码问题。第 394 题,第 682 题,第 856 题,第 880 题。
+- **单调栈**。**利用栈维护一个单调递增或者递减的下标数组**。第 84 题,第 456 题,第 496 题,第 503 题,第 739 题,第 901 题,第 907 题,第 1019 题。
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Stack/)
+
+
+
+## Tree
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Tree/)
+
+
+
+
+
+## Dynamic Programming
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Dynamic_Programming/)
+
+
+
+## Backtracking
+
+
+
+- 排列问题 Permutations。第 46 题,第 47 题。第 60 题,第 526 题,第 996 题。
+- 组合问题 Combination。第 39 题,第 40 题,第 77 题,第 216 题。
+- 排列和组合杂交问题。第 1079 题。
+- N 皇后终极解法(二进制解法)。第 51 题,第 52 题。
+- 数独问题。第 37 题。
+- 四个方向搜索。第 79 题,第 212 题,第 980 题。
+- 子集合问题。第 78 题,第 90 题。
+- Trie。第 208 题,第 211 题。
+- BFS 优化。第 126 题,第 127 题。
+- DFS 模板。(只是一个例子,不对应任何题)
+
+```go
+func combinationSum2(candidates []int, target int) [][]int {
+ if len(candidates) == 0 {
+ return [][]int{}
+ }
+ c, res := []int{}, [][]int{}
+ sort.Ints(candidates)
+ findcombinationSum2(candidates, target, 0, c, &res)
+ return res
+}
+
+func findcombinationSum2(nums []int, target, index int, c []int, res *[][]int) {
+ if target == 0 {
+ b := make([]int, len(c))
+ copy(b, c)
+ *res = append(*res, b)
+ return
+ }
+ for i := index; i < len(nums); i++ {
+ if i > index && nums[i] == nums[i-1] { // 这里是去重的关键逻辑
+ continue
+ }
+ if target >= nums[i] {
+ c = append(c, nums[i])
+ findcombinationSum2(nums, target-nums[i], i+1, c, res)
+ c = c[:len(c)-1]
+ }
+ }
+}
+```
+- BFS 模板。(只是一个例子,不对应任何题)
+
+```go
+func updateMatrix_BFS(matrix [][]int) [][]int {
+ res := make([][]int, len(matrix))
+ if len(matrix) == 0 || len(matrix[0]) == 0 {
+ return res
+ }
+ queue := make([][]int, 0)
+ for i, _ := range matrix {
+ res[i] = make([]int, len(matrix[0]))
+ for j, _ := range res[i] {
+ if matrix[i][j] == 0 {
+ res[i][j] = -1
+ queue = append(queue, []int{i, j})
+ }
+ }
+ }
+ level := 1
+ for len(queue) > 0 {
+ size := len(queue)
+ for size > 0 {
+ size -= 1
+ node := queue[0]
+ queue = queue[1:]
+ i, j := node[0], node[1]
+ for _, direction := range [][]int{{-1, 0}, {1, 0}, {0, 1}, {0, -1}} {
+ x := i + direction[0]
+ y := j + direction[1]
+ if x < 0 || x >= len(matrix) || y < 0 || y >= len(matrix[0]) || res[x][y] < 0 || res[x][y] > 0 {
+ continue
+ }
+ res[x][y] = level
+ queue = append(queue, []int{x, y})
+ }
+ }
+ level++
+ }
+ for i, row := range res {
+ for j, cell := range row {
+ if cell == -1 {
+ res[i][j] = 0
+ }
+ }
+ }
+ return res
+}
+```
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Backtracking/)
+
+
+## Depth First Search
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Depth_First_Search/)
+
+
+
+
+## Breadth First Search
+
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Breadth_First_Search/)
+
+
+
+
+
+## Binary Search
+
+![]()
+
+- 二分搜索的经典写法。需要注意的三点:
+ 1. 循环退出条件,注意是 low <= high,而不是 low < high。
+ 2. mid 的取值,mid := low + (high-low)>>1
+ 3. low 和 high 的更新。low = mid + 1,high = mid - 1。
+
+```go
+func binarySearchMatrix(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + (high-low)>>1
+ if nums[mid] == target {
+ return mid
+ } else if nums[mid] > target {
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ }
+ return -1
+}
+```
+
+- 二分搜索的变种写法。有 4 个基本变种:
+ 1. 查找第一个与 target 相等的元素,时间复杂度 O(logn)
+ 2. 查找最后一个与 target 相等的元素,时间复杂度 O(logn)
+ 3. 查找第一个大于等于 target 的元素,时间复杂度 O(logn)
+ 4. 查找最后一个小于等于 target 的元素,时间复杂度 O(logn)
+
+```go
+// 二分查找第一个与 target 相等的元素,时间复杂度 O(logn)
+func searchFirstEqualElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] > target {
+ high = mid - 1
+ } else if nums[mid] < target {
+ low = mid + 1
+ } else {
+ if (mid == 0) || (nums[mid-1] != target) { // 找到第一个与 target 相等的元素
+ return mid
+ }
+ high = mid - 1
+ }
+ }
+ return -1
+}
+
+// 二分查找最后一个与 target 相等的元素,时间复杂度 O(logn)
+func searchLastEqualElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] > target {
+ high = mid - 1
+ } else if nums[mid] < target {
+ low = mid + 1
+ } else {
+ if (mid == len(nums)-1) || (nums[mid+1] != target) { // 找到最后一个与 target 相等的元素
+ return mid
+ }
+ low = mid + 1
+ }
+ }
+ return -1
+}
+
+// 二分查找第一个大于等于 target 的元素,时间复杂度 O(logn)
+func searchFirstGreaterElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] >= target {
+ if (mid == 0) || (nums[mid-1] < target) { // 找到第一个大于等于 target 的元素
+ return mid
+ }
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ }
+ return -1
+}
+
+// 二分查找最后一个小于等于 target 的元素,时间复杂度 O(logn)
+func searchLastLessElement(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ if nums[mid] <= target {
+ if (mid == len(nums)-1) || (nums[mid+1] > target) { // 找到最后一个小于等于 target 的元素
+ return mid
+ }
+ low = mid + 1
+ } else {
+ high = mid - 1
+ }
+ }
+ return -1
+}
+```
+
+- 在基本有序的数组中用二分搜索。经典解法可以解,变种写法也可以写,常见的题型,在山峰数组中找山峰,在旋转有序数组中找分界点。第 33 题,第 81 题,第 153 题,第 154 题,第 162 题,第 852 题
+
+```go
+func peakIndexInMountainArray(A []int) int {
+ low, high := 0, len(A)-1
+ for low < high {
+ mid := low + (high-low)>>1
+ // 如果 mid 较大,则左侧存在峰值,high = m,如果 mid + 1 较大,则右侧存在峰值,low = mid + 1
+ if A[mid] > A[mid+1] {
+ high = mid
+ } else {
+ low = mid + 1
+ }
+ }
+ return low
+}
+```
+
+- max-min 最大值最小化问题。求在最小满足条件的情况下的最大值。第 410 题,第 875 题,第 1011 题,第 1283 题。
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Binary_Search/)
+
+
+
+## Math
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Math/)
+
+
+
+
+## Hash Table
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Hash_Table/)
+
+
+
+## Sort
+
+
+
+- 深刻的理解多路快排。第 75 题。
+- 链表的排序,插入排序(第 147 题)和归并排序(第 148 题)
+- 桶排序和基数排序。第 164 题。
+- "摆动排序"。第 324 题。
+- 两两不相邻的排序。第 767 题,第 1054 题。
+- "饼子排序"。第 969 题。
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Sort/)
+
+
+## Bit Manipulation
+
+
+
+- 异或的特性。第 136 题,第 268 题,第 389 题,第 421 题,
+
+```go
+x ^ 0 = x
+x ^ 11111……1111 = ~x
+x ^ (~x) = 11111……1111
+x ^ x = 0
+a ^ b = c => a ^ c = b => b ^ c = a (交换律)
+a ^ b ^ c = a ^ (b ^ c) = (a ^ b)^ c (结合律)
+```
+
+- 构造特殊 Mask,将特殊位置放 0 或 1。
+
+```go
+将 x 最右边的 n 位清零, x & ( ~0 << n )
+获取 x 的第 n 位值(0 或者 1),(x >> n) & 1
+获取 x 的第 n 位的幂值,x & (1 << (n - 1))
+仅将第 n 位置为 1,x | (1 << n)
+仅将第 n 位置为 0,x & (~(1 << n))
+将 x 最高位至第 n 位(含)清零,x & ((1 << n) - 1)
+将第 n 位至第 0 位(含)清零,x & (~((1 << (n + 1)) - 1))
+```
+
+- 有特殊意义的 & 位操作运算。第 260 题,第 201 题,第 318 题,第 371 题,第 397 题,第 461 题,第 693 题,
+
+```go
+X & 1 == 1 判断是否是奇数(偶数)
+X & = (X - 1) 将最低位(LSB)的 1 清零
+X & -X 得到最低位(LSB)的 1
+X & ~X = 0
+```
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Bit_Manipulation/)
+
+
+## Union Find
+
+
+
+- 灵活使用并查集的思想,熟练掌握并查集的[模板](https://github.com/halfrost/LeetCode-Go/blob/master/template/UnionFind.go),模板中有两种并查集的实现方式,一种是路径压缩 + 秩优化的版本,另外一种是计算每个集合中元素的个数 + 最大集合元素个数的版本,这两种版本都有各自使用的地方。能使用第一类并查集模板的题目有:第 128 题,第 130 题,第 547 题,第 684 题,第 721 题,第 765 题,第 778 题,第 839 题,第 924 题,第 928 题,第 947 题,第 952 题,第 959 题,第 990 题。能使用第二类并查集模板的题目有:第 803 题,第 952 题。第 803 题秩优化和统计集合个数这些地方会卡时间,如果不优化,会 TLE。
+- 并查集是一种思想,有些题需要灵活使用这种思想,而不是死套模板,如第 399 题,这一题是 stringUnionFind,利用并查集思想实现的。这里每个节点是基于字符串和 map 的,而不是单纯的用 int 节点编号实现的。
+- 有些题死套模板反而做不出来,比如第 685 题,这一题不能路径压缩和秩优化,因为题目中涉及到有向图,需要知道节点的前驱节点,如果路径压缩了,这一题就没法做了。这一题不需要路径压缩和秩优化。
+- 灵活的抽象题目给的信息,将给定的信息合理的编号,使用并查集解题,并用 map 降低时间复杂度,如第 721 题,第 959 题。
+- 关于地图,砖块,网格的题目,可以新建一个特殊节点,将四周边缘的砖块或者网格都 union() 到这个特殊节点上。第 130 题,第 803 题。
+- 能用并查集的题目,一般也可以用 DFS 和 BFS 解答,只不过时间复杂度会高一点。
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Union_Find/)
+
+
+
+## Sliding Window
+
+
+
+- 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
+
+```c
+ left, right := 0, -1
+
+ for left < len(s) {
+ if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
+ freq[s[right+1]-'a']++
+ right++
+ } else {
+ freq[s[left]-'a']--
+ left++
+ }
+ result = max(result, right-left+1)
+ }
+```
+- 滑动窗口经典题。第 239 题,第 480 题。
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Sliding_Window/)
+
+
+## Segment Tree
+
+
+
+- 线段树的经典数组实现写法。将合并两个节点 pushUp 逻辑抽象出来了,可以实现任意操作(常见的操作有:加法,取 max,min 等等)。第 218 题,第 303 题,第 307 题,第 699 题。
+- 计数线段树的经典写法。第 315 题,第 327 题,第 493 题。
+- 线段树的树的实现写法。第 715 题,第 732 题。
+- 区间懒惰更新。第 218 题,第 699 题。
+- 离散化。离散化需要注意一个特殊情况:假如三个区间为 [1,10] [1,4] [6,10],离散化后 x[1]=1,x[2]=4,x[3]=6,x[4]=10。第一个区间为 [1,4],第二个区间为 [1,2],第三个区间为 [3,4],这样一来,区间一 = 区间二 + 区间三,这和离散前的模型不符,离散前,很明显,区间一 > 区间二 + 区间三。正确的做法是:在相差大于 1 的数间加一个数,例如在上面 1 4 6 10 中间加 5,即可 x[1]=1,x[2]=4,x[3]=5,x[4]=6,x[5]=10。这样处理之后,区间一是 1-5 ,区间二是 1-2 ,区间三是 4-5 。
+- 灵活构建线段树。线段树节点可以存储多条信息,合并两个节点的 pushUp 操作也可以是多样的。第 850 题,第 1157 题。
+
+
+线段树[题型](https://blog.csdn.net/xuechelingxiao/article/details/38313105)从简单到困难:
+
+1. 单点更新:
+ [HDU 1166 敌兵布阵](http://acm.hdu.edu.cn/showproblem.php?pid=1166) update:单点增减 query:区间求和
+ [HDU 1754 I Hate It](http://acm.hdu.edu.cn/showproblem.php?pid=1754) update:单点替换 query:区间最值
+ [HDU 1394 Minimum Inversion Number](http://acm.hdu.edu.cn/showproblem.php?pid=1394) update:单点增减 query:区间求和
+ [HDU 2795 Billboard](http://acm.hdu.edu.cn/showproblem.php?pid=2795) query:区间求最大值的位子(直接把update的操作在query里做了)
+2. 区间更新:
+ [HDU 1698 Just a Hook](http://acm.hdu.edu.cn/showproblem.php?pid=1698) update:成段替换 (由于只query一次总区间,所以可以直接输出 1 结点的信息)
+ [POJ 3468 A Simple Problem with Integers](http://poj.org/problem?id=3468) update:成段增减 query:区间求和
+ [POJ 2528 Mayor’s posters](http://poj.org/problem?id=2528) 离散化 + update:成段替换 query:简单hash
+ [POJ 3225 Help with Intervals](http://poj.org/problem?id=3225) update:成段替换,区间异或 query:简单hash
+3. 区间合并(这类题目会询问区间中满足条件的连续最长区间,所以PushUp的时候需要对左右儿子的区间进行合并):
+ [POJ 3667 Hotel](http://poj.org/problem?id=3667) update:区间替换 query:询问满足条件的最左端点
+4. 扫描线(这类题目需要将一些操作排序,然后从左到右用一根扫描线扫过去最典型的就是矩形面积并,周长并等题):
+ [HDU 1542 Atlantis](http://acm.hdu.edu.cn/showproblem.php?pid=1542) update:区间增减 query:直接取根节点的值
+ [HDU 1828 Picture](http://acm.hdu.edu.cn/showproblem.php?pid=1828) update:区间增减 query:直接取根节点的值
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Segment_Tree/)
+
+
+## Binary Indexed Tree
+
+
+
+Problems List in [there](https://books.halfrost.com/leetcode/ChapterTwo/Binary_Indexed_Tree/)
+
+
+----------------------------------------------------------------------------------------
+
+
+
+
+
+Thank you for reading here. This is bonus. You can download my [《ACM-ICPC Algorithm Template》](https://github.com/halfrost/LeetCode-Go/releases/tag/Special/)
+
+
+
+## ♥️ Thanks
+
+Thanks for your Star!
+
+[](https://starchart.cc/halfrost/LeetCode-Go)
+
diff --git a/ctl/template_render.go b/ctl/template_render.go
new file mode 100644
index 00000000..374b36f8
--- /dev/null
+++ b/ctl/template_render.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ m "github.com/halfrost/LeetCode-Go/ctl/models"
+ "github.com/halfrost/LeetCode-Go/ctl/util"
+ "html/template"
+ "io/ioutil"
+ "os"
+)
+
+func makeReadmeFile(mdrows m.Mdrows) {
+ file := "./README.md"
+ os.Remove(file)
+ var b bytes.Buffer
+ tmpl := template.Must(template.New("readme").Parse(readTMPL("template.markdown")))
+ err := tmpl.Execute(&b, mdrows)
+ if err != nil {
+ fmt.Println(err)
+ }
+ // 保存 README.md 文件
+ util.WriteFile(file, b.Bytes())
+}
+
+func readTMPL(path string) string {
+ file, err := os.Open(path)
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer file.Close()
+
+ data, err := ioutil.ReadAll(file)
+ if err != nil {
+ fmt.Println(err)
+ }
+ return string(data)
+}
diff --git a/ctl/util/util.go b/ctl/util/util.go
new file mode 100644
index 00000000..21226991
--- /dev/null
+++ b/ctl/util/util.go
@@ -0,0 +1,168 @@
+package util
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "sort"
+ "strconv"
+ "strings"
+)
+
+// LoadSolutionsDir define
+func LoadSolutionsDir() ([]int, []string, int) {
+ solutionIds, soNames, total := loadFile("../leetcode/")
+ fmt.Printf("读取了 %v 道题的题解,当前目录下有 %v 个文件(可能包含 .DS_Store),目录中有 %v 道题在尝试中\n", len(solutionIds), total, total-len(solutionIds))
+ return solutionIds, soNames, total - len(solutionIds)
+}
+
+// LoadChapterFourIds define
+func LoadChapterFourIds() ([]int, []string) {
+ solutionIds, soNames, _ := loadFile("../website/content/ChapterFour/")
+ fmt.Printf("读取了第四章 %v 道题的题解\n", len(solutionIds))
+ return solutionIds, soNames
+}
+
+func loadFile(path string) ([]int, []string, int) {
+ files, err := ioutil.ReadDir(path)
+ if err != nil {
+ fmt.Println(err)
+ }
+ solutionIds, soNames, solutionsMap := []int{}, []string{}, map[int]string{}
+ for _, f := range files {
+ if f.Name()[4] == '.' {
+ tmp, err := strconv.Atoi(f.Name()[:4])
+ if err != nil {
+ fmt.Println(err)
+ }
+ solutionIds = append(solutionIds, tmp)
+ solutionsMap[tmp] = f.Name()
+ }
+ }
+ sort.Ints(solutionIds)
+ for _, v := range solutionIds {
+ if name, ok := solutionsMap[v]; ok {
+ soNames = append(soNames, name)
+ }
+ }
+ return solutionIds, soNames, len(files)
+}
+
+// LoadChapterFourDir define
+func LoadChapterFourDir() []string {
+ files, err := ioutil.ReadDir("../website/content/ChapterFour/")
+ if err != nil {
+ fmt.Println(err)
+ }
+ solutions, solutionIds, solutionsMap := []string{}, []int{}, map[int]string{}
+ for _, f := range files {
+ if f.Name()[4] == '.' {
+ tmp, err := strconv.Atoi(f.Name()[:4])
+ if err != nil {
+ fmt.Println(err)
+ }
+ solutionIds = append(solutionIds, tmp)
+ // len(f.Name())-3 = 文件名去掉 .md 后缀
+ solutionsMap[tmp] = f.Name()[:len(f.Name())-3]
+ }
+ }
+ sort.Ints(solutionIds)
+ fmt.Printf("读取了第四章的 %v 道题的题解\n", len(solutionIds))
+ for _, v := range solutionIds {
+ if name, ok := solutionsMap[v]; ok {
+ solutions = append(solutions, name)
+ }
+ }
+ return solutions
+}
+
+// WriteFile define
+func WriteFile(fileName string, content []byte) {
+ file, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0777)
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer file.Close()
+
+ _, err = file.Write(content)
+ if err != nil {
+ fmt.Println(err)
+ }
+ //fmt.Println("write file successful")
+}
+
+// LoadFile define
+func LoadFile(filePath string) ([]byte, error) {
+ f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ reader, output := bufio.NewReader(f), []byte{}
+ for {
+ line, _, err := reader.ReadLine()
+ if err != nil {
+ if err == io.EOF {
+ return output, nil
+ }
+ return nil, err
+ }
+ output = append(output, line...)
+ output = append(output, []byte("\n")...)
+ }
+}
+
+// DestoryDir define
+func DestoryDir(path string) {
+ filepath.Walk(path, func(path string, fi os.FileInfo, err error) error {
+ if nil == fi {
+ return err
+ }
+ if !fi.IsDir() {
+ return nil
+ }
+ name := fi.Name()
+ if strings.Contains(name, "temp") {
+ fmt.Println("temp file name:", path)
+ err := os.RemoveAll(path)
+ if err != nil {
+ fmt.Println("delet dir error:", err)
+ }
+ }
+ return nil
+ })
+}
+
+// CopyFile define
+func CopyFile(dstName, srcName string) (written int64, err error) {
+ src, err := os.Open(srcName)
+ if err != nil {
+ return
+ }
+ defer src.Close()
+ dst, err := os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE, 0644)
+ if err != nil {
+ return
+ }
+ defer dst.Close()
+ return io.Copy(dst, src)
+}
+
+// BinarySearch define
+func BinarySearch(nums []int, target int) int {
+ low, high := 0, len(nums)-1
+ for low <= high {
+ mid := low + (high-low)>>1
+ if nums[mid] == target {
+ return mid
+ } else if nums[mid] > target {
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ }
+ return -1
+}
diff --git a/ctl/version.go b/ctl/version.go
new file mode 100644
index 00000000..c996a651
--- /dev/null
+++ b/ctl/version.go
@@ -0,0 +1,18 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/spf13/cobra"
+)
+
+var (
+ version = "v1.0"
+ versionCmd = &cobra.Command{
+ Use: "version",
+ Short: "Prints the version of tacoctl",
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("tacoctl version:", version)
+ },
+ }
+)
diff --git a/go.mod b/go.mod
new file mode 100644
index 00000000..ef681142
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,16 @@
+module github.com/halfrost/LeetCode-Go
+
+go 1.15
+
+require (
+ github.com/BurntSushi/toml v0.3.1
+ github.com/bitly/go-simplejson v0.5.0 // indirect
+ github.com/graphql-go/graphql v0.7.9
+ github.com/keegancsmith/rpc v1.3.0 // indirect
+ github.com/mozillazg/request v0.8.0
+ github.com/nsf/gocode v0.0.0-20190302080247-5bee97b48836 // indirect
+ github.com/spf13/cobra v1.1.1
+ github.com/stamblerre/gocode v1.0.0 // indirect
+ golang.org/x/mod v0.4.0 // indirect
+ golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58 // indirect
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 00000000..0d8cc757
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,321 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
+cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
+cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
+cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
+cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
+cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
+cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
+cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
+cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
+cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
+dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
+github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
+github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
+github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
+github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
+github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
+github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
+github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
+github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
+github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
+github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
+github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
+github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
+github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
+github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
+github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
+github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
+github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
+github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
+github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
+github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
+github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
+github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
+github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
+github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
+github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
+github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
+github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
+github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
+github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
+github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
+github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
+github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
+github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
+github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/graphql-go/graphql v0.7.9 h1:5Va/Rt4l5g3YjwDnid3vFfn43faaQBq7rMcIZ0VnV34=
+github.com/graphql-go/graphql v0.7.9/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI=
+github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
+github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
+github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
+github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
+github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
+github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
+github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
+github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
+github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
+github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
+github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
+github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
+github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
+github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
+github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
+github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
+github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
+github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
+github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
+github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
+github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
+github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
+github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
+github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
+github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
+github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
+github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
+github.com/keegancsmith/rpc v1.1.0 h1:bXVRk3EzbtrEegTGKxNTc+St1lR7t/Z1PAO8misBnCc=
+github.com/keegancsmith/rpc v1.1.0/go.mod h1:Xow74TKX34OPPiPCdz6x1o9c0SCxRqGxDuKGk7ZOo8s=
+github.com/keegancsmith/rpc v1.3.0 h1:wGWOpjcNrZaY8GDYZJfvyxmlLljm3YQWF+p918DXtDk=
+github.com/keegancsmith/rpc v1.3.0/go.mod h1:6O2xnOGjPyvIPbvp0MdrOe5r6cu1GZ4JoTzpzDhWeo0=
+github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
+github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
+github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
+github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
+github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
+github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
+github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
+github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
+github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
+github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
+github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
+github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/mozillazg/request v0.8.0 h1:TbXeQUdBWr1J1df5Z+lQczDFzX9JD71kTCl7Zu/9rNM=
+github.com/mozillazg/request v0.8.0/go.mod h1:weoQ/mVFNbWgRBtivCGF1tUT9lwneFesues+CleXMWc=
+github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
+github.com/nsf/gocode v0.0.0-20190302080247-5bee97b48836 h1:oc3CL18CoGhyOQJ7HDa9gJAde33bwI8Vi28zLdIzJVc=
+github.com/nsf/gocode v0.0.0-20190302080247-5bee97b48836/go.mod h1:6Q8/OMaaKAgTX7/jt2bOXVDrm1eJhoNd+iwzghR7jvs=
+github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
+github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
+github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
+github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
+github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
+github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
+github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
+github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
+github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
+github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
+github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
+github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
+github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
+github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
+github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
+github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
+github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
+github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
+github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
+github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
+github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
+github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
+github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
+github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
+github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
+github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
+github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
+github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
+github.com/stamblerre/gocode v1.0.0 h1:5aTRgkRTOS8mELHoKatkwhfX44OdEV3iwu3FCXyvLzk=
+github.com/stamblerre/gocode v1.0.0/go.mod h1:ONyGamdxpnxaG2+XLyGkNuuoYISmz0QFVHScxvsXsqM=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
+github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
+github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
+go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
+go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
+go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
+go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
+go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
+golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
+golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
+golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
+golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
+golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
+golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
+golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
+golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
+golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
+golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
+golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
+golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
+golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
+golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab h1:tpc/nJ4vD66vAk/2KN0sw/DvQIz2sKmCpWvyKtPmfMQ=
+golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58 h1:1Bs6RVeBFtLZ8Yi1Hk07DiOqzvwLD/4hln4iahvFlag=
+golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
+google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
+google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
+google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
+google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
+google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
+google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
+gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
+gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
+gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
+gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
+rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
diff --git a/leetcode/0015.3Sum/15. 3Sum.go b/leetcode/0015.3Sum/15. 3Sum.go
index ea643c8c..7b6bd93e 100644
--- a/leetcode/0015.3Sum/15. 3Sum.go
+++ b/leetcode/0015.3Sum/15. 3Sum.go
@@ -4,7 +4,44 @@ import (
"sort"
)
+// 解法一 最优解,双指针 + 排序
func threeSum(nums []int) [][]int {
+ sort.Ints(nums)
+ result, start, end, index, addNum, length := make([][]int, 0), 0, 0, 0, 0, len(nums)
+ if length > 0 && (nums[0] > 0 || nums[length-1] < 0) {
+ return result
+ }
+ for index = 1; index < length-1; index++ {
+ start, end = 0, length-1
+ if index > 1 && nums[index] == nums[index-1] {
+ start = index - 1
+ }
+ for start < index && end > index {
+ if start > 0 && nums[start] == nums[start-1] {
+ start++
+ continue
+ }
+ if end < length-1 && nums[end] == nums[end+1] {
+ end--
+ continue
+ }
+ addNum = nums[start] + nums[end] + nums[index]
+ if addNum == 0 {
+ result = append(result, []int{nums[start], nums[index], nums[end]})
+ start++
+ end--
+ } else if addNum > 0 {
+ end--
+ } else {
+ start++
+ }
+ }
+ }
+ return result
+}
+
+// 解法二
+func threeSum1(nums []int) [][]int {
res := [][]int{}
counter := map[int]int{}
for _, value := range nums {
diff --git a/leetcode/0027.Remove-Element/27. Remove Element.go b/leetcode/0027.Remove-Element/27. Remove Element.go
index f0233b6a..1395d108 100644
--- a/leetcode/0027.Remove-Element/27. Remove Element.go
+++ b/leetcode/0027.Remove-Element/27. Remove Element.go
@@ -9,10 +9,8 @@ func removeElement(nums []int, val int) int {
if nums[i] != val {
if i != j {
nums[i], nums[j] = nums[j], nums[i]
- j++
- } else {
- j++
}
+ j++
}
}
return j
diff --git a/leetcode/0082.Remove-Duplicates-from-Sorted-List-II/82. Remove Duplicates from Sorted List II.go b/leetcode/0082.Remove-Duplicates-from-Sorted-List-II/82. Remove Duplicates from Sorted List II.go
index 1fd71973..aa08a6ce 100644
--- a/leetcode/0082.Remove-Duplicates-from-Sorted-List-II/82. Remove Duplicates from Sorted List II.go
+++ b/leetcode/0082.Remove-Duplicates-from-Sorted-List-II/82. Remove Duplicates from Sorted List II.go
@@ -91,3 +91,66 @@ func deleteDuplicates(head *ListNode) *ListNode {
}
return head
}
+
+// 双循环简单解法 O(n*m)
+func deleteDuplicates3(head *ListNode) *ListNode {
+ if head == nil {
+ return head
+ }
+
+ nilNode := &ListNode{Val: 0, Next: head}
+ head = nilNode
+
+ lastVal := 0
+ for head.Next != nil && head.Next.Next != nil {
+ if head.Next.Val == head.Next.Next.Val {
+ lastVal = head.Next.Val
+ for head.Next != nil && lastVal == head.Next.Val {
+ head.Next = head.Next.Next
+ }
+ } else {
+ head = head.Next
+ }
+ }
+ return nilNode.Next
+}
+
+// 双指针+删除标志位,单循环解法 O(n)
+func deleteDuplicates4(head *ListNode) *ListNode {
+ if head == nil || head.Next == nil {
+ return head
+ }
+
+ nilNode := &ListNode{Val: 0, Next: head}
+ // 上次遍历有删除操作的标志位
+ lastIsDel := false
+ // 虚拟空结点
+ head = nilNode
+ // 前后指针用于判断
+ pre, back := head.Next, head.Next.Next
+ // 每次只删除前面的一个重复的元素,留一个用于下次遍历判重
+ // pre, back 指针的更新位置和值比较重要和巧妙
+ for head.Next != nil && head.Next.Next != nil {
+ if pre.Val != back.Val && lastIsDel {
+ head.Next = head.Next.Next
+ pre, back = head.Next, head.Next.Next
+ lastIsDel = false
+ continue
+ }
+
+ if pre.Val == back.Val {
+ head.Next = head.Next.Next
+ pre, back = head.Next, head.Next.Next
+ lastIsDel = true
+ } else {
+ head = head.Next
+ pre, back = head.Next, head.Next.Next
+ lastIsDel = false
+ }
+ }
+ // 处理 [1,1] 这种删除还剩一个的情况
+ if lastIsDel && head.Next != nil {
+ head.Next = nil
+ }
+ return nilNode.Next
+}
diff --git a/leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal.go b/leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal.go
index 30e3d452..dc8f398d 100644
--- a/leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal.go
+++ b/leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal.go
@@ -16,6 +16,7 @@ type TreeNode = structures.TreeNode
* }
*/
+// 解法一
func zigzagLevelOrder(root *TreeNode) [][]int {
if root == nil {
return [][]int{}
@@ -57,3 +58,26 @@ func zigzagLevelOrder(root *TreeNode) [][]int {
}
return res
}
+
+// 解法二 递归
+func zigzagLevelOrder0(root *TreeNode) [][]int {
+ var res [][]int
+ search(root, 0, &res)
+ return res
+}
+
+func search(root *TreeNode, depth int, res *[][]int) {
+ if root == nil {
+ return
+ }
+ for len(*res) < depth+1 {
+ *res = append(*res, []int{})
+ }
+ if depth%2 == 0 {
+ (*res)[depth] = append((*res)[depth], root.Val)
+ } else {
+ (*res)[depth] = append([]int{root.Val}, (*res)[depth]...)
+ }
+ search(root.Left, depth+1, res)
+ search(root.Right, depth+1, res)
+}
diff --git a/leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/README.md b/leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/README.md
index 0c0c91ae..692a49ca 100644
--- a/leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/README.md
+++ b/leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/README.md
@@ -27,4 +27,5 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig
## 解题思路
-思路比较简单,依次把链表的中间点作为根结点,类似二分的思想,递归排列所有结点即可。
\ No newline at end of file
+思路比较简单,依次把链表的中间点作为根结点,类似二分的思想,递归排列所有结点即可。
+
diff --git a/leetcode/0125.Valid-Palindrome/125. Valid Palindrome.go b/leetcode/0125.Valid-Palindrome/125. Valid Palindrome.go
index ce998bd5..6ccd9200 100644
--- a/leetcode/0125.Valid-Palindrome/125. Valid Palindrome.go
+++ b/leetcode/0125.Valid-Palindrome/125. Valid Palindrome.go
@@ -5,9 +5,7 @@ import (
)
func isPalindrome(s string) bool {
-
s = strings.ToLower(s)
-
i, j := 0, len(s)-1
for i < j {
for i < j && !isChar(s[i]) {
@@ -22,7 +20,6 @@ func isPalindrome(s string) bool {
i++
j--
}
-
return true
}
diff --git a/leetcode/0127.Word-Ladder/README.md b/leetcode/0127.Word-Ladder/README.md
index 9a207836..6575eab2 100755
--- a/leetcode/0127.Word-Ladder/README.md
+++ b/leetcode/0127.Word-Ladder/README.md
@@ -60,6 +60,6 @@ Given two words (*beginWord* and *endWord*), and a dictionary's word list, fin
- 这一题要求输出从 `beginWord` 变换到 `endWord` 最短变换次数。可以用 BFS,从 `beginWord` 开始变换,把该单词的每个字母都用 `'a'~'z'` 变换一次,生成的数组到 `wordList` 中查找,这里用 Map 来记录查找。找得到就入队列,找不到就输出 0 。入队以后按照 BFS 的算法依次遍历完,当所有单词都 `len(queue)<=0` 出队以后,整个程序结束。
- 这一题题目中虽然说了要求找到一条最短的路径,但是实际上最短的路径的寻找方法已经告诉你了:
- 1. 每次只变换一个字母
+ 1. 每次只变换一个字母
2. 每次变换都必须在 `wordList` 中
所以不需要单独考虑何种方式是最短的。
diff --git a/leetcode/0146.LRU-Cache/146. LRU Cache.go b/leetcode/0146.LRU-Cache/146. LRU Cache.go
new file mode 100644
index 00000000..f7a1ae05
--- /dev/null
+++ b/leetcode/0146.LRU-Cache/146. LRU Cache.go
@@ -0,0 +1,71 @@
+package leetcode
+
+type LRUCache struct {
+ head, tail *Node
+ Keys map[int]*Node
+ Cap int
+}
+
+type Node struct {
+ Key, Val int
+ Prev, Next *Node
+}
+
+func Constructor(capacity int) LRUCache {
+ return LRUCache{Keys: make(map[int]*Node), Cap: capacity}
+}
+
+func (this *LRUCache) Get(key int) int {
+ if node, ok := this.Keys[key]; ok {
+ this.Remove(node)
+ this.Add(node)
+ return node.Val
+ }
+ return -1
+}
+
+func (this *LRUCache) Put(key int, value int) {
+ if node, ok := this.Keys[key]; ok {
+ node.Val = value
+ this.Remove(node)
+ this.Add(node)
+ return
+ } else {
+ node = &Node{Key: key, Val: value}
+ this.Keys[key] = node
+ this.Add(node)
+ }
+ if len(this.Keys) > this.Cap {
+ delete(this.Keys, this.tail.Key)
+ this.Remove(this.tail)
+ }
+}
+
+func (this *LRUCache) Add(node *Node) {
+ node.Prev = nil
+ node.Next = this.head
+ if this.head != nil {
+ this.head.Prev = node
+ }
+ this.head = node
+ if this.tail == nil {
+ this.tail = node
+ this.tail.Next = nil
+ }
+}
+
+func (this *LRUCache) Remove(node *Node) {
+ if node == this.head {
+ this.head = node.Next
+ node.Next = nil
+ return
+ }
+ if node == this.tail {
+ this.tail = node.Prev
+ node.Prev.Next = nil
+ node.Prev = nil
+ return
+ }
+ node.Prev.Next = node.Next
+ node.Next.Prev = node.Prev
+}
diff --git a/leetcode/0146.LRU-Cache/146. LRU Cache_test.go b/leetcode/0146.LRU-Cache/146. LRU Cache_test.go
new file mode 100644
index 00000000..9d8d1604
--- /dev/null
+++ b/leetcode/0146.LRU-Cache/146. LRU Cache_test.go
@@ -0,0 +1,40 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+func Test_Problem146(t *testing.T) {
+ obj := Constructor(2)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.Put(1, 1)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.Put(2, 2)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ param1 := obj.Get(1)
+ fmt.Printf("param_1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ obj.Put(3, 3)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ param1 = obj.Get(2)
+ fmt.Printf("param_1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ obj.Put(4, 4)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ param1 = obj.Get(1)
+ fmt.Printf("param_1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.Get(3)
+ fmt.Printf("param_1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.Get(4)
+ fmt.Printf("param_1 = %v obj = %v\n", param1, MList2Ints(&obj))
+}
+
+func MList2Ints(lru *LRUCache) [][]int {
+ res := [][]int{}
+ head := lru.head
+ for head != nil {
+ tmp := []int{head.Key, head.Val}
+ res = append(res, tmp)
+ head = head.Next
+ }
+ return res
+}
diff --git a/leetcode/0146.LRU-Cache/README.md b/leetcode/0146.LRU-Cache/README.md
new file mode 100644
index 00000000..3e5ac858
--- /dev/null
+++ b/leetcode/0146.LRU-Cache/README.md
@@ -0,0 +1,134 @@
+# [146. LRU Cache](https://leetcode.com/problems/lru-cache/)
+
+## 题目
+
+Design a data structure that follows the constraints of a **[Least Recently Used (LRU) cache](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU)**.
+
+Implement the `LRUCache` class:
+
+- `LRUCache(int capacity)` Initialize the LRU cache with **positive** size `capacity`.
+- `int get(int key)` Return the value of the `key` if the key exists, otherwise return `1`.
+- `void put(int key, int value)` Update the value of the `key` if the `key` exists. Otherwise, add the `key-value` pair to the cache. If the number of keys exceeds the `capacity` from this operation, **evict** the least recently used key.
+
+**Follow up:**Could you do `get` and `put` in `O(1)` time complexity?
+
+**Example 1:**
+
+```
+Input
+["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, null, -1, 3, 4]
+
+Explanation
+LRUCache lRUCache = new LRUCache(2);
+lRUCache.put(1, 1); // cache is {1=1}
+lRUCache.put(2, 2); // cache is {1=1, 2=2}
+lRUCache.get(1); // return 1
+lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}
+lRUCache.get(2); // returns -1 (not found)
+lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}
+lRUCache.get(1); // return -1 (not found)
+lRUCache.get(3); // return 3
+lRUCache.get(4); // return 4
+
+```
+
+**Constraints:**
+
+- `1 <= capacity <= 3000`
+- `0 <= key <= 3000`
+- `0 <= value <= 104`
+- At most `3 * 104` calls will be made to `get` and `put`.
+
+## 题目大意
+
+运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制 。
+实现 LRUCache 类:
+
+- LRUCache(int capacity) 以正整数作为容量 capacity 初始化 LRU 缓存
+- int get(int key) 如果关键字 key 存在于缓存中,则返回关键字的值,否则返回 -1 。
+- void put(int key, int value) 如果关键字已经存在,则变更其数据值;如果关键字不存在,则插入该组「关键字-值」。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的数据值,从而为新的数据值留出空间。
+
+进阶:你是否可以在 O(1) 时间复杂度内完成这两种操作?
+
+## 解题思路
+
+- 这一题是 LRU 经典面试题,详细解释见[第三章 LRUCache 模板](https://books.halfrost.com/leetcode/ChapterThree/LRUCache/)。
+
+## 代码
+
+```go
+package leetcode
+
+type LRUCache struct {
+ head, tail *Node
+ Keys map[int]*Node
+ Cap int
+}
+
+type Node struct {
+ Key, Val int
+ Prev, Next *Node
+}
+
+func Constructor(capacity int) LRUCache {
+ return LRUCache{Keys: make(map[int]*Node), Cap: capacity}
+}
+
+func (this *LRUCache) Get(key int) int {
+ if node, ok := this.Keys[key]; ok {
+ this.Remove(node)
+ this.Add(node)
+ return node.Val
+ }
+ return -1
+}
+
+func (this *LRUCache) Put(key int, value int) {
+ if node, ok := this.Keys[key]; ok {
+ node.Val = value
+ this.Remove(node)
+ this.Add(node)
+ return
+ } else {
+ node = &Node{Key: key, Val: value}
+ this.Keys[key] = node
+ this.Add(node)
+ }
+ if len(this.Keys) > this.Cap {
+ delete(this.Keys, this.tail.Key)
+ this.Remove(this.tail)
+ }
+}
+
+func (this *LRUCache) Add(node *Node) {
+ node.Prev = nil
+ node.Next = this.head
+ if this.head != nil {
+ this.head.Prev = node
+ }
+ this.head = node
+ if this.tail == nil {
+ this.tail = node
+ this.tail.Next = nil
+ }
+}
+
+func (this *LRUCache) Remove(node *Node) {
+ if node == this.head {
+ this.head = node.Next
+ node.Next = nil
+ return
+ }
+ if node == this.tail {
+ this.tail = node.Prev
+ node.Prev.Next = nil
+ node.Prev = nil
+ return
+ }
+ node.Prev.Next = node.Next
+ node.Next.Prev = node.Prev
+}
+```
\ No newline at end of file
diff --git a/leetcode/0148.Sort-List/148. Sort List.go b/leetcode/0148.Sort-List/148. Sort List.go
index c5132dbb..2461013f 100644
--- a/leetcode/0148.Sort-List/148. Sort List.go
+++ b/leetcode/0148.Sort-List/148. Sort List.go
@@ -25,17 +25,17 @@ func sortList(head *ListNode) *ListNode {
return head
}
- middleNode := middleNode1(head)
+ middleNode := middleNode(head)
cur = middleNode.Next
middleNode.Next = nil
middleNode = cur
left := sortList(head)
right := sortList(middleNode)
- return mergeTwoLists148(left, right)
+ return mergeTwoLists(left, right)
}
-func middleNode1(head *ListNode) *ListNode {
+func middleNode(head *ListNode) *ListNode {
if head == nil || head.Next == nil {
return head
}
@@ -48,21 +48,6 @@ func middleNode1(head *ListNode) *ListNode {
return p1
}
-func mergeTwoLists148(l1 *ListNode, l2 *ListNode) *ListNode {
- if l1 == nil {
- return l2
- }
- if l2 == nil {
- return l1
- }
- if l1.Val < l2.Val {
- l1.Next = mergeTwoLists(l1.Next, l2)
- return l1
- }
- l2.Next = mergeTwoLists(l1, l2.Next)
- return l2
-}
-
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
if l1 == nil {
return l2
diff --git a/leetcode/0164.Maximum-Gap/164. Maximum Gap.go b/leetcode/0164.Maximum-Gap/164. Maximum Gap.go
index bfe40b51..120334ff 100644
--- a/leetcode/0164.Maximum-Gap/164. Maximum Gap.go
+++ b/leetcode/0164.Maximum-Gap/164. Maximum Gap.go
@@ -1,12 +1,11 @@
package leetcode
-// 解法一
+// 解法一 快排
func maximumGap(nums []int) int {
if len(nums) < 2 {
return 0
}
quickSort164(nums, 0, len(nums)-1)
-
res := 0
for i := 0; i < len(nums)-1; i++ {
if (nums[i+1] - nums[i]) > res {
@@ -37,52 +36,42 @@ func quickSort164(a []int, lo, hi int) {
quickSort164(a, p+1, hi)
}
-// 解法二
+// 解法二 基数排序
func maximumGap1(nums []int) int {
-
if nums == nil || len(nums) < 2 {
return 0
}
-
// m is the maximal number in nums
m := nums[0]
for i := 1; i < len(nums); i++ {
m = max(m, nums[i])
}
-
exp := 1 // 1, 10, 100, 1000 ...
R := 10 // 10 digits
-
aux := make([]int, len(nums))
-
for (m / exp) > 0 { // Go through all digits from LSB to MSB
count := make([]int, R)
-
for i := 0; i < len(nums); i++ {
count[(nums[i]/exp)%10]++
}
-
for i := 1; i < len(count); i++ {
count[i] += count[i-1]
}
-
for i := len(nums) - 1; i >= 0; i-- {
tmp := count[(nums[i]/exp)%10]
tmp--
aux[tmp] = nums[i]
+ count[(nums[i]/exp)%10] = tmp
}
-
for i := 0; i < len(nums); i++ {
nums[i] = aux[i]
}
exp *= 10
}
-
maxValue := 0
for i := 1; i < len(aux); i++ {
maxValue = max(maxValue, aux[i]-aux[i-1])
}
-
return maxValue
}
diff --git a/leetcode/0164.Maximum-Gap/164. Maximum Gap_test.go b/leetcode/0164.Maximum-Gap/164. Maximum Gap_test.go
index 6030dfe2..db38fb38 100644
--- a/leetcode/0164.Maximum-Gap/164. Maximum Gap_test.go
+++ b/leetcode/0164.Maximum-Gap/164. Maximum Gap_test.go
@@ -49,6 +49,11 @@ func Test_Problem164(t *testing.T) {
para164{[]int{2, 435, 214, 64321, 643, 7234, 7, 436523, 7856, 8}},
ans164{372202},
},
+
+ {
+ para164{[]int{1, 10000000}},
+ ans164{9999999},
+ },
}
fmt.Printf("------------------------Leetcode Problem 164------------------------\n")
diff --git a/leetcode/0189.Rotate-Array/189. Rotate Array.go b/leetcode/0189.Rotate-Array/189. Rotate Array.go
new file mode 100644
index 00000000..004b55e6
--- /dev/null
+++ b/leetcode/0189.Rotate-Array/189. Rotate Array.go
@@ -0,0 +1,24 @@
+package leetcode
+
+// 解法一 时间复杂度 O(n),空间复杂度 O(1)
+func rotate(nums []int, k int) {
+ k %= len(nums)
+ reverse(nums)
+ reverse(nums[:k])
+ reverse(nums[k:])
+}
+
+func reverse(a []int) {
+ for i, n := 0, len(a); i < n/2; i++ {
+ a[i], a[n-1-i] = a[n-1-i], a[i]
+ }
+}
+
+// 解法二 时间复杂度 O(n),空间复杂度 O(n)
+func rotate1(nums []int, k int) {
+ newNums := make([]int, len(nums))
+ for i, v := range nums {
+ newNums[(i+k)%len(nums)] = v
+ }
+ copy(nums, newNums)
+}
diff --git a/leetcode/0189.Rotate-Array/189. Rotate Array_test.go b/leetcode/0189.Rotate-Array/189. Rotate Array_test.go
new file mode 100644
index 00000000..a3267c9a
--- /dev/null
+++ b/leetcode/0189.Rotate-Array/189. Rotate Array_test.go
@@ -0,0 +1,50 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question189 struct {
+ para189
+ ans189
+}
+
+// para 是参数
+// one 代表第一个参数
+type para189 struct {
+ nums []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans189 struct {
+ one []int
+}
+
+func Test_Problem189(t *testing.T) {
+
+ qs := []question189{
+
+ {
+ para189{[]int{1, 2, 3, 4, 5, 6, 7}, 3},
+ ans189{[]int{5, 6, 7, 1, 2, 3, 4}},
+ },
+
+ {
+ para189{[]int{-1, -100, 3, 99}, 2},
+ ans189{[]int{3, 99, -1, -100}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 189------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans189, q.para189
+ fmt.Printf("【input】:%v ", p)
+ rotate(p.nums, p.k)
+ fmt.Printf("【output】:%v\n", p.nums)
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/0189.Rotate-Array/README.md b/leetcode/0189.Rotate-Array/README.md
new file mode 100644
index 00000000..a83b4ab6
--- /dev/null
+++ b/leetcode/0189.Rotate-Array/README.md
@@ -0,0 +1,75 @@
+# [189. Rotate Array](https://leetcode.com/problems/rotate-array/)
+
+## 题目
+
+Given an array, rotate the array to the right by *k* steps, where *k* is non-negative.
+
+**Follow up:**
+
+- Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
+- Could you do it in-place with O(1) extra space?
+
+**Example 1:**
+
+```
+Input: nums = [1,2,3,4,5,6,7], k = 3
+Output: [5,6,7,1,2,3,4]
+Explanation:
+rotate 1 steps to the right: [7,1,2,3,4,5,6]
+rotate 2 steps to the right: [6,7,1,2,3,4,5]
+rotate 3 steps to the right: [5,6,7,1,2,3,4]
+```
+
+**Example 2:**
+
+```
+Input: nums = [-1,-100,3,99], k = 2
+Output: [3,99,-1,-100]
+Explanation:
+rotate 1 steps to the right: [99,-1,-100,3]
+rotate 2 steps to the right: [3,99,-1,-100]
+```
+
+**Constraints:**
+
+- `1 <= nums.length <= 2 * 10^4`
+- `-2^31 <= nums[i] <= 2^31 - 1`
+- `0 <= k <= 10^5`
+
+## 题目大意
+
+给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
+
+## 解题思路
+
+- 解法二,使用一个额外的数组,先将原数组下标为 i 的元素移动到 `(i+k) mod n` 的位置,再将剩下的元素拷贝回来即可。
+- 解法一,由于题目要求不能使用额外的空间,所以本题最佳解法不是解法二。翻转最终态是,末尾 `k mod n` 个元素移动至了数组头部,剩下的元素右移 `k mod n` 个位置至最尾部。确定了最终态以后再变换就很容易。先将数组中所有元素从头到尾翻转一次,尾部的所有元素都到了头部,然后再将 `[0,(k mod n) − 1]` 区间内的元素翻转一次,最后再将 `[k mod n, n − 1]` 区间内的元素翻转一次,即可满足题目要求。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 时间复杂度 O(n),空间复杂度 O(1)
+func rotate(nums []int, k int) {
+ k %= len(nums)
+ reverse(nums)
+ reverse(nums[:k])
+ reverse(nums[k:])
+}
+
+func reverse(a []int) {
+ for i, n := 0, len(a); i < n/2; i++ {
+ a[i], a[n-1-i] = a[n-1-i], a[i]
+ }
+}
+
+// 解法二 时间复杂度 O(n),空间复杂度 O(n)
+func rotate1(nums []int, k int) {
+ newNums := make([]int, len(nums))
+ for i, v := range nums {
+ newNums[(i+k)%len(nums)] = v
+ }
+ copy(nums, newNums)
+}
+```
\ No newline at end of file
diff --git a/leetcode/0211.Add-and-Search-Word---Data-structure-design/211. Add and Search Word - Data structure design.go b/leetcode/0211.Design-Add-and-Search-Words-Data-Structure/211. Design Add and Search Words Data Structure.go
similarity index 100%
rename from leetcode/0211.Add-and-Search-Word---Data-structure-design/211. Add and Search Word - Data structure design.go
rename to leetcode/0211.Design-Add-and-Search-Words-Data-Structure/211. Design Add and Search Words Data Structure.go
diff --git a/leetcode/0211.Add-and-Search-Word---Data-structure-design/211. Add and Search Word - Data structure design_test.go b/leetcode/0211.Design-Add-and-Search-Words-Data-Structure/211. Design Add and Search Words Data Structure_test.go
similarity index 100%
rename from leetcode/0211.Add-and-Search-Word---Data-structure-design/211. Add and Search Word - Data structure design_test.go
rename to leetcode/0211.Design-Add-and-Search-Words-Data-Structure/211. Design Add and Search Words Data Structure_test.go
diff --git a/leetcode/0211.Add-and-Search-Word---Data-structure-design/README.md b/leetcode/0211.Design-Add-and-Search-Words-Data-Structure/README.md
similarity index 89%
rename from leetcode/0211.Add-and-Search-Word---Data-structure-design/README.md
rename to leetcode/0211.Design-Add-and-Search-Words-Data-Structure/README.md
index 57f8c335..cc646b06 100755
--- a/leetcode/0211.Add-and-Search-Word---Data-structure-design/README.md
+++ b/leetcode/0211.Design-Add-and-Search-Words-Data-Structure/README.md
@@ -1,4 +1,4 @@
-# [211. Add and Search Word - Data structure design](https://leetcode.com/problems/add-and-search-word-data-structure-design/)
+# [211. Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
## 题目
diff --git a/leetcode/0228.Summary-Ranges/228. Summary Ranges.go b/leetcode/0228.Summary-Ranges/228. Summary Ranges.go
new file mode 100644
index 00000000..b19c0e86
--- /dev/null
+++ b/leetcode/0228.Summary-Ranges/228. Summary Ranges.go
@@ -0,0 +1,19 @@
+package leetcode
+
+import (
+ "strconv"
+)
+
+func summaryRanges(nums []int) (ans []string) {
+ for i, n := 0, len(nums); i < n; {
+ left := i
+ for i++; i < n && nums[i-1]+1 == nums[i]; i++ {
+ }
+ s := strconv.Itoa(nums[left])
+ if left != i-1 {
+ s += "->" + strconv.Itoa(nums[i-1])
+ }
+ ans = append(ans, s)
+ }
+ return
+}
diff --git a/leetcode/0228.Summary-Ranges/228. Summary Ranges_test.go b/leetcode/0228.Summary-Ranges/228. Summary Ranges_test.go
new file mode 100644
index 00000000..dd18d007
--- /dev/null
+++ b/leetcode/0228.Summary-Ranges/228. Summary Ranges_test.go
@@ -0,0 +1,62 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question228 struct {
+ para228
+ ans228
+}
+
+// para 是参数
+// one 代表第一个参数
+type para228 struct {
+ nums []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans228 struct {
+ ans []string
+}
+
+func Test_Problem228(t *testing.T) {
+
+ qs := []question228{
+
+ {
+ para228{[]int{0, 1, 2, 4, 5, 7}},
+ ans228{[]string{"0->2", "4->5", "7"}},
+ },
+
+ {
+ para228{[]int{0, 2, 3, 4, 6, 8, 9}},
+ ans228{[]string{"0", "2->4", "6", "8->9"}},
+ },
+
+ {
+ para228{[]int{}},
+ ans228{[]string{}},
+ },
+
+ {
+ para228{[]int{-1}},
+ ans228{[]string{"-1"}},
+ },
+
+ {
+ para228{[]int{0}},
+ ans228{[]string{"0"}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 228------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans228, q.para228
+ fmt.Printf("【input】:%v 【output】:%v\n", p, summaryRanges(p.nums))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/0228.Summary-Ranges/README.md b/leetcode/0228.Summary-Ranges/README.md
new file mode 100644
index 00000000..85530b5a
--- /dev/null
+++ b/leetcode/0228.Summary-Ranges/README.md
@@ -0,0 +1,107 @@
+# [228. Summary Ranges](https://leetcode.com/problems/summary-ranges/)
+
+## 题目
+
+You are given a **sorted unique** integer array `nums`.
+
+Return *the **smallest sorted** list of ranges that **cover all the numbers in the array exactly***. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`.
+
+Each range `[a,b]` in the list should be output as:
+
+- `"a->b"` if `a != b`
+- `"a"` if `a == b`
+
+**Example 1:**
+
+```
+Input: nums = [0,1,2,4,5,7]
+Output: ["0->2","4->5","7"]
+Explanation: The ranges are:
+[0,2] --> "0->2"
+[4,5] --> "4->5"
+[7,7] --> "7"
+
+```
+
+**Example 2:**
+
+```
+Input: nums = [0,2,3,4,6,8,9]
+Output: ["0","2->4","6","8->9"]
+Explanation: The ranges are:
+[0,0] --> "0"
+[2,4] --> "2->4"
+[6,6] --> "6"
+[8,9] --> "8->9"
+
+```
+
+**Example 3:**
+
+```
+Input: nums = []
+Output: []
+
+```
+
+**Example 4:**
+
+```
+Input: nums = [-1]
+Output: ["-1"]
+
+```
+
+**Example 5:**
+
+```
+Input: nums = [0]
+Output: ["0"]
+
+```
+
+**Constraints:**
+
+- `0 <= nums.length <= 20`
+- `231 <= nums[i] <= 231 - 1`
+- All the values of `nums` are **unique**.
+- `nums` is sorted in ascending order.
+
+## 题目大意
+
+给定一个无重复元素的有序整数数组 nums 。
+
+返回 恰好覆盖数组中所有数字 的 最小有序 区间范围列表。也就是说,nums 的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个范围但不属于 nums 的数字 x 。
+
+列表中的每个区间范围 [a,b] 应该按如下格式输出:
+
+- "a->b" ,如果 a != b
+- "a" ,如果 a == b
+
+## 解题思路
+
+- 简单题。按照题意,用一个游标变量累加寻找连续的区间。一旦出现了中断,就按照题意格式输出。输出的规则有多种,带箭头的区间,单个元素区间,空区间。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "strconv"
+)
+
+func summaryRanges(nums []int) (ans []string) {
+ for i, n := 0, len(nums); i < n; {
+ left := i
+ for i++; i < n && nums[i-1]+1 == nums[i]; i++ {
+ }
+ s := strconv.Itoa(nums[left])
+ if left != i-1 {
+ s += "->" + strconv.Itoa(nums[i-1])
+ }
+ ans = append(ans, s)
+ }
+ return
+}
+```
\ No newline at end of file
diff --git a/leetcode/0387.First-Unique-Character-in-a-String/387. First Unique Character in a String.go b/leetcode/0387.First-Unique-Character-in-a-String/387. First Unique Character in a String.go
index 591c37f8..1ce1fe89 100644
--- a/leetcode/0387.First-Unique-Character-in-a-String/387. First Unique Character in a String.go
+++ b/leetcode/0387.First-Unique-Character-in-a-String/387. First Unique Character in a String.go
@@ -1,5 +1,6 @@
package leetcode
+// 解法一
func firstUniqChar(s string) int {
result := make([]int, 26)
for i := 0; i < len(s); i++ {
@@ -12,3 +13,34 @@ func firstUniqChar(s string) int {
}
return -1
}
+
+// 解法二
+// 执行用时: 8 ms
+// 内存消耗: 5.2 MB
+func firstUniqChar1(s string) int {
+ charMap := make([][2]int, 26)
+ for i := 0; i < 26; i++ {
+ charMap[i][0] = -1
+ charMap[i][1] = -1
+ }
+ for i := 0; i < len(s); i++ {
+ if charMap[s[i]-'a'][0] == -1 {
+ charMap[s[i]-'a'][0] = i
+ } else { //已经出现过
+ charMap[s[i]-'a'][1] = i
+ }
+ }
+ res := len(s)
+ for i := 0; i < 26; i++ {
+ //只出现了一次
+ if charMap[i][0] >= 0 && charMap[i][1] == -1 {
+ if charMap[i][0] < res {
+ res = charMap[i][0]
+ }
+ }
+ }
+ if res == len(s) {
+ return -1
+ }
+ return res
+}
diff --git a/leetcode/0460.LFU-Cache/460. LFU Cache.go b/leetcode/0460.LFU-Cache/460. LFU Cache.go
new file mode 100644
index 00000000..e2a29f53
--- /dev/null
+++ b/leetcode/0460.LFU-Cache/460. LFU Cache.go
@@ -0,0 +1,74 @@
+package leetcode
+
+import "container/list"
+
+type LFUCache struct {
+ nodes map[int]*list.Element
+ lists map[int]*list.List
+ capacity int
+ min int
+}
+
+type node struct {
+ key int
+ value int
+ frequency int
+}
+
+func Constructor(capacity int) LFUCache {
+ return LFUCache{nodes: make(map[int]*list.Element),
+ lists: make(map[int]*list.List),
+ capacity: capacity,
+ min: 0,
+ }
+}
+
+func (this *LFUCache) Get(key int) int {
+ value, ok := this.nodes[key]
+ if !ok {
+ return -1
+ }
+ currentNode := value.Value.(*node)
+ this.lists[currentNode.frequency].Remove(value)
+ currentNode.frequency++
+ if _, ok := this.lists[currentNode.frequency]; !ok {
+ this.lists[currentNode.frequency] = list.New()
+ }
+ newList := this.lists[currentNode.frequency]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+ if currentNode.frequency-1 == this.min && this.lists[currentNode.frequency-1].Len() == 0 {
+ this.min++
+ }
+ return currentNode.value
+}
+
+func (this *LFUCache) Put(key int, value int) {
+ if this.capacity == 0 {
+ return
+ }
+ if currentValue, ok := this.nodes[key]; ok {
+ currentNode := currentValue.Value.(*node)
+ currentNode.value = value
+ this.Get(key)
+ return
+ }
+ if this.capacity == len(this.nodes) {
+ currentList := this.lists[this.min]
+ frontNode := currentList.Front()
+ delete(this.nodes, frontNode.Value.(*node).key)
+ currentList.Remove(frontNode)
+ }
+ this.min = 1
+ currentNode := &node{
+ key: key,
+ value: value,
+ frequency: 1,
+ }
+ if _, ok := this.lists[1]; !ok {
+ this.lists[1] = list.New()
+ }
+ newList := this.lists[1]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+}
diff --git a/leetcode/0460.LFU-Cache/460. LFU Cache_test.go b/leetcode/0460.LFU-Cache/460. LFU Cache_test.go
new file mode 100644
index 00000000..12205d94
--- /dev/null
+++ b/leetcode/0460.LFU-Cache/460. LFU Cache_test.go
@@ -0,0 +1,64 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+func Test_Problem460(t *testing.T) {
+ obj := Constructor(5)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(1, 1)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(2, 2)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(3, 3)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(4, 4)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(5, 5)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+
+ param1 := obj.Get(4)
+ fmt.Printf("param_1 = %v obj.list = %v obj.map = %v obj.min = %v\n", param1, MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ param1 = obj.Get(4)
+ fmt.Printf("param_1 = %v obj.list = %v obj.map = %v obj.min = %v\n", param1, MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ param1 = obj.Get(4)
+ fmt.Printf("param_1 = %v obj.list = %v obj.map = %v obj.min = %v\n", param1, MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ param1 = obj.Get(5)
+ fmt.Printf("param_1 = %v obj.list = %v obj.map = %v obj.min = %v\n", param1, MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ param1 = obj.Get(5)
+ fmt.Printf("param_1 = %v obj.list = %v obj.map = %v obj.min = %v\n", param1, MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ param1 = obj.Get(5)
+ fmt.Printf("param_1 = %v obj.list = %v obj.map = %v obj.min = %v\n", param1, MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(6, 6)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(7, 7)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+ obj.Put(8, 8)
+ fmt.Printf("obj.list = %v obj.map = %v obj.min = %v\n", MLists2Ints(&obj), MList2Ints(&obj), obj.min)
+}
+
+func MList2Ints(lfu *LFUCache) map[int][][]int {
+ res := map[int][][]int{}
+ for k, v := range lfu.nodes {
+ node := v.Value.(*node)
+ arr := [][]int{}
+ tmp := []int{node.key, node.value, node.frequency}
+ arr = append(arr, tmp)
+ res[k] = arr
+ }
+ return res
+}
+
+func MLists2Ints(lfu *LFUCache) map[int][]int {
+ res := map[int][]int{}
+ for k, v := range lfu.lists {
+ tmp := []int{}
+ for head := v.Front(); head != nil; head = head.Next() {
+ tmp = append(tmp, head.Value.(*node).value)
+ }
+ res[k] = tmp
+ }
+ return res
+}
diff --git a/leetcode/0460.LFU-Cache/README.md b/leetcode/0460.LFU-Cache/README.md
new file mode 100644
index 00000000..f4a07c44
--- /dev/null
+++ b/leetcode/0460.LFU-Cache/README.md
@@ -0,0 +1,142 @@
+# [460. LFU Cache](https://leetcode.com/problems/lfu-cache/)
+
+
+## 题目
+
+Design and implement a data structure for [Least Frequently Used (LFU)](https://en.wikipedia.org/wiki/Least_frequently_used) cache.
+
+Implement the `LFUCache` class:
+
+- `LFUCache(int capacity)` Initializes the object with the `capacity` of the data structure.
+- `int get(int key)` Gets the value of the `key` if the `key` exists in the cache. Otherwise, returns `1`.
+- `void put(int key, int value)` Sets or inserts the value if the `key` is not already present. When the cache reaches its `capacity`, it should invalidate the least frequently used item before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), **the least recently** used `key` would be evicted.
+
+**Notice that** the number of times an item is used is the number of calls to the `get` and `put` functions for that item since it was inserted. This number is set to zero when the item is removed.
+
+**Example 1:**
+
+```
+Input
+["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, 3, null, -1, 3, 4]
+
+Explanation
+LFUCache lfu = new LFUCache(2);
+lfu.put(1, 1);
+lfu.put(2, 2);
+lfu.get(1); // return 1
+lfu.put(3, 3); // evicts key 2
+lfu.get(2); // return -1 (not found)
+lfu.get(3); // return 3
+lfu.put(4, 4); // evicts key 1.
+lfu.get(1); // return -1 (not found)
+lfu.get(3); // return 3
+lfu.get(4); // return 4
+
+```
+
+**Constraints:**
+
+- `0 <= capacity, key, value <= 104`
+- At most `10^5` calls will be made to `get` and `put`.
+
+**Follow up:** Could you do both operations in `O(1)` time complexity?
+
+## 题目大意
+
+请你为 最不经常使用(LFU)缓存算法设计并实现数据结构。
+
+实现 LFUCache 类:
+
+- LFUCache(int capacity) - 用数据结构的容量 capacity 初始化对象
+- int get(int key) - 如果键存在于缓存中,则获取键的值,否则返回 -1。
+- void put(int key, int value) - 如果键已存在,则变更其值;如果键不存在,请插入键值对。当缓存达到其容量时,则应该在插入新项之前,使最不经常使用的项无效。在此问题中,当存在平局(即两个或更多个键具有相同使用频率)时,应该去除 最久未使用 的键。
+
+注意「项的使用次数」就是自插入该项以来对其调用 get 和 put 函数的次数之和。使用次数会在对应项被移除后置为 0 。
+
+进阶:你是否可以在 O(1) 时间复杂度内执行两项操作?
+
+## 解题思路
+
+- 这一题是 LFU 经典面试题,详细解释见[第三章 LFUCache 模板](https://books.halfrost.com/leetcode/ChapterThree/LFUCache/)。
+
+## 代码
+
+```go
+package leetcode
+
+import "container/list"
+
+type LFUCache struct {
+ nodes map[int]*list.Element
+ lists map[int]*list.List
+ capacity int
+ min int
+}
+
+type node struct {
+ key int
+ value int
+ frequency int
+}
+
+func Constructor(capacity int) LFUCache {
+ return LFUCache{nodes: make(map[int]*list.Element),
+ lists: make(map[int]*list.List),
+ capacity: capacity,
+ min: 0,
+ }
+}
+
+func (this *LFUCache) Get(key int) int {
+ value, ok := this.nodes[key]
+ if !ok {
+ return -1
+ }
+ currentNode := value.Value.(*node)
+ this.lists[currentNode.frequency].Remove(value)
+ currentNode.frequency++
+ if _, ok := this.lists[currentNode.frequency]; !ok {
+ this.lists[currentNode.frequency] = list.New()
+ }
+ newList := this.lists[currentNode.frequency]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+ if currentNode.frequency-1 == this.min && this.lists[currentNode.frequency-1].Len() == 0 {
+ this.min++
+ }
+ return currentNode.value
+}
+
+func (this *LFUCache) Put(key int, value int) {
+ if this.capacity == 0 {
+ return
+ }
+ if currentValue, ok := this.nodes[key]; ok {
+ currentNode := currentValue.Value.(*node)
+ currentNode.value = value
+ this.Get(key)
+ return
+ }
+ if this.capacity == len(this.nodes) {
+ currentList := this.lists[this.min]
+ frontNode := currentList.Front()
+ delete(this.nodes, frontNode.Value.(*node).key)
+ currentList.Remove(frontNode)
+ }
+ this.min = 1
+ currentNode := &node{
+ key: key,
+ value: value,
+ frequency: 1,
+ }
+ if _, ok := this.lists[1]; !ok {
+ this.lists[1] = list.New()
+ }
+ newList := this.lists[1]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+}
+```
\ No newline at end of file
diff --git a/leetcode/0547.Friend-Circles/547. Friend Circles.go b/leetcode/0547.Number-of-Provinces/547. Number of Provinces.go
similarity index 100%
rename from leetcode/0547.Friend-Circles/547. Friend Circles.go
rename to leetcode/0547.Number-of-Provinces/547. Number of Provinces.go
diff --git a/leetcode/0547.Friend-Circles/547. Friend Circles_test.go b/leetcode/0547.Number-of-Provinces/547. Number of Provinces_test.go
similarity index 100%
rename from leetcode/0547.Friend-Circles/547. Friend Circles_test.go
rename to leetcode/0547.Number-of-Provinces/547. Number of Provinces_test.go
diff --git a/leetcode/0547.Friend-Circles/README.md b/leetcode/0547.Number-of-Provinces/README.md
similarity index 97%
rename from leetcode/0547.Friend-Circles/README.md
rename to leetcode/0547.Number-of-Provinces/README.md
index 6cfe79b1..0dafa9ba 100755
--- a/leetcode/0547.Friend-Circles/README.md
+++ b/leetcode/0547.Number-of-Provinces/README.md
@@ -1,4 +1,4 @@
-# [547. Friend Circles](https://leetcode.com/problems/friend-circles/)
+# [547. Number of Provinces](https://leetcode.com/problems/number-of-provinces/)
## 题目
diff --git a/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go b/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go
new file mode 100644
index 00000000..0b598096
--- /dev/null
+++ b/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go
@@ -0,0 +1,18 @@
+package leetcode
+
+func canPlaceFlowers(flowerbed []int, n int) bool {
+ lenth := len(flowerbed)
+ for i := 0; i < lenth && n > 0; i += 2 {
+ if flowerbed[i] == 0 {
+ if i+1 == lenth || flowerbed[i+1] == 0 {
+ n--
+ } else {
+ i++
+ }
+ }
+ }
+ if n == 0 {
+ return true
+ }
+ return false
+}
diff --git a/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers_test.go b/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers_test.go
new file mode 100644
index 00000000..0b7ce7f2
--- /dev/null
+++ b/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers_test.go
@@ -0,0 +1,68 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question605 struct {
+ para605
+ ans605
+}
+
+// para 是参数
+// one 代表第一个参数
+type para605 struct {
+ flowerbed []int
+ n int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans605 struct {
+ one bool
+}
+
+func Test_Problem605(t *testing.T) {
+
+ qs := []question605{
+
+ {
+ para605{[]int{1, 0, 0, 0, 1}, 1},
+ ans605{true},
+ },
+
+ {
+ para605{[]int{1, 0, 0, 0, 1}, 2},
+ ans605{false},
+ },
+
+ {
+ para605{[]int{1, 0, 0, 0, 0, 1}, 2},
+ ans605{false},
+ },
+
+ {
+ para605{[]int{0, 0, 1, 0}, 1},
+ ans605{true},
+ },
+
+ {
+ para605{[]int{0, 0, 1, 0, 0}, 1},
+ ans605{true},
+ },
+
+ {
+ para605{[]int{1, 0, 0, 1, 0}, 2},
+ ans605{false},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 605------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans605, q.para605
+ fmt.Printf("【input】:%v 【output】:%v\n", p, canPlaceFlowers(p.flowerbed, p.n))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/0605.Can-Place-Flowers/README.md b/leetcode/0605.Can-Place-Flowers/README.md
new file mode 100644
index 00000000..746817ad
--- /dev/null
+++ b/leetcode/0605.Can-Place-Flowers/README.md
@@ -0,0 +1,60 @@
+# [605. Can Place Flowers](https://leetcode.com/problems/can-place-flowers/)
+
+## 题目
+
+You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in **adjacent** plots.
+
+Given an integer array `flowerbed` containing `0`'s and `1`'s, where `0` means empty and `1` means not empty, and an integer `n`, return *if* `n` new flowers can be planted in the `flowerbed` without violating the no-adjacent-flowers rule.
+
+**Example 1:**
+
+```
+Input: flowerbed = [1,0,0,0,1], n = 1
+Output: true
+```
+
+**Example 2:**
+
+```
+Input: flowerbed = [1,0,0,0,1], n = 2
+Output: false
+```
+
+**Constraints:**
+
+- `1 <= flowerbed.length <= 2 * 104`
+- `flowerbed[i]` is `0` or `1`.
+- There are no two adjacent flowers in `flowerbed`.
+- `0 <= n <= flowerbed.length`
+
+## 题目大意
+
+假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有。可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去。给定一个花坛(表示为一个数组包含0和1,其中0表示没种植花,1表示种植了花),和一个数 n 。能否在不打破种植规则的情况下种入 n 朵花?能则返回True,不能则返回False。
+
+## 解题思路
+
+- 这一题最容易想到的解法是步长为 2 遍历数组,依次计数 0 的个数。有 2 种特殊情况需要单独判断,第一种情况是首尾连续多个 0,例如,00001 和 10000,第二种情况是 2 个 1 中间存在的 0 不足以种花,例如,1001 和 100001,1001 不能种任何花,100001 只能种一种花。单独判断出这 2 种情况,这一题就可以 AC 了。
+- 换个思路,找到可以种花的基本单元是 00,那么上面那 2 种特殊情况都可以统一成一种情况。判断是否当前存在 00 的组合,如果存在 00 的组合,都可以种花。末尾的情况需要单独判断,如果末尾为 0,也可以种花。这个时候不需要再找 00 组合,因为会越界。代码实现如下,思路很简洁明了。
+
+## 代码
+
+```go
+package leetcode
+
+func canPlaceFlowers(flowerbed []int, n int) bool {
+ lenth := len(flowerbed)
+ for i := 0; i < lenth && n > 0; i += 2 {
+ if flowerbed[i] == 0 {
+ if i+1 == lenth || flowerbed[i+1] == 0 {
+ n--
+ } else {
+ i++
+ }
+ }
+ }
+ if n == 0 {
+ return true
+ }
+ return false
+}
+```
\ No newline at end of file
diff --git a/leetcode/0633.Sum-of-Square-Numbers/README.md b/leetcode/0633.Sum-of-Square-Numbers/README.md
index 7bad9940..de0a6e54 100755
--- a/leetcode/0633.Sum-of-Square-Numbers/README.md
+++ b/leetcode/0633.Sum-of-Square-Numbers/README.md
@@ -25,4 +25,4 @@ Given a non-negative integer `c`, your task is to decide whether there're two i
## 解题思路
- 给出一个数,要求判断这个数能否由由 2 个完全平方数组成。能则输出 true,不能则输出 false。
-- 可以用二分搜索来解答这道题。判断题意,依次计算 `low * low + high * high` 和 c 是否相等。从 [1, sqrt(n)] 区间内进行二分,若能找到则返回 true,找不到就返回 false 。
+- 可以用二分搜索来解答这道题。判断题意,依次计算 `low * low + high * high` 和 c 是否相等。从 [0, sqrt(n)] 区间内进行二分,若能找到则返回 true,找不到就返回 false 。
diff --git a/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite.go b/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite.go
new file mode 100644
index 00000000..e0b6089a
--- /dev/null
+++ b/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite.go
@@ -0,0 +1,35 @@
+package leetcode
+
+// DFS 染色,1 是红色,0 是绿色,-1 是未染色
+func isBipartite(graph [][]int) bool {
+ colors := make([]int, len(graph))
+ for i := range colors {
+ colors[i] = -1
+ }
+ for i := range graph {
+ if !dfs(i, graph, colors, -1) {
+ return false
+ }
+ }
+ return true
+}
+
+func dfs(n int, graph [][]int, colors []int, parentCol int) bool {
+ if colors[n] == -1 {
+ if parentCol == 1 {
+ colors[n] = 0
+ } else {
+ colors[n] = 1
+ }
+ } else if colors[n] == parentCol {
+ return false
+ } else if colors[n] != parentCol {
+ return true
+ }
+ for _, c := range graph[n] {
+ if !dfs(c, graph, colors, colors[n]) {
+ return false
+ }
+ }
+ return true
+}
diff --git a/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite_test.go b/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite_test.go
new file mode 100644
index 00000000..862eaf59
--- /dev/null
+++ b/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question785 struct {
+ para785
+ ans785
+}
+
+// para 是参数
+// one 代表第一个参数
+type para785 struct {
+ graph [][]int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans785 struct {
+ one bool
+}
+
+func Test_Problem785(t *testing.T) {
+
+ qs := []question785{
+
+ {
+ para785{[][]int{{1, 3}, {0, 2}, {1, 3}, {0, 2}}},
+ ans785{true},
+ },
+
+ {
+ para785{[][]int{{1, 2, 3}, {0, 2}, {0, 1, 3}, {0, 2}}},
+ ans785{false},
+ },
+
+ {
+ para785{[][]int{{1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}}},
+ ans785{false},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 785------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans785, q.para785
+ fmt.Printf("【input】:%v 【output】:%v\n", p, isBipartite(p.graph))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/0785.Is-Graph-Bipartite/README.md b/leetcode/0785.Is-Graph-Bipartite/README.md
new file mode 100644
index 00000000..a5eb6679
--- /dev/null
+++ b/leetcode/0785.Is-Graph-Bipartite/README.md
@@ -0,0 +1,98 @@
+# [785. Is Graph Bipartite?](https://leetcode.com/problems/is-graph-bipartite/)
+
+
+## 题目
+
+Given an undirected `graph`, return `true` if and only if it is bipartite.
+
+Recall that a graph is *bipartite* if we can split it's set of nodes into two independent subsets A and B such that every edge in the graph has one node in A and another node in B.
+
+The graph is given in the following form: `graph[i]` is a list of indexes `j` for which the edge between nodes `i` and `j` exists. Each node is an integer between `0` and `graph.length - 1`. There are no self edges or parallel edges: `graph[i]` does not contain `i`, and it doesn't contain any element twice.
+
+
+ Example 1:Input: [[1,3], [0,2], [1,3], [0,2]]
+ Output: true
+ Explanation:
+ The graph looks like this:
+ 0----1
+ | |
+ | |
+ 3----2
+ We can divide the vertices into two groups: {0, 2} and {1, 3}.
+
+
+ Example 2:Input: [[1,2,3], [0,2], [0,1,3], [0,2]]
+ Output: false
+ Explanation:
+ The graph looks like this:
+ 0----1
+ | \ |
+ | \ |
+ 3----2
+ We cannot find a way to divide the set of nodes into two independent subsets.
+
+
+**Note:**
+
+- `graph` will have length in range `[1, 100]`.
+- `graph[i]` will contain integers in range `[0, graph.length - 1]`.
+- `graph[i]` will not contain `i` or duplicate values.
+- The graph is undirected: if any element `j` is in `graph[i]`, then `i` will be in `graph[j]`.
+
+## 题目大意
+
+给定一个无向图 graph,当这个图为二分图时返回 true。
+
+graph 将会以邻接表方式给出,graph[i] 表示图中与节点i相连的所有节点。每个节点都是一个在 0 到 graph.length-1 之间的整数。这图中没有自环和平行边: graph[i] 中不存在 i,并且 graph[i] 中没有重复的值。
+
+注意:
+
+- graph 的长度范围为 [1, 100]。
+- graph[i] 中的元素的范围为 [0, graph.length - 1]。
+- graph[i] 不会包含 i 或者有重复的值。
+- 图是无向的: 如果 j 在 graph[i] 里边, 那么 i 也会在 graph[j] 里边。
+
+## 解题思路
+
+- 判断一个无向图是否是二分图。二分图的定义:如果我们能将一个图的节点集合分割成两个独立的子集 A 和 B,并使图中的每一条边的两个节点一个来自 A 集合,一个来自 B 集合,我们就将这个图称为二分图。
+- 这一题可以用 BFS、DFS、并查集来解答。这里是 DFS 实现。任选一个节点开始,把它染成红色,然后对整个图 DFS 遍历,把与它相连的节点并且未被染色的,都染成绿色。颜色不同的节点代表不同的集合。这时候还可能遇到第 2 种情况,与它相连的节点已经有颜色了,并且这个颜色和前一个节点的颜色相同,这就说明了该无向图不是二分图。可以直接 return false。如此遍历到所有节点都染色了,如果能染色成功,说明该无向图是二分图,返回 true。
+
+## 代码
+
+```go
+package leetcode
+
+// DFS 染色,1 是红色,0 是绿色,-1 是未染色
+func isBipartite(graph [][]int) bool {
+ colors := make([]int, len(graph))
+ for i := range colors {
+ colors[i] = -1
+ }
+ for i := range graph {
+ if !dfs(i, graph, colors, -1) {
+ return false
+ }
+ }
+ return true
+}
+
+func dfs(n int, graph [][]int, colors []int, parentCol int) bool {
+ if colors[n] == -1 {
+ if parentCol == 1 {
+ colors[n] = 0
+ } else {
+ colors[n] = 1
+ }
+ } else if colors[n] == parentCol {
+ return false
+ } else if colors[n] != parentCol {
+ return true
+ }
+ for _, c := range graph[n] {
+ if !dfs(c, graph, colors, colors[n]) {
+ return false
+ }
+ }
+ return true
+}
+```
\ No newline at end of file
diff --git a/leetcode/0828.COPYRIGHT-PROBLEM-XXX/README.md b/leetcode/0828.COPYRIGHT-PROBLEM-XXX/README.md
deleted file mode 100644
index b26bae01..00000000
--- a/leetcode/0828.COPYRIGHT-PROBLEM-XXX/README.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# [828. Unique Letter String](https://leetcode.com/problems/unique-letter-string/)
-
-## 题目
-
-THIS PROBLEM COPYRIGHT BELONGS TO CODILITY.COM
-
-**Example 1:**
-
-
-
-**Example 2:**
-
-
-
-## 题目大意
-
-如果一个字符在字符串 S 中有且仅有出现一次,那么我们称其为独特字符。例如,在字符串 S = "LETTER" 中,"L" 和 "R" 可以被称为独特字符。我们再定义 UNIQ(S) 作为字符串 S 中独特字符的个数。那么,在 S = "LETTER" 中, UNIQ("LETTER") = 2。
-
-对于给定字符串 S,计算其所有非空子串的独特字符的个数(即 UNIQ(substring))之和。如果在 S 的不同位置上出现两个甚至多个相同的子串,那么我们认为这些子串是不同的。考虑到答案可能会非常大,规定返回格式为:结果 mod 10 ^ 9 + 7。
-
-
-## 解题思路
-
-- 这一题可以先用暴力解法尝试解题,不过提交以后会发现判题结果是超时。出错的一组数据是一个有 10000 个字符的字符串。暴力解法中间由于遍历了太多的子区间,导致了超时。
-- 这道题换一个角度思考问题。当子字符串中字符 X 出现了 2 次以上,那么它就对最终结果没有任何影响,所以只有当某个字符只出现一次的时候才会影响最终结果。再者,一个子字符串中不重复的字符的总个数,也就是这个子字符串 UNIQ 值。例如,“ABC”,这个子字符串的 UNIQ 值是 3,可以这样计算,它属于 A 的独特的字符串,也属于 B 的独特的字符串,也属于 C 的独特的字符串,那么计算这个子字符串的问题可以分解成计算 A 有多少个独特的子字符串,B 有多少个独特的子字符串,C 有多少个独特的子字符串的问题。在计算 A 有多少个子字符串的问题的时候,里面肯定会包含 "ABC" 这个子字符串的。所以原问题就转换成了分别计算给出的字符串中每个字符出现在独特字符串中的总数之和。
-- 假设原字符串是 BAABBABBBAAABA,这个字符串中出现了很多 A 和很多 B,假设我们当前计算到了第 3 个 A 的位置了(index = 5),即标红色的那个 A。如何计算这个 A 在哪些子字符串中是独特的呢?由于子字符串题目中要求必须是连续的区间,所以这个问题很简单。找到这个 A 前一个 A 的下标位置(index = 2),再找到这个 A 后一个 A 的下标位置(index = 9),即 BAABBABBBAAABA,第一个 A 和当前计算的 A 中间区间有 2 个字符,第三个 A 和当前计算的 A 中间有 3 个字符。那么当前计算的 A 出现在 `(2 + 1) * (3 + 1) = 12` 个子字符串中是独特的,这 12 个字符串是:`A`,`BA`,`BBA`,`AB`,`ABB`,`ABBB`,`BAB`,`BABB`,`BABBB`,`BBAB`,`BBABB`,`BBABBB`。计算方法,假设当前待计算的字符的下标是 i ,找到当前字符前一次出现的下标位置 left,再找到当前字符后一次出现的下标位置 right,那么左边区间 (left,i) 的**开区间**内包含的字符数是 i - left - 1,右边区间 (i,right) 的**开区间**内包含的字符数是 right - i - 1。左右两边都还需要考虑空字符串的情况,即左右两边都可以不取任何字符,那么对应的就是只有中间这个待计算的字符 `A`。所以左右两边都还需要再加上空串的情况,左边 i - left - 1 + 1 = i - left,右边 right - i - 1 + 1 = right - i。左右两边的情况进行排列组合,即 (i - left) * (right - i)。针对字符串的每个字符都计算这样的值,最后累积的总和就是题目中要求的总 UNIQ 值。
-
-
diff --git a/leetcode/0828.COPYRIGHT-PROBLEM-XXX/828. Unique Letter String.go b/leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String.go
similarity index 100%
rename from leetcode/0828.COPYRIGHT-PROBLEM-XXX/828. Unique Letter String.go
rename to leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String.go
diff --git a/leetcode/0828.COPYRIGHT-PROBLEM-XXX/828. Unique Letter String_test.go b/leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String_test.go
similarity index 100%
rename from leetcode/0828.COPYRIGHT-PROBLEM-XXX/828. Unique Letter String_test.go
rename to leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String_test.go
diff --git a/website/content/ChapterFour/0828.COPYRIGHT-PROBLEM-XXX.md b/leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/README.md
similarity index 66%
rename from website/content/ChapterFour/0828.COPYRIGHT-PROBLEM-XXX.md
rename to leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/README.md
index 49ebc4c0..fd29a4af 100644
--- a/website/content/ChapterFour/0828.COPYRIGHT-PROBLEM-XXX.md
+++ b/leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/README.md
@@ -1,16 +1,44 @@
-# [828. Unique Letter String](https://leetcode.com/problems/unique-letter-string/)
+# [828. Count Unique Characters of All Substrings of a Given String](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/)
+
## 题目
-THIS PROBLEM COPYRIGHT BELONGS TO CODILITY.COM
+Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`, for example if `s = "LEETCODE"` then `"L"`, `"T"`,`"C"`,`"O"`,`"D"` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`.On this problem given a string `s` we need to return the sum of `countUniqueChars(t)` where `t` is a substring of `s`. Notice that some substrings can be repeated so on this case you have to count the repeated ones too.
-**Example 1**:
+Since the answer can be very large, return the answer modulo `10 ^ 9 + 7`.
+**Example 1:**
+```
+Input: s = "ABC"
+Output: 10
+Explanation: All possible substrings are: "A","B","C","AB","BC" and "ABC".
+Evey substring is composed with only unique letters.
+Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10
-**Example 2**:
+```
+**Example 2:**
+```
+Input: s = "ABA"
+Output: 8
+Explanation: The same as example 1, except countUniqueChars("ABA") = 1.
+
+```
+
+**Example 3:**
+
+```
+Input: s = "LEETCODE"
+Output: 92
+
+```
+
+**Constraints:**
+
+- `0 <= s.length <= 10^4`
+- `s` contain upper-case English letters only.
## 题目大意
@@ -18,20 +46,15 @@ THIS PROBLEM COPYRIGHT BELONGS TO CODILITY.COM
对于给定字符串 S,计算其所有非空子串的独特字符的个数(即 UNIQ(substring))之和。如果在 S 的不同位置上出现两个甚至多个相同的子串,那么我们认为这些子串是不同的。考虑到答案可能会非常大,规定返回格式为:结果 mod 10 ^ 9 + 7。
-
## 解题思路
- 这一题可以先用暴力解法尝试解题,不过提交以后会发现判题结果是超时。出错的一组数据是一个有 10000 个字符的字符串。暴力解法中间由于遍历了太多的子区间,导致了超时。
- 这道题换一个角度思考问题。当子字符串中字符 X 出现了 2 次以上,那么它就对最终结果没有任何影响,所以只有当某个字符只出现一次的时候才会影响最终结果。再者,一个子字符串中不重复的字符的总个数,也就是这个子字符串 UNIQ 值。例如,“ABC”,这个子字符串的 UNIQ 值是 3,可以这样计算,它属于 A 的独特的字符串,也属于 B 的独特的字符串,也属于 C 的独特的字符串,那么计算这个子字符串的问题可以分解成计算 A 有多少个独特的子字符串,B 有多少个独特的子字符串,C 有多少个独特的子字符串的问题。在计算 A 有多少个子字符串的问题的时候,里面肯定会包含 "ABC" 这个子字符串的。所以原问题就转换成了分别计算给出的字符串中每个字符出现在独特字符串中的总数之和。
-- 假设原字符串是 BAABBABBBAAABA,这个字符串中出现了很多 A 和很多 B,假设我们当前计算到了第 3 个 A 的位置了(index = 5),即标红色的那个 A。如何计算这个 A 在哪些子字符串中是独特的呢?由于子字符串题目中要求必须是连续的区间,所以这个问题很简单。找到这个 A 前一个 A 的下标位置(index = 2),再找到这个 A 后一个 A 的下标位置(index = 9),即 BAABBABBBAAABA,第一个 A 和当前计算的 A 中间区间有 2 个字符,第三个 A 和当前计算的 A 中间有 3 个字符。那么当前计算的 A 出现在 `(2 + 1) * (3 + 1) = 12` 个子字符串中是独特的,这 12 个字符串是:`A`,`BA`,`BBA`,`AB`,`ABB`,`ABBB`,`BAB`,`BABB`,`BABBB`,`BBAB`,`BBABB`,`BBABBB`。计算方法,假设当前待计算的字符的下标是 i ,找到当前字符前一次出现的下标位置 left,再找到当前字符后一次出现的下标位置 right,那么左边区间 (left,i) 的**开区间**内包含的字符数是 i - left - 1,右边区间 (i,right) 的**开区间**内包含的字符数是 right - i - 1。左右两边都还需要考虑空字符串的情况,即左右两边都可以不取任何字符,那么对应的就是只有中间这个待计算的字符 `A`。所以左右两边都还需要再加上空串的情况,左边 i - left - 1 + 1 = i - left,右边 right - i - 1 + 1 = right - i。左右两边的情况进行排列组合,即 (i - left) * (right - i)。针对字符串的每个字符都计算这样的值,最后累积的总和就是题目中要求的总 UNIQ 值。
-
-
-
+- 假设原字符串是 BAABBABBBAAABA,这个字符串中出现了很多 A 和很多 B,假设我们当前计算到了第 3 个 A 的位置了(index = 5),即标红色的那个 A。如何计算这个 A 在哪些子字符串中是独特的呢?由于子字符串题目中要求必须是连续的区间,所以这个问题很简单。找到这个 A 前一个 A 的下标位置(index = 2),再找到这个 A 后一个 A 的下标位置(index = 9),即 BAABBABBBAAABA,第一个 A 和当前计算的 A 中间区间有 2 个字符,第三个 A 和当前计算的 A 中间有 3 个字符。那么当前计算的 A 出现在 `(2 + 1) * (3 + 1) = 12` 个子字符串中是独特的,这 12 个字符串是:`A`,`BA`,`BBA`,`AB`,`ABB`,`ABBB`,`BAB`,`BABB`,`BABBB`,`BBAB`,`BBABB`,`BBABBB`。计算方法,假设当前待计算的字符的下标是 i ,找到当前字符前一次出现的下标位置 left,再找到当前字符后一次出现的下标位置 right,那么左边区间 (left,i) 的***开区间****内包含的字符数是 i - left - 1,右边区间 (i,right) 的***开区间****内包含的字符数是 right - i - 1。左右两边都还需要考虑空字符串的情况,即左右两边都可以不取任何字符,那么对应的就是只有中间这个待计算的字符 `A`。所以左右两边都还需要再加上空串的情况,左边 i - left - 1 + 1 = i - left,右边 right - i - 1 + 1 = right - i。左右两边的情况进行排列组合,即 (i - left) * (right - i)。针对字符串的每个字符都计算这样的值,最后累积的总和就是题目中要求的总 UNIQ 值。
## 代码
```go
-
package leetcode
func uniqueLetterString(S string) int {
@@ -75,6 +98,4 @@ func uniqueLetterString1(S string) int {
}
return res % mod
}
-
-
```
\ No newline at end of file
diff --git a/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups.go b/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups.go
new file mode 100644
index 00000000..8b61b338
--- /dev/null
+++ b/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups.go
@@ -0,0 +1,15 @@
+package leetcode
+
+func largeGroupPositions(S string) [][]int {
+ res, end := [][]int{}, 0
+ for end < len(S) {
+ start, str := end, S[end]
+ for end < len(S) && S[end] == str {
+ end++
+ }
+ if end-start >= 3 {
+ res = append(res, []int{start, end - 1})
+ }
+ }
+ return res
+}
diff --git a/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups_test.go b/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups_test.go
new file mode 100644
index 00000000..ed74b05a
--- /dev/null
+++ b/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups_test.go
@@ -0,0 +1,57 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question830 struct {
+ para830
+ ans830
+}
+
+// para 是参数
+// one 代表第一个参数
+type para830 struct {
+ S string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans830 struct {
+ one [][]int
+}
+
+func Test_Problem830(t *testing.T) {
+
+ qs := []question830{
+
+ {
+ para830{"abbxxxxzzy"},
+ ans830{[][]int{{3, 6}}},
+ },
+
+ {
+ para830{"abc"},
+ ans830{[][]int{{}}},
+ },
+
+ {
+ para830{"abcdddeeeeaabbbcd"},
+ ans830{[][]int{{3, 5}, {6, 9}, {12, 14}}},
+ },
+
+ {
+ para830{"aba"},
+ ans830{[][]int{{}}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 830------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans830, q.para830
+ fmt.Printf("【input】:%v 【output】:%v\n", p, largeGroupPositions(p.S))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/0830.Positions-of-Large-Groups/README.md b/leetcode/0830.Positions-of-Large-Groups/README.md
new file mode 100644
index 00000000..5323f2e0
--- /dev/null
+++ b/leetcode/0830.Positions-of-Large-Groups/README.md
@@ -0,0 +1,80 @@
+# [830. Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups/)
+
+
+## 题目
+
+In a string `s` of lowercase letters, these letters form consecutive groups of the same character.
+
+For example, a string like `s = "abbxxxxzyy"` has the groups `"a"`, `"bb"`, `"xxxx"`, `"z"`, and `"yy"`.
+
+A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indices (inclusive) of the group. In the above example, `"xxxx"` has the interval `[3,6]`.
+
+A group is considered **large** if it has 3 or more characters.
+
+Return *the intervals of every **large** group sorted in **increasing order by start index***.
+
+**Example 1:**
+
+```
+Input: s = "abbxxxxzzy"
+Output: [[3,6]]
+Explanation: "xxxx" is the only large group with start index 3 and end index 6.
+```
+
+**Example 2:**
+
+```
+Input: s = "abc"
+Output: []
+Explanation: We have groups "a", "b", and "c", none of which are large groups.
+```
+
+**Example 3:**
+
+```
+Input: s = "abcdddeeeeaabbbcd"
+Output: [[3,5],[6,9],[12,14]]
+Explanation: The large groups are "ddd", "eeee", and "bbb".
+```
+
+**Example 4:**
+
+```
+Input: s = "aba"
+Output: []
+```
+
+**Constraints:**
+
+- `1 <= s.length <= 1000`
+- `s` contains lower-case English letters only.
+
+## 题目大意
+
+在一个由小写字母构成的字符串 s 中,包含由一些连续的相同字符所构成的分组。例如,在字符串 s = "abbxxxxzyy" 中,就含有 "a", "bb", "xxxx", "z" 和 "yy" 这样的一些分组。分组可以用区间 [start, end] 表示,其中 start 和 end 分别表示该分组的起始和终止位置的下标。上例中的 "xxxx" 分组用区间表示为 [3,6] 。我们称所有包含大于或等于三个连续字符的分组为 较大分组 。
+
+找到每一个 较大分组 的区间,按起始位置下标递增顺序排序后,返回结果。
+
+## 解题思路
+
+- 简单题。利用滑动窗口的思想,先扩大窗口的右边界,找到能相同字母且能到达的最右边。记录左右边界。再将窗口的左边界移动到上一次的右边界处。以此类推,重复扩大窗口的右边界,直至扫完整个字符串。最终所有满足题意的较大分组区间都在数组中了。
+
+## 代码
+
+```go
+package leetcode
+
+func largeGroupPositions(S string) [][]int {
+ res, end := [][]int{}, 0
+ for end < len(S) {
+ start, str := end, S[end]
+ for end < len(S) && S[end] == str {
+ end++
+ }
+ if end-start >= 3 {
+ res = append(res, []int{start, end - 1})
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/0910.Smallest-Range-II/910.Smallest Range II.go b/leetcode/0910.Smallest-Range-II/910.Smallest Range II.go
new file mode 100644
index 00000000..a2543300
--- /dev/null
+++ b/leetcode/0910.Smallest-Range-II/910.Smallest Range II.go
@@ -0,0 +1,30 @@
+package leetcode
+
+import "sort"
+
+func smallestRangeII(A []int, K int) int {
+ n := len(A)
+ sort.Ints(A)
+ res := A[n-1] - A[0]
+ for i := 0; i < n-1; i++ {
+ a, b := A[i], A[i+1]
+ high := max(A[n-1]-K, a+K)
+ low := min(A[0]+K, b-K)
+ res = min(res, high-low)
+ }
+ return res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/0910.Smallest-Range-II/910.Smallest Range II_test.go b/leetcode/0910.Smallest-Range-II/910.Smallest Range II_test.go
new file mode 100644
index 00000000..f1a83a99
--- /dev/null
+++ b/leetcode/0910.Smallest-Range-II/910.Smallest Range II_test.go
@@ -0,0 +1,48 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question910 struct {
+ para910
+ ans910
+}
+
+type para910 struct {
+ A []int
+ K int
+}
+
+type ans910 struct {
+ one int
+}
+
+// Test_Problem910 ...
+func Test_Problem910(t *testing.T) {
+
+ qs := []question910{
+
+ {
+ para910{[]int{1}, 0},
+ ans910{0},
+ },
+ {
+ para910{[]int{0, 10}, 2},
+ ans910{6},
+ },
+ {
+ para910{[]int{1, 3, 6}, 3},
+ ans910{3},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 910------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans910, q.para910
+ fmt.Printf("【input】:%v 【output】:%v\n", p, smallestRangeII(p.A, p.K))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/0910.Smallest-Range-II/README.md b/leetcode/0910.Smallest-Range-II/README.md
new file mode 100644
index 00000000..e8a3d8ff
--- /dev/null
+++ b/leetcode/0910.Smallest-Range-II/README.md
@@ -0,0 +1,82 @@
+# [910. Smallest Range II](https://leetcode.com/problems/smallest-range-ii/)
+
+## 题目
+
+Given an array `A` of integers, for each integer `A[i]` we need to choose **either `x = -K` or `x = K`**, and add `x` to `A[i]` **(only once)**.
+
+After this process, we have some array `B`.
+
+Return the smallest possible difference between the maximum value of `B` and the minimum value of `B`.
+
+**Example 1:**
+
+```c
+Input: A = [1], K = 0
+Output: 0
+Explanation: B = [1]
+```
+
+**Example 2:**
+
+```c
+Input: A = [0,10], K = 2
+Output: 6
+Explanation: B = [2,8]
+```
+
+**Example 3:**
+
+```c
+Input: A = [1,3,6], K = 3
+Output: 3
+Explanation: B = [4,6,3]
+```
+
+**Note:**
+
+1. `1 <= A.length <= 10000`
+2. `0 <= A[i] <= 10000`
+3. `0 <= K <= 10000`
+
+## 题目大意
+
+给你一个整数数组 A,对于每个整数 A[i],可以选择 x = -K 或是 x = K (K 总是非负整数),并将 x 加到 A[i] 中。在此过程之后,得到数组 B。返回 B 的最大值和 B 的最小值之间可能存在的最小差值。
+
+## 解题思路
+
+- 简单题。先排序,找出 A 数组中最大的差值。然后循环扫一遍数组,利用双指针,选择 x = -K 或是 x = K ,每次选择都更新一次最大值和最小值之间的最小差值。循环一次以后便可以找到满足题意的答案。
+
+## 代码
+
+```go
+package leetcode
+
+import "sort"
+
+func smallestRangeII(A []int, K int) int {
+ n := len(A)
+ sort.Ints(A)
+ res := A[n-1] - A[0]
+ for i := 0; i < n-1; i++ {
+ a, b := A[i], A[i+1]
+ high := max(A[n-1]-K, a+K)
+ low := min(A[0]+K, b-K)
+ res = min(res, high-low)
+ }
+ return res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name.go b/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name.go
index 69b27ea5..8c28a2bf 100644
--- a/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name.go
+++ b/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name.go
@@ -7,20 +7,18 @@ func isLongPressedName(name string, typed string) bool {
if (len(name) == 0 && len(typed) != 0) || (len(name) != 0 && len(typed) == 0) {
return false
}
-
- j := 0
- for i := 0; i < len(name); i++ {
- if j < len(typed) && name[i] == typed[j] {
+ i, j := 0, 0
+ for i < len(name) && j < len(typed) {
+ if name[i] != typed[j] {
+ return false
+ }
+ for i < len(name) && j < len(typed) && name[i] == typed[j] {
+ i++
+ j++
+ }
+ for j < len(typed) && typed[j] == typed[j-1] {
j++
- continue
- } else {
- if i > 0 && j < len(typed) && name[i-1] == typed[j] {
- j++
- i--
- } else {
- return false
- }
}
}
- return true
+ return i == len(name) && j == len(typed)
}
diff --git a/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name_test.go b/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name_test.go
index f374c797..d2ae6662 100644
--- a/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name_test.go
+++ b/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name_test.go
@@ -32,6 +32,21 @@ func Test_Problem925(t *testing.T) {
ans925{true},
},
+ {
+ para925{"alex", "alexxr"},
+ ans925{false},
+ },
+
+ {
+ para925{"alex", "alexxxxr"},
+ ans925{false},
+ },
+
+ {
+ para925{"alex", "alexxxxx"},
+ ans925{true},
+ },
+
{
para925{"saeed", "ssaaedd"},
ans925{false},
diff --git a/leetcode/0925.Long-Pressed-Name/README.md b/leetcode/0925.Long-Pressed-Name/README.md
index 95dfbaf5..1b588feb 100644
--- a/leetcode/0925.Long-Pressed-Name/README.md
+++ b/leetcode/0925.Long-Pressed-Name/README.md
@@ -53,8 +53,8 @@ Note:
## 解题思路
-这一题也可以借助滑动窗口的思想。2 个字符串一起比较,如果遇到有相同的字符串,窗口继续往后滑动。直到遇到了第一个不同的字符,如果遇到两个字符串不相等的情况,可以直接返回 false。具体实现见代码。
-
+- 这一题也可以借助滑动窗口的思想。2 个字符串一起比较,如果遇到有相同的字符串,窗口继续往后滑动。直到遇到了第一个不同的字符,如果遇到两个字符串不相等的情况,可以直接返回 false。具体实现见代码。
+- 这一题的测试用例修改过一次,需要注意我这里写的第二组测试用例,当 name 结束以后,如果 typed 还有多余的不同的字符,这种情况要输出 false 的。具体见 test 文件里面的第二组,第三组,第四组测试用例。
diff --git a/leetcode/0978.Longest-Turbulent-Subarray/978. Longest Turbulent Subarray.go b/leetcode/0978.Longest-Turbulent-Subarray/978. Longest Turbulent Subarray.go
index 60d3eace..8a089026 100644
--- a/leetcode/0978.Longest-Turbulent-Subarray/978. Longest Turbulent Subarray.go
+++ b/leetcode/0978.Longest-Turbulent-Subarray/978. Longest Turbulent Subarray.go
@@ -47,7 +47,7 @@ func maxTurbulenceSize1(A []int) int {
flag = lastNum - A[right]
lastNum = A[right]
} else {
- if right != left && flag != 0 {
+ if flag != 0 {
res = max(res, right-left+1)
}
left++
diff --git a/leetcode/1018.Binary-Prefix-Divisible-By-5/1018. Binary Prefix Divisible By 5.go b/leetcode/1018.Binary-Prefix-Divisible-By-5/1018. Binary Prefix Divisible By 5.go
new file mode 100644
index 00000000..8d88763f
--- /dev/null
+++ b/leetcode/1018.Binary-Prefix-Divisible-By-5/1018. Binary Prefix Divisible By 5.go
@@ -0,0 +1,10 @@
+package leetcode
+
+func prefixesDivBy5(a []int) []bool {
+ res, num := make([]bool, len(a)), 0
+ for i, v := range a {
+ num = (num<<1 | v) % 5
+ res[i] = num == 0
+ }
+ return res
+}
diff --git a/leetcode/1018.Binary-Prefix-Divisible-By-5/1018. Binary Prefix Divisible By 5_test.go b/leetcode/1018.Binary-Prefix-Divisible-By-5/1018. Binary Prefix Divisible By 5_test.go
new file mode 100644
index 00000000..2903210e
--- /dev/null
+++ b/leetcode/1018.Binary-Prefix-Divisible-By-5/1018. Binary Prefix Divisible By 5_test.go
@@ -0,0 +1,57 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1018 struct {
+ para1018
+ ans1018
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1018 struct {
+ a []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1018 struct {
+ one []bool
+}
+
+func Test_Problem1018(t *testing.T) {
+
+ qs := []question1018{
+
+ {
+ para1018{[]int{0, 1, 1}},
+ ans1018{[]bool{true, false, false}},
+ },
+
+ {
+ para1018{[]int{1, 1, 1}},
+ ans1018{[]bool{false, false, false}},
+ },
+
+ {
+ para1018{[]int{0, 1, 1, 1, 1, 1}},
+ ans1018{[]bool{true, false, false, false, true, false}},
+ },
+
+ {
+ para1018{[]int{1, 1, 1, 0, 1}},
+ ans1018{[]bool{false, false, false, false, false}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1018------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1018, q.para1018
+ fmt.Printf("【input】:%v 【output】:%v\n", p, prefixesDivBy5(p.a))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1018.Binary-Prefix-Divisible-By-5/README.md b/leetcode/1018.Binary-Prefix-Divisible-By-5/README.md
new file mode 100644
index 00000000..5559c7e9
--- /dev/null
+++ b/leetcode/1018.Binary-Prefix-Divisible-By-5/README.md
@@ -0,0 +1,70 @@
+# [1018. Binary Prefix Divisible By 5](https://leetcode.com/problems/binary-prefix-divisible-by-5/)
+
+
+## 题目
+
+Given an array `A` of `0`s and `1`s, consider `N_i`: the i-th subarray from `A[0]` to `A[i]` interpreted as a binary number (from most-significant-bit to least-significant-bit.)
+
+Return a list of booleans `answer`, where `answer[i]` is `true` if and only if `N_i` is divisible by 5.
+
+**Example 1:**
+
+```
+Input: [0,1,1]
+Output: [true,false,false]
+Explanation:
+The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. Only the first number is divisible by 5, so answer[0] is true.
+
+```
+
+**Example 2:**
+
+```
+Input: [1,1,1]
+Output: [false,false,false]
+
+```
+
+**Example 3:**
+
+```
+Input: [0,1,1,1,1,1]
+Output: [true,false,false,false,true,false]
+
+```
+
+**Example 4:**
+
+```
+Input: [1,1,1,0,1]
+Output: [false,false,false,false,false]
+
+```
+
+**Note:**
+
+1. `1 <= A.length <= 30000`
+2. `A[i]` is `0` or `1`
+
+## 题目大意
+
+给定由若干 0 和 1 组成的数组 A。我们定义 N_i:从 A[0] 到 A[i] 的第 i 个子数组被解释为一个二进制数(从最高有效位到最低有效位)。返回布尔值列表 answer,只有当 N_i 可以被 5 整除时,答案 answer[i] 为 true,否则为 false。
+
+## 解题思路
+
+- 简单题。每扫描数组中的一个数字,累计转换成二进制数对 5 取余,如果余数为 0,则存入 true,否则存入 false。
+
+## 代码
+
+```go
+package leetcode
+
+func prefixesDivBy5(a []int) []bool {
+ res, num := make([]bool, len(a)), 0
+ for i, v := range a {
+ num = (num<<1 | v) % 5
+ res[i] = num == 0
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1079.Letter-Tile-Possibilities/README.md b/leetcode/1079.Letter-Tile-Possibilities/README.md
index e8e12a5e..4f789c73 100755
--- a/leetcode/1079.Letter-Tile-Possibilities/README.md
+++ b/leetcode/1079.Letter-Tile-Possibilities/README.md
@@ -33,4 +33,4 @@ You have a set of `tiles`, where each tile has one letter `tiles[i]` printed
- 题目要求输出所有非空字母序列的数目。这一题是排列和组合的结合题目。组合是可以选择一个字母,二个字母,…… n 个字母。每个组合内是排列问题。比如选择 2 个字母,字母之间相互排序不同是影响最终结果的,不同的排列顺序是不同的解。
- 这道题目由于不需要输出所有解,所以解法可以优化,例如我们在递归计算解的时候,不需要真的遍历原字符串,只需要累加一些字母的频次就可以。当然如果要输出所有解,就需要真实遍历原字符串了(见解法二)。简单的做法是每次递归按照频次累加。因为每次增加一个字母一定是 26 个大写字母中的一个。这里需要注意的是,增加的只能是 26 个字母里面还能取出“机会”的字母,例如递归到到第 3 轮了,A 用完了,这个时候只能取频次还不为 0 的字母拼上去。
-
\ No newline at end of file
+
diff --git a/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies.go b/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies.go
new file mode 100644
index 00000000..07a715b8
--- /dev/null
+++ b/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies.go
@@ -0,0 +1,123 @@
+package leetcode
+
+// 解法一 拓扑排序版的 DFS
+func sortItems(n int, m int, group []int, beforeItems [][]int) []int {
+ groups, inDegrees := make([][]int, n+m), make([]int, n+m)
+ for i, g := range group {
+ if g > -1 {
+ g += n
+ groups[g] = append(groups[g], i)
+ inDegrees[i]++
+ }
+ }
+ for i, ancestors := range beforeItems {
+ gi := group[i]
+ if gi == -1 {
+ gi = i
+ } else {
+ gi += n
+ }
+ for _, ancestor := range ancestors {
+ ga := group[ancestor]
+ if ga == -1 {
+ ga = ancestor
+ } else {
+ ga += n
+ }
+ if gi == ga {
+ groups[ancestor] = append(groups[ancestor], i)
+ inDegrees[i]++
+ } else {
+ groups[ga] = append(groups[ga], gi)
+ inDegrees[gi]++
+ }
+ }
+ }
+ res := []int{}
+ for i, d := range inDegrees {
+ if d == 0 {
+ sortItemsDFS(i, n, &res, &inDegrees, &groups)
+ }
+ }
+ if len(res) != n {
+ return nil
+ }
+ return res
+}
+
+func sortItemsDFS(i, n int, res, inDegrees *[]int, groups *[][]int) {
+ if i < n {
+ *res = append(*res, i)
+ }
+ (*inDegrees)[i] = -1
+ for _, ch := range (*groups)[i] {
+ if (*inDegrees)[ch]--; (*inDegrees)[ch] == 0 {
+ sortItemsDFS(ch, n, res, inDegrees, groups)
+ }
+ }
+}
+
+// 解法二 二维拓扑排序 时间复杂度 O(m+n),空间复杂度 O(m+n)
+func sortItems1(n int, m int, group []int, beforeItems [][]int) []int {
+ groupItems, res := map[int][]int{}, []int{}
+ for i := 0; i < len(group); i++ {
+ if group[i] == -1 {
+ group[i] = m + i
+ }
+ groupItems[group[i]] = append(groupItems[group[i]], i)
+ }
+ groupGraph, groupDegree, itemGraph, itemDegree := make([][]int, m+n), make([]int, m+n), make([][]int, n), make([]int, n)
+ for i := 0; i < len(beforeItems); i++ {
+ for j := 0; j < len(beforeItems[i]); j++ {
+ if group[beforeItems[i][j]] != group[i] {
+ // 不同组项目,确定组间依赖关系
+ groupGraph[group[beforeItems[i][j]]] = append(groupGraph[group[beforeItems[i][j]]], group[i])
+ groupDegree[group[i]]++
+ } else {
+ // 同组项目,确定组内依赖关系
+ itemGraph[beforeItems[i][j]] = append(itemGraph[beforeItems[i][j]], i)
+ itemDegree[i]++
+ }
+ }
+ }
+ items := []int{}
+ for i := 0; i < m+n; i++ {
+ items = append(items, i)
+ }
+ // 组间拓扑
+ groupOrders := topSort(groupGraph, groupDegree, items)
+ if len(groupOrders) < len(items) {
+ return nil
+ }
+ for i := 0; i < len(groupOrders); i++ {
+ items := groupItems[groupOrders[i]]
+ // 组内拓扑
+ orders := topSort(itemGraph, itemDegree, items)
+ if len(orders) < len(items) {
+ return nil
+ }
+ res = append(res, orders...)
+ }
+ return res
+}
+
+func topSort(graph [][]int, deg, items []int) (orders []int) {
+ q := []int{}
+ for _, i := range items {
+ if deg[i] == 0 {
+ q = append(q, i)
+ }
+ }
+ for len(q) > 0 {
+ from := q[0]
+ q = q[1:]
+ orders = append(orders, from)
+ for _, to := range graph[from] {
+ deg[to]--
+ if deg[to] == 0 {
+ q = append(q, to)
+ }
+ }
+ }
+ return
+}
diff --git a/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies_test.go b/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies_test.go
new file mode 100644
index 00000000..6abb3b54
--- /dev/null
+++ b/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies_test.go
@@ -0,0 +1,50 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1203 struct {
+ para1203
+ ans1203
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1203 struct {
+ n int
+ m int
+ group []int
+ beforeItems [][]int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1203 struct {
+ one []int
+}
+
+func Test_Problem1203(t *testing.T) {
+
+ qs := []question1203{
+
+ {
+ para1203{8, 2, []int{-1, -1, 1, 0, 0, 1, 0, -1}, [][]int{{}, {6}, {5}, {6}, {3, 6}, {}, {}, {}}},
+ ans1203{[]int{6, 3, 4, 5, 2, 0, 7, 1}},
+ },
+
+ {
+ para1203{8, 2, []int{-1, -1, 1, 0, 0, 1, 0, -1}, [][]int{{}, {6}, {5}, {6}, {3}, {}, {4}, {}}},
+ ans1203{[]int{}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1203------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1203, q.para1203
+ fmt.Printf("【input】:%v 【output】:%v\n", p, sortItems1(p.n, p.m, p.group, p.beforeItems))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/README.md b/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/README.md
new file mode 100644
index 00000000..3bbddd16
--- /dev/null
+++ b/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/README.md
@@ -0,0 +1,191 @@
+# [1203. Sort Items by Groups Respecting Dependencies](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies/)
+
+
+## 题目
+
+There are `n` items each belonging to zero or one of `m` groups where `group[i]` is the group that the `i`-th item belongs to and it's equal to `-1` if the `i`-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.
+
+Return a sorted list of the items such that:
+
+- The items that belong to the same group are next to each other in the sorted list.
+- There are some relations between these items where `beforeItems[i]` is a list containing all the items that should come before the `i`th item in the sorted array (to the left of the `i`th item).
+
+Return any solution if there is more than one solution and return an **empty list** if there is no solution.
+
+**Example 1:**
+
+
+
+```
+Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]
+Output: [6,3,4,1,5,2,0,7]
+
+```
+
+**Example 2:**
+
+```
+Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]
+Output: []
+Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.
+
+```
+
+**Constraints:**
+
+- `1 <= m <= n <= 3 * 104`
+- `group.length == beforeItems.length == n`
+- `1 <= group[i] <= m - 1`
+- `0 <= beforeItems[i].length <= n - 1`
+- `0 <= beforeItems[i][j] <= n - 1`
+- `i != beforeItems[i][j]`
+- `beforeItems[i]` does not contain duplicates elements.
+
+## 题目大意
+
+有 n 个项目,每个项目或者不属于任何小组,或者属于 m 个小组之一。group[i] 表示第 i 个小组所属的小组,如果第 i 个项目不属于任何小组,则 group[i] 等于 -1。项目和小组都是从零开始编号的。可能存在小组不负责任何项目,即没有任何项目属于这个小组。
+
+请你帮忙按要求安排这些项目的进度,并返回排序后的项目列表:
+
+- 同一小组的项目,排序后在列表中彼此相邻。
+- 项目之间存在一定的依赖关系,我们用一个列表 beforeItems 来表示,其中 beforeItems[i] 表示在进行第 i 个项目前(位于第 i 个项目左侧)应该完成的所有项目。
+
+如果存在多个解决方案,只需要返回其中任意一个即可。如果没有合适的解决方案,就请返回一个 空列表 。
+
+## 解题思路
+
+- 读完题能确定这一题是拓扑排序。但是和单纯的拓扑排序有区别的是,同一小组内的项目需要彼此相邻。用 2 次拓扑排序即可解决。第一次拓扑排序排出组间的顺序,第二次拓扑排序排出组内的顺序。为了实现方便,用 map 给虚拟分组标记编号。如下图,将 3,4,6 三个任务打包到 0 号分组里面,将 2,5 两个任务打包到 1 号分组里面,其他任务单独各自为一组。组间的依赖是 6 号任务依赖 1 号任务。由于 6 号任务封装在 0 号分组里,所以 3 号分组依赖 0 号分组。先组间排序,确定分组顺序,再组内拓扑排序,排出最终顺序。
+
+ 
+
+- 上面的解法可以 AC,但是时间太慢了。因为做了一些不必要的操作。有没有可能只用一次拓扑排序呢?将必须要在一起的结点统一依赖一个虚拟结点,例如下图中的虚拟结点 8 和 9 。3,4,6 都依赖 8 号任务,2 和 5 都依赖 9 号任务。1 号任务本来依赖 6 号任务,由于 6 由依赖 8 ,所以添加 1 依赖 8 的边。通过增加虚拟结点,增加了需要打包在一起结点的入度。构建出以上关系以后,按照入度为 0 的原则,依次进行 DFS。8 号和 9 号两个虚拟结点的入度都为 0 ,对它们进行 DFS,必定会使得与它关联的节点都被安排在一起,这样就满足了题意:同一小组的项目,排序后在列表中彼此相邻。一遍扫完,满足题意的顺序就排出来了。这个解法 beat 100%!
+
+ 
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 拓扑排序版的 DFS
+func sortItems(n int, m int, group []int, beforeItems [][]int) []int {
+ groups, inDegrees := make([][]int, n+m), make([]int, n+m)
+ for i, g := range group {
+ if g > -1 {
+ g += n
+ groups[g] = append(groups[g], i)
+ inDegrees[i]++
+ }
+ }
+ for i, ancestors := range beforeItems {
+ gi := group[i]
+ if gi == -1 {
+ gi = i
+ } else {
+ gi += n
+ }
+ for _, ancestor := range ancestors {
+ ga := group[ancestor]
+ if ga == -1 {
+ ga = ancestor
+ } else {
+ ga += n
+ }
+ if gi == ga {
+ groups[ancestor] = append(groups[ancestor], i)
+ inDegrees[i]++
+ } else {
+ groups[ga] = append(groups[ga], gi)
+ inDegrees[gi]++
+ }
+ }
+ }
+ res := []int{}
+ for i, d := range inDegrees {
+ if d == 0 {
+ sortItemsDFS(i, n, &res, &inDegrees, &groups)
+ }
+ }
+ if len(res) != n {
+ return nil
+ }
+ return res
+}
+
+func sortItemsDFS(i, n int, res, inDegrees *[]int, groups *[][]int) {
+ if i < n {
+ *res = append(*res, i)
+ }
+ (*inDegrees)[i] = -1
+ for _, ch := range (*groups)[i] {
+ if (*inDegrees)[ch]--; (*inDegrees)[ch] == 0 {
+ sortItemsDFS(ch, n, res, inDegrees, groups)
+ }
+ }
+}
+
+// 解法二 二维拓扑排序 时间复杂度 O(m+n),空间复杂度 O(m+n)
+func sortItems1(n int, m int, group []int, beforeItems [][]int) []int {
+ groupItems, res := map[int][]int{}, []int{}
+ for i := 0; i < len(group); i++ {
+ if group[i] == -1 {
+ group[i] = m + i
+ }
+ groupItems[group[i]] = append(groupItems[group[i]], i)
+ }
+ groupGraph, groupDegree, itemGraph, itemDegree := make([][]int, m+n), make([]int, m+n), make([][]int, n), make([]int, n)
+ for i := 0; i < len(beforeItems); i++ {
+ for j := 0; j < len(beforeItems[i]); j++ {
+ if group[beforeItems[i][j]] != group[i] {
+ // 不同组项目,确定组间依赖关系
+ groupGraph[group[beforeItems[i][j]]] = append(groupGraph[group[beforeItems[i][j]]], group[i])
+ groupDegree[group[i]]++
+ } else {
+ // 同组项目,确定组内依赖关系
+ itemGraph[beforeItems[i][j]] = append(itemGraph[beforeItems[i][j]], i)
+ itemDegree[i]++
+ }
+ }
+ }
+ items := []int{}
+ for i := 0; i < m+n; i++ {
+ items = append(items, i)
+ }
+ // 组间拓扑
+ groupOrders := topSort(groupGraph, groupDegree, items)
+ if len(groupOrders) < len(items) {
+ return nil
+ }
+ for i := 0; i < len(groupOrders); i++ {
+ items := groupItems[groupOrders[i]]
+ // 组内拓扑
+ orders := topSort(itemGraph, itemDegree, items)
+ if len(orders) < len(items) {
+ return nil
+ }
+ res = append(res, orders...)
+ }
+ return res
+}
+
+func topSort(graph [][]int, deg, items []int) (orders []int) {
+ q := []int{}
+ for _, i := range items {
+ if deg[i] == 0 {
+ q = append(q, i)
+ }
+ }
+ for len(q) > 0 {
+ from := q[0]
+ q = q[1:]
+ orders = append(orders, from)
+ for _, to := range graph[from] {
+ deg[to]--
+ if deg[to] == 0 {
+ q = append(q, to)
+ }
+ }
+ }
+ return
+}
+```
\ No newline at end of file
diff --git a/leetcode/1217.Play-with-Chips/1217. Play with Chips.go b/leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position.go
similarity index 100%
rename from leetcode/1217.Play-with-Chips/1217. Play with Chips.go
rename to leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position.go
diff --git a/leetcode/1217.Play-with-Chips/1217. Play with Chips_test.go b/leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position_test.go
similarity index 100%
rename from leetcode/1217.Play-with-Chips/1217. Play with Chips_test.go
rename to leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position_test.go
diff --git a/leetcode/1217.Play-with-Chips/README.md b/leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/README.md
similarity index 95%
rename from leetcode/1217.Play-with-Chips/README.md
rename to leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/README.md
index 7eb9669f..e7ac7fe5 100755
--- a/leetcode/1217.Play-with-Chips/README.md
+++ b/leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/README.md
@@ -1,4 +1,4 @@
-# [1217. Play with Chips](https://leetcode.com/problems/play-with-chips/)
+# [1217. Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/)
## 题目
diff --git a/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target.go b/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target.go
index f008a556..9bd5f6d5 100644
--- a/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target.go
+++ b/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target.go
@@ -10,6 +10,15 @@ func findBestValue(arr []int, target int) int {
high = mid
}
}
+ if high == 100000 {
+ res := 0
+ for _, num := range arr {
+ if res < num {
+ res = num
+ }
+ }
+ return res
+ }
// 比较阈值线分别定在 left - 1 和 left 的时候与 target 的接近程度
sum1, sum2 := calculateSum(arr, low-1), calculateSum(arr, low)
if target-sum1 <= sum2-target {
diff --git a/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target_test.go b/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target_test.go
index 9fca7e54..da66fbba 100644
--- a/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target_test.go
+++ b/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target_test.go
@@ -37,6 +37,12 @@ func Test_Problem1300(t *testing.T) {
ans1300{5},
},
+ // new case
+ {
+ para1300{[]int{2, 3, 5}, 11},
+ ans1300{5},
+ },
+
{
para1300{[]int{60864, 25176, 27249, 21296, 20204}, 56803},
ans1300{11361},
diff --git a/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/README.md b/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/README.md
index dcee2bcd..15c7d5d7 100644
--- a/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/README.md
+++ b/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/README.md
@@ -57,6 +57,7 @@ Output: 11361
## 代码
```go
+
func findBestValue(arr []int, target int) int {
low, high := 0, 100000
for low < high {
@@ -67,6 +68,15 @@ func findBestValue(arr []int, target int) int {
high = mid
}
}
+ if high == 100000 {
+ res := 0
+ for _, num := range arr {
+ if res < num {
+ res = num
+ }
+ }
+ return res
+ }
// 比较阈值线分别定在 left - 1 和 left 的时候与 target 的接近程度
sum1, sum2 := calculateSum(arr, low-1), calculateSum(arr, low)
if target-sum1 <= sum2-target {
@@ -82,4 +92,12 @@ func calculateSum(arr []int, mid int) int {
}
return sum
}
+
+func min(a int, b int) int {
+ if a > b {
+ return b
+ }
+ return a
+}
+
```
\ No newline at end of file
diff --git a/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array.go b/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array.go
new file mode 100644
index 00000000..7663c290
--- /dev/null
+++ b/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array.go
@@ -0,0 +1,10 @@
+package leetcode
+
+func runningSum(nums []int) []int {
+ dp := make([]int, len(nums)+1)
+ dp[0] = 0
+ for i := 1; i <= len(nums); i++ {
+ dp[i] = dp[i-1] + nums[i-1]
+ }
+ return dp[1:]
+}
diff --git a/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array_test.go b/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array_test.go
new file mode 100644
index 00000000..c2053b1b
--- /dev/null
+++ b/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1480 struct {
+ para1480
+ ans1480
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1480 struct {
+ nums []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1480 struct {
+ one []int
+}
+
+func Test_Problem1480(t *testing.T) {
+
+ qs := []question1480{
+
+ {
+ para1480{[]int{1, 2, 3, 4}},
+ ans1480{[]int{1, 3, 6, 10}},
+ },
+
+ {
+ para1480{[]int{1, 1, 1, 1, 1}},
+ ans1480{[]int{1, 2, 3, 4, 5}},
+ },
+
+ {
+ para1480{[]int{3, 1, 2, 10, 1}},
+ ans1480{[]int{3, 4, 6, 16, 17}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1480------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1480, q.para1480
+ fmt.Printf("【input】:%v 【output】:%v \n", p, runningSum(p.nums))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1480.Running-Sum-of-1d-Array/README.md b/leetcode/1480.Running-Sum-of-1d-Array/README.md
new file mode 100644
index 00000000..d0e48335
--- /dev/null
+++ b/leetcode/1480.Running-Sum-of-1d-Array/README.md
@@ -0,0 +1,64 @@
+# [1480. Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/)
+
+## 题目
+
+Given an array `nums`. We define a running sum of an array as `runningSum[i] = sum(nums[0]…nums[i])`.
+
+Return the running sum of `nums`.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,4]
+Output: [1,3,6,10]
+Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,1,1,1,1]
+Output: [1,2,3,4,5]
+Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
+
+```
+
+**Example 3**:
+
+```
+Input: nums = [3,1,2,10,1]
+Output: [3,4,6,16,17]
+
+```
+
+
+**Constraints**:
+
+- `1 <= nums.length <= 1000`
+- `-10^6 <= nums[i] <= 10^6`
+
+## 题目大意
+
+给你一个数组 nums 。数组「动态和」的计算公式为:runningSum[i] = sum(nums[0]…nums[i]) 。请返回 nums 的动态和。
+
+
+## 解题思路
+
+- 简单题,按照题意依次循环计算前缀和即可。
+
+## 代码
+
+```go
+package leetcode
+
+func runningSum(nums []int) []int {
+ dp := make([]int, len(nums)+1)
+ dp[0] = 0
+ for i := 1; i <= len(nums); i++ {
+ dp[i] = dp[i-1] + nums[i-1]
+ }
+ return dp[1:]
+}
+
+```
\ No newline at end of file
diff --git a/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs.go b/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs.go
new file mode 100644
index 00000000..6edfcdfa
--- /dev/null
+++ b/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs.go
@@ -0,0 +1,13 @@
+package leetcode
+
+func numIdenticalPairs(nums []int) int {
+ total := 0
+ for x := 0; x < len(nums); x++ {
+ for y := x + 1; y < len(nums); y++ {
+ if nums[x] == nums[y] {
+ total++
+ }
+ }
+ }
+ return total
+}
diff --git a/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs_test.go b/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs_test.go
new file mode 100644
index 00000000..3fc12218
--- /dev/null
+++ b/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1512 struct {
+ para1512
+ ans1512
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1512 struct {
+ nums []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1512 struct {
+ one int
+}
+
+func Test_Problem1512(t *testing.T) {
+
+ qs := []question1512{
+
+ {
+ para1512{[]int{1, 2, 3, 1, 1, 3}},
+ ans1512{4},
+ },
+
+ {
+ para1512{[]int{1, 1, 1, 1}},
+ ans1512{6},
+ },
+
+ {
+ para1512{[]int{1, 2, 3}},
+ ans1512{0},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1512------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1512, q.para1512
+ fmt.Printf("【input】:%v 【output】:%v \n", p, numIdenticalPairs(p.nums))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1512.Number-of-Good-Pairs/README.md b/leetcode/1512.Number-of-Good-Pairs/README.md
new file mode 100644
index 00000000..a6954aa0
--- /dev/null
+++ b/leetcode/1512.Number-of-Good-Pairs/README.md
@@ -0,0 +1,67 @@
+# [1512. Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/)
+
+## 题目
+
+Given an array of integers `nums`.
+
+A pair `(i,j)` is called good if `nums[i] == nums[j]` and `i < j`.
+
+Return the number of good pairs.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,1,1,3]
+Output: 4
+Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,1,1,1]
+Output: 6
+Explanation: Each pair in the array are good.
+
+```
+
+**Example 3**:
+
+```
+Input: nums = [1,2,3]
+Output: 0
+
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 1000`
+- `1 <= nums[i] <= 100`
+
+## 题目大意
+
+给你一个整数数组 nums。如果一组数字 (i,j) 满足 nums[i] == nums[j] 且 i < j ,就可以认为这是一组好数对。返回好数对的数目。
+
+## 解题思路
+
+- 简单题,按照题目中好数对的定义,循环遍历判断两数是否相等,累加计数即可。
+
+## 代码
+
+```go
+package leetcode
+
+func numIdenticalPairs(nums []int) int {
+ total := 0
+ for x := 0; x < len(nums); x++ {
+ for y := x + 1; y < len(nums); y++ {
+ if nums[x] == nums[y] {
+ total++
+ }
+ }
+ }
+ return total
+}
+
+```
\ No newline at end of file
diff --git a/leetcode/1539.Kth-Missing-Positive-Number/1539. Kth Missing Positive Number.go b/leetcode/1539.Kth-Missing-Positive-Number/1539. Kth Missing Positive Number.go
new file mode 100644
index 00000000..667a3b70
--- /dev/null
+++ b/leetcode/1539.Kth-Missing-Positive-Number/1539. Kth Missing Positive Number.go
@@ -0,0 +1,20 @@
+package leetcode
+
+func findKthPositive(arr []int, k int) int {
+ positive, index := 1, 0
+ for index < len(arr) {
+ if arr[index] != positive {
+ k--
+ } else {
+ index++
+ }
+ if k == 0 {
+ break
+ }
+ positive++
+ }
+ if k != 0 {
+ positive += k - 1
+ }
+ return positive
+}
diff --git a/leetcode/1539.Kth-Missing-Positive-Number/1539. Kth Missing Positive Number_test.go b/leetcode/1539.Kth-Missing-Positive-Number/1539. Kth Missing Positive Number_test.go
new file mode 100644
index 00000000..ffd93841
--- /dev/null
+++ b/leetcode/1539.Kth-Missing-Positive-Number/1539. Kth Missing Positive Number_test.go
@@ -0,0 +1,48 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1539 struct {
+ para1539
+ ans1539
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1539 struct {
+ arr []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1539 struct {
+ one int
+}
+
+func Test_Problem1539(t *testing.T) {
+
+ qs := []question1539{
+
+ {
+ para1539{[]int{2, 3, 4, 7, 11}, 5},
+ ans1539{9},
+ },
+
+ {
+ para1539{[]int{1, 2, 3, 4}, 2},
+ ans1539{6},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1539------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1539, q.para1539
+ fmt.Printf("【input】:%v 【output】:%v \n", p, findKthPositive(p.arr, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1539.Kth-Missing-Positive-Number/README.md b/leetcode/1539.Kth-Missing-Positive-Number/README.md
new file mode 100644
index 00000000..ba13a085
--- /dev/null
+++ b/leetcode/1539.Kth-Missing-Positive-Number/README.md
@@ -0,0 +1,63 @@
+# [1539. Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number/)
+
+## 题目
+
+Given an array `arr` of positive integers sorted in a **strictly increasing order**, and an integer `k`.
+
+*Find the* `kth` *positive integer that is missing from this array.*
+
+**Example 1:**
+
+```
+Input: arr = [2,3,4,7,11], k = 5
+Output: 9
+Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9.
+```
+
+**Example 2:**
+
+```
+Input: arr = [1,2,3,4], k = 2
+Output: 6
+Explanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6.
+```
+
+**Constraints:**
+
+- `1 <= arr.length <= 1000`
+- `1 <= arr[i] <= 1000`
+- `1 <= k <= 1000`
+- `arr[i] < arr[j]` for `1 <= i < j <= arr.length`
+
+## 题目大意
+
+给你一个 **严格升序排列** 的正整数数组 `arr` 和一个整数 `k` 。请你找到这个数组里第 `k` 个缺失的正整数。
+
+## 解题思路
+
+- 简单题。用一个变量从 1 开始累加,依次比对数组中是否存在,不存在的话就把 k - -,直到 k 为 0 的时候即是要输出的值。特殊情况,missing positive 都在数组之外,如例子 2 。
+
+## 代码
+
+```go
+package leetcode
+
+func findKthPositive(arr []int, k int) int {
+ positive, index := 1, 0
+ for index < len(arr) {
+ if arr[index] != positive {
+ k--
+ } else {
+ index++
+ }
+ if k == 0 {
+ break
+ }
+ positive++
+ }
+ if k != 0 {
+ positive += k - 1
+ }
+ return positive
+}
+```
\ No newline at end of file
diff --git a/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String.go b/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String.go
new file mode 100644
index 00000000..8d81e495
--- /dev/null
+++ b/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String.go
@@ -0,0 +1,38 @@
+package leetcode
+
+func numWays(s string) int {
+ ones := 0
+ for _, c := range s {
+ if c == '1' {
+ ones++
+ }
+ }
+ if ones%3 != 0 {
+ return 0
+ }
+ if ones == 0 {
+ return (len(s) - 1) * (len(s) - 2) / 2 % 1000000007
+ }
+ N, a, b, c, d, count := ones/3, 0, 0, 0, 0, 0
+ for i, letter := range s {
+ if letter == '0' {
+ continue
+ }
+ if letter == '1' {
+ count++
+ }
+ if count == N {
+ a = i
+ }
+ if count == N+1 {
+ b = i
+ }
+ if count == 2*N {
+ c = i
+ }
+ if count == 2*N+1 {
+ d = i
+ }
+ }
+ return (b - a) * (d - c) % 1000000007
+}
diff --git a/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String_test.go b/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String_test.go
new file mode 100644
index 00000000..36719145
--- /dev/null
+++ b/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String_test.go
@@ -0,0 +1,57 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1573 struct {
+ para1573
+ ans1573
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1573 struct {
+ s string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1573 struct {
+ one int
+}
+
+func Test_Problem1573(t *testing.T) {
+
+ qs := []question1573{
+
+ {
+ para1573{"10101"},
+ ans1573{4},
+ },
+
+ {
+ para1573{"1001"},
+ ans1573{0},
+ },
+
+ {
+ para1573{"0000"},
+ ans1573{3},
+ },
+
+ {
+ para1573{"100100010100110"},
+ ans1573{12},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1573------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1573, q.para1573
+ fmt.Printf("【input】:%v 【output】:%v \n", p, numWays(p.s))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1573.Number-of-Ways-to-Split-a-String/README.md b/leetcode/1573.Number-of-Ways-to-Split-a-String/README.md
new file mode 100644
index 00000000..6b8ac226
--- /dev/null
+++ b/leetcode/1573.Number-of-Ways-to-Split-a-String/README.md
@@ -0,0 +1,108 @@
+# [1573. Number of Ways to Split a String](https://leetcode.com/problems/number-of-ways-to-split-a-string/)
+
+
+## 题目
+
+Given a binary string `s` (a string consisting only of '0's and '1's), we can split `s` into 3 **non-empty** strings s1, s2, s3 (s1+ s2+ s3 = s).
+
+Return the number of ways `s` can be split such that the number of characters '1' is the same in s1, s2, and s3.
+
+Since the answer may be too large, return it modulo 10^9 + 7.
+
+**Example 1:**
+
+```
+Input: s = "10101"
+Output: 4
+Explanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.
+"1|010|1"
+"1|01|01"
+"10|10|1"
+"10|1|01"
+
+```
+
+**Example 2:**
+
+```
+Input: s = "1001"
+Output: 0
+
+```
+
+**Example 3:**
+
+```
+Input: s = "0000"
+Output: 3
+Explanation: There are three ways to split s in 3 parts.
+"0|0|00"
+"0|00|0"
+"00|0|0"
+
+```
+
+**Example 4:**
+
+```
+Input: s = "100100010100110"
+Output: 12
+
+```
+
+**Constraints:**
+
+- `3 <= s.length <= 10^5`
+- `s[i]` is `'0'` or `'1'`.
+
+## 题目大意
+
+给你一个二进制串 s (一个只包含 0 和 1 的字符串),我们可以将 s 分割成 3 个 非空 字符串 s1, s2, s3 (s1 + s2 + s3 = s)。请你返回分割 s 的方案数,满足 s1,s2 和 s3 中字符 '1' 的数目相同。由于答案可能很大,请将它对 10^9 + 7 取余后返回。
+
+## 解题思路
+
+- 这一题是考察的排列组合的知识。根据题意,如果 1 的个数不是 3 的倍数,直接返回 -1。如果字符串里面没有 1,那么切分的方案就是组合,在 n-1 个字母里面选出 2 个位置。利用组合的计算方法,组合数是 (n-1) * (n-2) / 2 。
+- 剩下的是 3 的倍数的情况。在字符串中选 2 个位置隔成 3 段。从第一段最后一个 1 到第二段第一个 1 之间的 0 的个数为 m1,从第二段最后一个 1 到第三段第一个 1 之间的 0 的个数为 m2。利用乘法原理,方案数为 m1 * m2。
+
+## 代码
+
+```go
+package leetcode
+
+func numWays(s string) int {
+ ones := 0
+ for _, c := range s {
+ if c == '1' {
+ ones++
+ }
+ }
+ if ones%3 != 0 {
+ return 0
+ }
+ if ones == 0 {
+ return (len(s) - 1) * (len(s) - 2) / 2 % 1000000007
+ }
+ N, a, b, c, d, count := ones/3, 0, 0, 0, 0, 0
+ for i, letter := range s {
+ if letter == '0' {
+ continue
+ }
+ if letter == '1' {
+ count++
+ }
+ if count == N {
+ a = i
+ }
+ if count == N+1 {
+ b = i
+ }
+ if count == 2*N {
+ c = i
+ }
+ if count == 2*N+1 {
+ d = i
+ }
+ }
+ return (b - a) * (d - c) % 1000000007
+}
+```
\ No newline at end of file
diff --git a/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation.go b/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation.go
new file mode 100644
index 00000000..384022e2
--- /dev/null
+++ b/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation.go
@@ -0,0 +1,26 @@
+package leetcode
+
+func canFormArray(arr []int, pieces [][]int) bool {
+ arrMap := map[int]int{}
+ for i, v := range arr {
+ arrMap[v] = i
+ }
+ for i := 0; i < len(pieces); i++ {
+ order := -1
+ for j := 0; j < len(pieces[i]); j++ {
+ if _, ok := arrMap[pieces[i][j]]; !ok {
+ return false
+ }
+ if order == -1 {
+ order = arrMap[pieces[i][j]]
+ } else {
+ if arrMap[pieces[i][j]] == order+1 {
+ order = arrMap[pieces[i][j]]
+ } else {
+ return false
+ }
+ }
+ }
+ }
+ return true
+}
diff --git a/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation_test.go b/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation_test.go
new file mode 100644
index 00000000..39b3a717
--- /dev/null
+++ b/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation_test.go
@@ -0,0 +1,63 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1640 struct {
+ para1640
+ ans1640
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1640 struct {
+ arr []int
+ pieces [][]int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1640 struct {
+ one bool
+}
+
+func Test_Problem1640(t *testing.T) {
+
+ qs := []question1640{
+
+ {
+ para1640{[]int{85}, [][]int{{85}}},
+ ans1640{true},
+ },
+
+ {
+ para1640{[]int{15, 88}, [][]int{{88}, {15}}},
+ ans1640{true},
+ },
+
+ {
+ para1640{[]int{49, 18, 16}, [][]int{{16, 18, 49}}},
+ ans1640{false},
+ },
+
+ {
+ para1640{[]int{91, 4, 64, 78}, [][]int{{78}, {4, 64}, {91}}},
+ ans1640{true},
+ },
+
+ {
+ para1640{[]int{1, 3, 5, 7}, [][]int{{2, 4, 6, 8}}},
+ ans1640{false},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1640------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1640, q.para1640
+ fmt.Printf("【input】:%v 【output】:%v \n", p, canFormArray(p.arr, p.pieces))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1640.Check-Array-Formation-Through-Concatenation/README.md b/leetcode/1640.Check-Array-Formation-Through-Concatenation/README.md
new file mode 100644
index 00000000..86498177
--- /dev/null
+++ b/leetcode/1640.Check-Array-Formation-Through-Concatenation/README.md
@@ -0,0 +1,95 @@
+# [1640. Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)
+
+
+## 题目
+
+You are given an array of **distinct** integers `arr` and an array of integer arrays `pieces`, where the integers in `pieces` are **distinct**. Your goal is to form `arr` by concatenating the arrays in `pieces` **in any order**. However, you are **not** allowed to reorder the integers in each array `pieces[i]`.
+
+Return `true` *if it is possible to form the array* `arr` *from* `pieces`. Otherwise, return `false`.
+
+**Example 1:**
+
+```
+Input: arr = [85], pieces = [[85]]
+Output: true
+```
+
+**Example 2:**
+
+```
+Input: arr = [15,88], pieces = [[88],[15]]
+Output: true
+Explanation: Concatenate [15] then [88]
+```
+
+**Example 3:**
+
+```
+Input: arr = [49,18,16], pieces = [[16,18,49]]
+Output: false
+Explanation: Even though the numbers match, we cannot reorder pieces[0].
+```
+
+**Example 4:**
+
+```
+Input: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]
+Output: true
+Explanation: Concatenate [91] then [4,64] then [78]
+```
+
+**Example 5:**
+
+```
+Input: arr = [1,3,5,7], pieces = [[2,4,6,8]]
+Output: false
+
+```
+
+**Constraints:**
+
+- `1 <= pieces.length <= arr.length <= 100`
+- `sum(pieces[i].length) == arr.length`
+- `1 <= pieces[i].length <= arr.length`
+- `1 <= arr[i], pieces[i][j] <= 100`
+- The integers in `arr` are **distinct**.
+- The integers in `pieces` are **distinct** (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).
+
+## 题目大意
+
+给你一个整数数组 arr ,数组中的每个整数 互不相同 。另有一个由整数数组构成的数组 pieces,其中的整数也 互不相同 。请你以 任意顺序 连接 pieces 中的数组以形成 arr 。但是,不允许 对每个数组 pieces[i] 中的整数重新排序。如果可以连接 pieces 中的数组形成 arr ,返回 true ;否则,返回 false 。
+
+## 解题思路
+
+- 简单题。题目保证了 arr 中的元素唯一,所以可以用 map 把每个元素的 index 存起来,方便查找。遍历 pieces 数组,在每个一维数组中判断元素顺序是否和原 arr 元素相对顺序一致。这个时候就用 map 查找,如果顺序是一一相连的,那么就是正确的。有一个顺序不是一一相连,或者出现了 arr 不存在的元素,都返回 false。
+
+## 代码
+
+```go
+package leetcode
+
+func canFormArray(arr []int, pieces [][]int) bool {
+ arrMap := map[int]int{}
+ for i, v := range arr {
+ arrMap[v] = i
+ }
+ for i := 0; i < len(pieces); i++ {
+ order := -1
+ for j := 0; j < len(pieces[i]); j++ {
+ if _, ok := arrMap[pieces[i][j]]; !ok {
+ return false
+ }
+ if order == -1 {
+ order = arrMap[pieces[i][j]]
+ } else {
+ if arrMap[pieces[i][j]] == order+1 {
+ order = arrMap[pieces[i][j]]
+ } else {
+ return false
+ }
+ }
+ }
+ }
+ return true
+}
+```
\ No newline at end of file
diff --git a/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings.go b/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings.go
new file mode 100644
index 00000000..be2ec59d
--- /dev/null
+++ b/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings.go
@@ -0,0 +1,35 @@
+package leetcode
+
+// 解法一 打表
+func countVowelStrings(n int) int {
+ res := []int{1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465, 35960, 40920, 46376, 52360, 58905, 66045, 73815, 82251, 91390, 101270, 111930, 123410, 135751, 148995, 163185, 178365, 194580, 211876, 230300, 249900, 270725, 292825, 316251}
+ return res[n]
+}
+
+func makeTable() []int {
+ res, array := 0, []int{}
+ for i := 0; i < 51; i++ {
+ countVowelStringsDFS(i, 0, []string{}, []string{"a", "e", "i", "o", "u"}, &res)
+ array = append(array, res)
+ res = 0
+ }
+ return array
+}
+
+func countVowelStringsDFS(n, index int, cur []string, vowels []string, res *int) {
+ vowels = vowels[index:]
+ if len(cur) == n {
+ (*res)++
+ return
+ }
+ for i := 0; i < len(vowels); i++ {
+ cur = append(cur, vowels[i])
+ countVowelStringsDFS(n, i, cur, vowels, res)
+ cur = cur[:len(cur)-1]
+ }
+}
+
+// 解法二 数学方法 —— 组合
+func countVowelStrings1(n int) int {
+ return (n + 1) * (n + 2) * (n + 3) * (n + 4) / 24
+}
diff --git a/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings_test.go b/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings_test.go
new file mode 100644
index 00000000..081ffbcd
--- /dev/null
+++ b/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1641 struct {
+ para1641
+ ans1641
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1641 struct {
+ n int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1641 struct {
+ one int
+}
+
+func Test_Problem1641(t *testing.T) {
+
+ qs := []question1641{
+
+ {
+ para1641{1},
+ ans1641{5},
+ },
+
+ {
+ para1641{2},
+ ans1641{15},
+ },
+
+ {
+ para1641{33},
+ ans1641{66045},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1641------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1641, q.para1641
+ fmt.Printf("【input】:%v 【output】:%v \n", p, countVowelStrings(p.n))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1641.Count-Sorted-Vowel-Strings/README.md b/leetcode/1641.Count-Sorted-Vowel-Strings/README.md
new file mode 100644
index 00000000..8da3acfd
--- /dev/null
+++ b/leetcode/1641.Count-Sorted-Vowel-Strings/README.md
@@ -0,0 +1,90 @@
+# [1641. Count Sorted Vowel Strings](https://leetcode.com/problems/count-sorted-vowel-strings/)
+
+
+## 题目
+
+Given an integer `n`, return *the number of strings of length* `n` *that consist only of vowels (*`a`*,* `e`*,* `i`*,* `o`*,* `u`*) and are **lexicographically sorted**.*
+
+A string `s` is **lexicographically sorted** if for all valid `i`, `s[i]` is the same as or comes before `s[i+1]` in the alphabet.
+
+**Example 1:**
+
+```
+Input: n = 1
+Output: 5
+Explanation: The 5 sorted strings that consist of vowels only are ["a","e","i","o","u"].
+```
+
+**Example 2:**
+
+```
+Input: n = 2
+Output: 15
+Explanation: The 15 sorted strings that consist of vowels only are
+["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"].
+Note that "ea" is not a valid string since 'e' comes after 'a' in the alphabet.
+
+```
+
+**Example 3:**
+
+```
+Input: n = 33
+Output: 66045
+
+```
+
+**Constraints:**
+
+- `1 <= n <= 50`
+
+## 题目大意
+
+给你一个整数 n,请返回长度为 n 、仅由元音 (a, e, i, o, u) 组成且按 字典序排列 的字符串数量。
+
+字符串 s 按 字典序排列 需要满足:对于所有有效的 i,s[i] 在字母表中的位置总是与 s[i+1] 相同或在 s[i+1] 之前。
+
+## 解题思路
+
+- 题目给的数据量并不大,第一个思路是利用 DFS 遍历打表法。时间复杂度 O(1),空间复杂度 O(1)。
+- 第二个思路是利用数学中的组合公式计算结果。题目等价于假设现在有 n 个字母,要求取 4 次球(可以选择不取)将字母分为 5 堆,问有几种取法。确定了取法以后,`a`,`e`,`i`,`o`,`u`,每个字母的个数就确定了,据题意要求按照字母序排序,那么最终字符串也就确定了。现在关注解决这个组合问题就可以了。把问题再转化一次,等价于,有 n+4 个字母,取 4 次,问有几种取法。+4 代表 4 个空操作,取走它们意味着不取。根据组合的数学定义,答案为 C(n+4,4)。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 打表
+func countVowelStrings(n int) int {
+ res := []int{1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465, 35960, 40920, 46376, 52360, 58905, 66045, 73815, 82251, 91390, 101270, 111930, 123410, 135751, 148995, 163185, 178365, 194580, 211876, 230300, 249900, 270725, 292825, 316251}
+ return res[n]
+}
+
+func makeTable() []int {
+ res, array := 0, []int{}
+ for i := 0; i < 51; i++ {
+ countVowelStringsDFS(i, 0, []string{}, []string{"a", "e", "i", "o", "u"}, &res)
+ array = append(array, res)
+ res = 0
+ }
+ return array
+}
+
+func countVowelStringsDFS(n, index int, cur []string, vowels []string, res *int) {
+ vowels = vowels[index:]
+ if len(cur) == n {
+ (*res)++
+ return
+ }
+ for i := 0; i < len(vowels); i++ {
+ cur = append(cur, vowels[i])
+ countVowelStringsDFS(n, i, cur, vowels, res)
+ cur = cur[:len(cur)-1]
+ }
+}
+
+// 解法二 数学方法 —— 组合
+func countVowelStrings1(n int) int {
+ return (n + 1) * (n + 2) * (n + 3) * (n + 4) / 24
+}
+```
\ No newline at end of file
diff --git a/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array.go b/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array.go
new file mode 100644
index 00000000..246a1e1f
--- /dev/null
+++ b/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array.go
@@ -0,0 +1,21 @@
+package leetcode
+
+func getMaximumGenerated(n int) int {
+ if n == 0 {
+ return 0
+ }
+ nums, max := make([]int, n+1), 0
+ nums[0], nums[1] = 0, 1
+ for i := 0; i <= n; i++ {
+ if nums[i] > max {
+ max = nums[i]
+ }
+ if 2*i >= 2 && 2*i <= n {
+ nums[2*i] = nums[i]
+ }
+ if 2*i+1 >= 2 && 2*i+1 <= n {
+ nums[2*i+1] = nums[i] + nums[i+1]
+ }
+ }
+ return max
+}
diff --git a/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array_test.go b/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array_test.go
new file mode 100644
index 00000000..38472190
--- /dev/null
+++ b/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array_test.go
@@ -0,0 +1,62 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1646 struct {
+ para1646
+ ans1646
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1646 struct {
+ n int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1646 struct {
+ one int
+}
+
+func Test_Problem1646(t *testing.T) {
+
+ qs := []question1646{
+
+ {
+ para1646{7},
+ ans1646{3},
+ },
+
+ {
+ para1646{2},
+ ans1646{1},
+ },
+
+ {
+ para1646{3},
+ ans1646{2},
+ },
+
+ {
+ para1646{0},
+ ans1646{0},
+ },
+
+ {
+ para1646{1},
+ ans1646{1},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1646------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1646, q.para1646
+ fmt.Printf("【input】:%v 【output】:%v \n", p, getMaximumGenerated(p.n))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1646.Get-Maximum-in-Generated-Array/README.md b/leetcode/1646.Get-Maximum-in-Generated-Array/README.md
new file mode 100644
index 00000000..a703bba7
--- /dev/null
+++ b/leetcode/1646.Get-Maximum-in-Generated-Array/README.md
@@ -0,0 +1,96 @@
+# [1646. Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array/)
+
+
+## 题目
+
+You are given an integer `n`. An array `nums` of length `n + 1` is generated in the following way:
+
+- `nums[0] = 0`
+- `nums[1] = 1`
+- `nums[2 * i] = nums[i]` when `2 <= 2 * i <= n`
+- `nums[2 * i + 1] = nums[i] + nums[i + 1]` when `2 <= 2 * i + 1 <= n`
+
+Return *****the **maximum** integer in the array* `nums`.
+
+**Example 1:**
+
+```
+Input: n = 7
+Output: 3
+Explanation: According to the given rules:
+ nums[0] = 0
+ nums[1] = 1
+ nums[(1 * 2) = 2] = nums[1] = 1
+ nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2
+ nums[(2 * 2) = 4] = nums[2] = 1
+ nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3
+ nums[(3 * 2) = 6] = nums[3] = 2
+ nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3
+Hence, nums = [0,1,1,2,1,3,2,3], and the maximum is 3.
+
+```
+
+**Example 2:**
+
+```
+Input: n = 2
+Output: 1
+Explanation: According to the given rules, the maximum between nums[0], nums[1], and nums[2] is 1.
+
+```
+
+**Example 3:**
+
+```
+Input: n = 3
+Output: 2
+Explanation: According to the given rules, the maximum between nums[0], nums[1], nums[2], and nums[3] is 2.
+
+```
+
+**Constraints:**
+
+- `0 <= n <= 100`
+
+## 题目大意
+
+给你一个整数 n 。按下述规则生成一个长度为 n + 1 的数组 nums :
+
+- nums[0] = 0
+- nums[1] = 1
+- 当 2 <= 2 * i <= n 时,nums[2 * i] = nums[i]
+- 当 2 <= 2 * i + 1 <= n 时,nums[2 * i + 1] = nums[i] + nums[i + 1]
+
+返回生成数组 nums 中的 最大值。
+
+## 解题思路
+
+- 给出一个 n + 1 的数组,并按照生成规则生成这个数组,求出这个数组中的最大值。
+- 简单题,按照题意生成数组,边生成边记录和更新最大值即可。
+- 注意边界条件,当 n 为 0 的时候,数组里面只有一个元素 0 。
+
+## 代码
+
+```go
+package leetcode
+
+func getMaximumGenerated(n int) int {
+ if n == 0 {
+ return 0
+ }
+ nums, max := make([]int, n+1), 0
+ nums[0], nums[1] = 0, 1
+ for i := 0; i <= n; i++ {
+ if nums[i] > max {
+ max = nums[i]
+ }
+ if 2*i >= 2 && 2*i <= n {
+ nums[2*i] = nums[i]
+ }
+ if 2*i+1 >= 2 && 2*i+1 <= n {
+ nums[2*i+1] = nums[i] + nums[i+1]
+ }
+ }
+ return max
+}
+```
\ No newline at end of file
diff --git a/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique.go b/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique.go
new file mode 100644
index 00000000..30219660
--- /dev/null
+++ b/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique.go
@@ -0,0 +1,22 @@
+package leetcode
+
+import (
+ "sort"
+)
+
+func minDeletions(s string) int {
+ frequency, res := make([]int, 26), 0
+ for i := 0; i < len(s); i++ {
+ frequency[s[i]-'a']++
+ }
+ sort.Sort(sort.Reverse(sort.IntSlice(frequency)))
+ for i := 1; i <= 25; i++ {
+ if frequency[i] == frequency[i-1] && frequency[i] != 0 {
+ res++
+ frequency[i]--
+ sort.Sort(sort.Reverse(sort.IntSlice(frequency)))
+ i--
+ }
+ }
+ return res
+}
diff --git a/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique_test.go b/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique_test.go
new file mode 100644
index 00000000..3bdc2735
--- /dev/null
+++ b/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique_test.go
@@ -0,0 +1,62 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1647 struct {
+ para1647
+ ans1647
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1647 struct {
+ s string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1647 struct {
+ one int
+}
+
+func Test_Problem1647(t *testing.T) {
+
+ qs := []question1647{
+
+ {
+ para1647{"aab"},
+ ans1647{0},
+ },
+
+ {
+ para1647{"aaabbbcc"},
+ ans1647{2},
+ },
+
+ {
+ para1647{"ceabaacb"},
+ ans1647{2},
+ },
+
+ {
+ para1647{""},
+ ans1647{0},
+ },
+
+ {
+ para1647{"abcabc"},
+ ans1647{3},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1647------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1647, q.para1647
+ fmt.Printf("【input】:%v 【output】:%v \n", p, minDeletions(p.s))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/README.md b/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/README.md
new file mode 100644
index 00000000..e6b2fff8
--- /dev/null
+++ b/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/README.md
@@ -0,0 +1,89 @@
+# [1647. Minimum Deletions to Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/)
+
+
+## 题目
+
+A string `s` is called **good** if there are no two different characters in `s` that have the same **frequency**.
+
+Given a string `s`, return *the **minimum** number of characters you need to delete to make* `s` ***good**.*
+
+The **frequency** of a character in a string is the number of times it appears in the string. For example, in the string `"aab"`, the **frequency** of `'a'` is `2`, while the **frequency** of `'b'` is `1`.
+
+**Example 1:**
+
+```
+Input: s = "aab"
+Output: 0
+Explanation: s is already good.
+
+```
+
+**Example 2:**
+
+```
+Input: s = "aaabbbcc"
+Output: 2
+Explanation: You can delete two 'b's resulting in the good string "aaabcc".
+Another way it to delete one 'b' and one 'c' resulting in the good string "aaabbc".
+```
+
+**Example 3:**
+
+```
+Input: s = "ceabaacb"
+Output: 2
+Explanation: You can delete both 'c's resulting in the good string "eabaab".
+Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).
+
+```
+
+**Constraints:**
+
+- `1 <= s.length <= 105`
+- `s` contains only lowercase English letters.
+
+## 题目大意
+
+如果字符串 s 中 不存在 两个不同字符 频次 相同的情况,就称 s 是 优质字符串 。
+
+给你一个字符串 s,返回使 s 成为优质字符串需要删除的最小字符数。
+
+字符串中字符的 频次 是该字符在字符串中的出现次数。例如,在字符串 "aab" 中,'a' 的频次是 2,而 'b' 的频次是 1 。
+
+**提示:**
+
+- `1 <= s.length <= 105`
+- `s` 仅含小写英文字母
+
+## 解题思路
+
+- 给出一个字符串 s,要求输出使 s 变成“优质字符串”需要删除的最小字符数。“优质字符串”的定义是:字符串 s 中不存在频次相同的两个不同字符。
+- 首先将 26 个字母在字符串中的频次分别统计出来,然后把频次从大到小排列,从频次大的开始,依次调整:例如,假设前一个和后一个频次相等,就把前一个字符删除一个,频次减一,再次排序,如果频次还相等,继续调整,如果频次不同了,游标往后移,继续调整后面的频次。直到所有的频次都不同了,就可以输出最终结果了。
+- 这里需要注意频次为 0 的情况,即字母都被删光了。频次为 0 以后,就不需要再比较了。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "sort"
+)
+
+func minDeletions(s string) int {
+ frequency, res := make([]int, 26), 0
+ for i := 0; i < len(s); i++ {
+ frequency[s[i]-'a']++
+ }
+ sort.Sort(sort.Reverse(sort.IntSlice(frequency)))
+ for i := 1; i <= 25; i++ {
+ if frequency[i] == frequency[i-1] && frequency[i] != 0 {
+ res++
+ frequency[i]--
+ sort.Sort(sort.Reverse(sort.IntSlice(frequency)))
+ i--
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls.go b/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls.go
new file mode 100644
index 00000000..677a3699
--- /dev/null
+++ b/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls.go
@@ -0,0 +1,102 @@
+package leetcode
+
+import (
+ "container/heap"
+)
+
+// 解法一 贪心 + 二分搜索
+func maxProfit(inventory []int, orders int) int {
+ maxItem, thresholdValue, count, res, mod := 0, -1, 0, 0, 1000000007
+ for i := 0; i < len(inventory); i++ {
+ if inventory[i] > maxItem {
+ maxItem = inventory[i]
+ }
+ }
+ low, high := 0, maxItem
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ for i := 0; i < len(inventory); i++ {
+ count += max(inventory[i]-mid, 0)
+ }
+ if count <= orders {
+ thresholdValue = mid
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ count = 0
+ }
+ count = 0
+ for i := 0; i < len(inventory); i++ {
+ count += max(inventory[i]-thresholdValue, 0)
+ }
+ count = orders - count
+ for i := 0; i < len(inventory); i++ {
+ if inventory[i] >= thresholdValue {
+ if count > 0 {
+ res += (thresholdValue + inventory[i]) * (inventory[i] - thresholdValue + 1) / 2
+ count--
+ } else {
+ res += (thresholdValue + 1 + inventory[i]) * (inventory[i] - thresholdValue) / 2
+ }
+ }
+ }
+ return res % mod
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+// 解法二 优先队列,超时!
+func maxProfit_(inventory []int, orders int) int {
+ res, mod := 0, 1000000007
+ q := PriorityQueue{}
+ for i := 0; i < len(inventory); i++ {
+ heap.Push(&q, &Item{count: inventory[i]})
+ }
+ for ; orders > 0; orders-- {
+ item := heap.Pop(&q).(*Item)
+ res = (res + item.count) % mod
+ heap.Push(&q, &Item{count: item.count - 1})
+ }
+ return res
+}
+
+// Item define
+type Item struct {
+ count int
+}
+
+// A PriorityQueue implements heap.Interface and holds Items.
+type PriorityQueue []*Item
+
+func (pq PriorityQueue) Len() int {
+ return len(pq)
+}
+
+func (pq PriorityQueue) Less(i, j int) bool {
+ // 注意:因为golang中的heap是按最小堆组织的,所以count越大,Less()越小,越靠近堆顶.
+ return pq[i].count > pq[j].count
+}
+
+func (pq PriorityQueue) Swap(i, j int) {
+ pq[i], pq[j] = pq[j], pq[i]
+}
+
+// Push define
+func (pq *PriorityQueue) Push(x interface{}) {
+ item := x.(*Item)
+ *pq = append(*pq, item)
+}
+
+// Pop define
+func (pq *PriorityQueue) Pop() interface{} {
+ n := len(*pq)
+ item := (*pq)[n-1]
+ *pq = (*pq)[:n-1]
+ return item
+}
diff --git a/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls_test.go b/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls_test.go
new file mode 100644
index 00000000..b81ce0e6
--- /dev/null
+++ b/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls_test.go
@@ -0,0 +1,63 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1648 struct {
+ para1648
+ ans1648
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1648 struct {
+ inventory []int
+ orders int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1648 struct {
+ one int
+}
+
+func Test_Problem1648(t *testing.T) {
+
+ qs := []question1648{
+
+ {
+ para1648{[]int{2, 3, 3, 4, 5}, 4},
+ ans1648{16},
+ },
+
+ {
+ para1648{[]int{2, 5}, 4},
+ ans1648{14},
+ },
+
+ {
+ para1648{[]int{3, 5}, 6},
+ ans1648{19},
+ },
+
+ {
+ para1648{[]int{2, 8, 4, 10, 6}, 20},
+ ans1648{110},
+ },
+
+ {
+ para1648{[]int{1000000000}, 1000000000},
+ ans1648{21},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1648------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1648, q.para1648
+ fmt.Printf("【input】:%v 【output】:%v \n", p, maxProfit(p.inventory, p.orders))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/README.md b/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/README.md
new file mode 100644
index 00000000..bddd91b3
--- /dev/null
+++ b/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/README.md
@@ -0,0 +1,131 @@
+# [1648. Sell Diminishing-Valued Colored Balls](https://leetcode.com/problems/sell-diminishing-valued-colored-balls/)
+
+
+## 题目
+
+You have an `inventory` of different colored balls, and there is a customer that wants `orders` balls of **any** color.
+
+The customer weirdly values the colored balls. Each colored ball's value is the number of balls **of that color** you currently have in your `inventory`. For example, if you own `6` yellow balls, the customer would pay `6` for the first yellow ball. After the transaction, there are only `5` yellow balls left, so the next yellow ball is then valued at `5` (i.e., the value of the balls decreases as you sell more to the customer).
+
+You are given an integer array, `inventory`, where `inventory[i]` represents the number of balls of the `ith` color that you initially own. You are also given an integer `orders`, which represents the total number of balls that the customer wants. You can sell the balls **in any order**.
+
+Return *the **maximum** total value that you can attain after selling* `orders` *colored balls*. As the answer may be too large, return it **modulo** `109 + 7`.
+
+**Example 1:**
+
+
+
+```
+Input: inventory = [2,5], orders = 4
+Output: 14
+Explanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).
+The maximum total value is 2 + 5 + 4 + 3 = 14.
+
+```
+
+**Example 2:**
+
+```
+Input: inventory = [3,5], orders = 6
+Output: 19
+Explanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).
+The maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.
+```
+
+**Example 3:**
+
+```
+Input: inventory = [2,8,4,10,6], orders = 20
+Output: 110
+```
+
+**Example 4:**
+
+```
+Input: inventory = [1000000000], orders = 1000000000
+Output: 21
+Explanation: Sell the 1st color 1000000000 times for a total value of 500000000500000000. 500000000500000000 modulo 109 + 7 = 21.
+```
+
+**Constraints:**
+
+- `1 <= inventory.length <= 10^5`
+- `1 <= inventory[i] <= 10^9`
+- `1 <= orders <= min(sum(inventory[i]), 10^9)`
+
+## 题目大意
+
+你有一些球的库存 inventory ,里面包含着不同颜色的球。一个顾客想要 任意颜色 总数为 orders 的球。这位顾客有一种特殊的方式衡量球的价值:每个球的价值是目前剩下的 同色球 的数目。比方说还剩下 6 个黄球,那么顾客买第一个黄球的时候该黄球的价值为 6 。这笔交易以后,只剩下 5 个黄球了,所以下一个黄球的价值为 5 (也就是球的价值随着顾客购买同色球是递减的)
+
+给你整数数组 inventory ,其中 inventory[i] 表示第 i 种颜色球一开始的数目。同时给你整数 orders ,表示顾客总共想买的球数目。你可以按照 任意顺序 卖球。请你返回卖了 orders 个球以后 最大 总价值之和。由于答案可能会很大,请你返回答案对 109 + 7 取余数 的结果。
+
+提示:
+
+- 1 <= inventory.length <= 10^5
+- 1 <= inventory[i] <= 10^9
+- 1 <= orders <= min(sum(inventory[i]), 10^9)
+
+## 解题思路
+
+- 给出一个 `inventory` 数组和 `orders` 次操作,要求输出数组中前 `orders` 大个元素累加和。需要注意的是,每累加一个元素 `inventory[i]`,这个元素都会减一,下次再累加的时候,需要选取更新以后的数组的最大值。
+- 拿到这个题目以后很容易想到优先队列,建立大根堆以后,`pop` 出当前最大值 `maxItem`,累加,以后把 `maxItem` 减一再 `push` 回去。循环执行 `orders` 次以后即是最终结果。题目是这个意思,但是我们不能这么写代码,因为题目条件里面给出了 `orders` 的数据大小。orders 最大为 10^9。按照优先队列的这个方法一定会超时,时间复杂度为 O(orders⋅logn)。那就换一个思路。优先队列这个思路中,重复操作了 `orders` 次,其实在这些操作中,有一些是没有必要的废操作。这些大量的“废”操作导致了超时。试想,在 `orders` 次操作中,能否合并 `n` 个 `pop` 操作,一口气先 `pop` 掉 `n` 个前 `n` 大的数呢?这个是可行的,因为每次 `pop` 出去,元素都只会减一,这个是非常有规律的。
+- 为了接下来的描述更加清晰易懂,还需要再定义 1 个值, `thresholdValue` 为操作 `n` 次以后,当前 `inventory` 数组的最大值。关于 `thresholdValue` 的理解,这里要说明一下。 `thresholdValue` 的来源有 2 种,一种是本来数组里面就有这个值,还有一种来源是 `inventory[i]` 元素减少到了 `thresholdValue` 这个值。举个例子:原始数组是 [2,3,3,4,5],`orders` = 4,取 4 次以后,剩下的数组是 [2,2,3,3,3]。3 个 3 里面其中一个 3 就来自于 `4-1=3`,或者 `5-2=3`。
+- 用二分搜索在 [0,max(`inventory`)] 区间内找到这个 `thresholdValue` 值,能满足下列不等式的最小 `thresholdValue` 值:
+
+ $$\sum_{inventory[i]\geqslant thresholdValue}^{} \left ( inventory[i] - thresholdValue \right )\leqslant orders$$
+
+ `thresholdValue` 越小,不等式左边的值越大,随着 `thresholdValue` 的增大,不等式左边的值越来越小,直到刚刚能小于等于 `orders`。求出了 `thresholdValue` 值以后,还需要再判断有多少值等于 `thresholdValue - 1` 值了。
+
+ 
+
+- 还是举上面的例子,原始数组是 [2,3,3,4,5],`orders` = 4,我们可以求得 `thresholdValue` = 3 。`inventory[i]` > `thresholdValue` 的那部分 100% 的要取走,`thresholdValue` 就像一个水平面,突出水平面的那些都要拿走,每列的值按照等差数列求和公式计算即可。但是 `orders` - `thresholdValue` = 1,说明水平面以下还要拿走一个,即 `thresholdValue` 线下的虚线框里面的那 4 个球,还需要任意取走一个。最后总的结果是这 2 部分的总和,( ( 5 + 4 ) + 4 ) + 3 = 16 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "container/heap"
+)
+
+// 解法一 贪心 + 二分搜索
+func maxProfit(inventory []int, orders int) int {
+ maxItem, thresholdValue, count, res, mod := 0, -1, 0, 0, 1000000007
+ for i := 0; i < len(inventory); i++ {
+ if inventory[i] > maxItem {
+ maxItem = inventory[i]
+ }
+ }
+ low, high := 0, maxItem
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ for i := 0; i < len(inventory); i++ {
+ count += max(inventory[i]-mid, 0)
+ }
+ if count <= orders {
+ thresholdValue = mid
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ count = 0
+ }
+ count = 0
+ for i := 0; i < len(inventory); i++ {
+ count += max(inventory[i]-thresholdValue, 0)
+ }
+ count = orders - count
+ for i := 0; i < len(inventory); i++ {
+ if inventory[i] >= thresholdValue {
+ if count > 0 {
+ res += (thresholdValue + inventory[i]) * (inventory[i] - thresholdValue + 1) / 2
+ count--
+ } else {
+ res += (thresholdValue + 1 + inventory[i]) * (inventory[i] - thresholdValue) / 2
+ }
+ }
+ }
+ return res % mod
+}
+```
\ No newline at end of file
diff --git a/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions.go b/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions.go
new file mode 100644
index 00000000..c60b1836
--- /dev/null
+++ b/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions.go
@@ -0,0 +1,106 @@
+package leetcode
+
+import (
+ "github.com/halfrost/LeetCode-Go/template"
+ "sort"
+)
+
+// 解法一 线段树 SegmentTree
+func createSortedArray(instructions []int) int {
+ if len(instructions) == 0 {
+ return 0
+ }
+ st, res, mod := template.SegmentCountTree{}, 0, 1000000007
+ numsMap, numsArray, tmpArray := discretization1649(instructions)
+ // 初始化线段树,节点内的值都赋值为 0,即计数为 0
+ st.Init(tmpArray, func(i, j int) int {
+ return 0
+ })
+ for i := 0; i < len(instructions); i++ {
+ strictlyLessThan := st.Query(0, numsMap[instructions[i]]-1)
+ strictlyGreaterThan := st.Query(numsMap[instructions[i]]+1, numsArray[len(numsArray)-1])
+ res = (res + min(strictlyLessThan, strictlyGreaterThan)) % mod
+ st.UpdateCount(numsMap[instructions[i]])
+ }
+ return res
+}
+
+func discretization1649(instructions []int) (map[int]int, []int, []int) {
+ tmpArray, numsArray, numsMap := []int{}, []int{}, map[int]int{}
+ for i := 0; i < len(instructions); i++ {
+ numsMap[instructions[i]] = instructions[i]
+ }
+ for _, v := range numsMap {
+ numsArray = append(numsArray, v)
+ }
+ sort.Ints(numsArray)
+ for i, num := range numsArray {
+ numsMap[num] = i
+ }
+ for i := range numsArray {
+ tmpArray = append(tmpArray, i)
+ }
+ return numsMap, numsArray, tmpArray
+}
+
+func min(a int, b int) int {
+ if a > b {
+ return b
+ }
+ return a
+}
+
+// 解法二 树状数组 Binary Indexed Tree
+func createSortedArray1(instructions []int) int {
+ b := newBIT(make([]int, 100001))
+ var res int
+ cnt := map[int]int{}
+ for i, n := range instructions {
+ less := b.get(n - 1)
+ greater := i - less - cnt[n]
+ res = (res + min(less, greater)) % (1e9 + 7)
+ b.update(n, 1)
+ cnt[n]++
+ }
+
+ return res % (1e9 + 7)
+}
+
+func max(x, y int) int {
+ if x > y {
+ return x
+ }
+ return y
+}
+
+type BIT struct {
+ data []int
+}
+
+func newBIT(nums []int) *BIT {
+ data := make([]int, len(nums)+1)
+ b := &BIT{data}
+ for i, n := range nums {
+ b.update(i, n)
+ }
+
+ return b
+}
+
+func (b *BIT) update(i, num int) {
+ i++
+ for i < len(b.data) {
+ b.data[i] += num
+ i += (i & -i)
+ }
+}
+
+func (b *BIT) get(i int) int {
+ i++
+ var sum int
+ for i > 0 {
+ sum += b.data[i]
+ i -= (i & -i)
+ }
+ return sum
+}
diff --git a/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions_test.go b/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions_test.go
new file mode 100644
index 00000000..892fe14f
--- /dev/null
+++ b/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1649 struct {
+ para1649
+ ans1649
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1649 struct {
+ instructions []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1649 struct {
+ one int
+}
+
+func Test_Problem1649(t *testing.T) {
+
+ qs := []question1649{
+
+ {
+ para1649{[]int{1, 5, 6, 2}},
+ ans1649{1},
+ },
+
+ {
+ para1649{[]int{1, 2, 3, 6, 5, 4}},
+ ans1649{3},
+ },
+
+ {
+ para1649{[]int{1, 3, 3, 3, 2, 4, 2, 1, 2}},
+ ans1649{4},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1649------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1649, q.para1649
+ fmt.Printf("【input】:%v 【output】:%v \n", p, createSortedArray(p.instructions))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1649.Create-Sorted-Array-through-Instructions/README.md b/leetcode/1649.Create-Sorted-Array-through-Instructions/README.md
new file mode 100644
index 00000000..2f99c307
--- /dev/null
+++ b/leetcode/1649.Create-Sorted-Array-through-Instructions/README.md
@@ -0,0 +1,189 @@
+# [1649. Create Sorted Array through Instructions](https://leetcode.com/problems/create-sorted-array-through-instructions/)
+
+## 题目
+
+Given an integer array `instructions`, you are asked to create a sorted array from the elements in `instructions`. You start with an empty container `nums`. For each element from **left to right** in `instructions`, insert it into `nums`. The **cost** of each insertion is the **minimum** of the following:
+
+- The number of elements currently in `nums` that are **strictly less than** `instructions[i]`.
+- The number of elements currently in `nums` that are **strictly greater than** `instructions[i]`.
+
+For example, if inserting element `3` into `nums = [1,2,3,5]`, the **cost** of insertion is `min(2, 1)` (elements `1` and `2` are less than `3`, element `5` is greater than `3`) and `nums` will become `[1,2,3,3,5]`.
+
+Return *the **total cost** to insert all elements from* `instructions` *into* `nums`. Since the answer may be large, return it **modulo** `10^9 + 7`
+
+**Example 1:**
+
+```
+Input: instructions = [1,5,6,2]
+Output: 1
+Explanation: Begin with nums = [].
+Insert 1 with cost min(0, 0) = 0, now nums = [1].
+Insert 5 with cost min(1, 0) = 0, now nums = [1,5].
+Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].
+Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].
+The total cost is 0 + 0 + 0 + 1 = 1.
+```
+
+**Example 2:**
+
+```
+Input: instructions = [1,2,3,6,5,4]
+Output: 3
+Explanation: Begin with nums = [].
+Insert 1 with cost min(0, 0) = 0, now nums = [1].
+Insert 2 with cost min(1, 0) = 0, now nums = [1,2].
+Insert 3 with cost min(2, 0) = 0, now nums = [1,2,3].
+Insert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].
+Insert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].
+Insert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].
+The total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.
+```
+
+**Example 3:**
+
+```
+Input: instructions = [1,3,3,3,2,4,2,1,2]
+Output: 4
+Explanation: Begin with nums = [].
+Insert 1 with cost min(0, 0) = 0, now nums = [1].
+Insert 3 with cost min(1, 0) = 0, now nums = [1,3].
+Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3].
+Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].
+Insert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].
+Insert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].
+Insert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].
+Insert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].
+Insert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].
+The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.
+```
+
+**Constraints:**
+
+- `1 <= instructions.length <= 105`
+- `1 <= instructions[i] <= 105`
+
+## 题目大意
+
+给你一个整数数组 instructions ,你需要根据 instructions 中的元素创建一个有序数组。一开始你有一个空的数组 nums ,你需要 从左到右 遍历 instructions 中的元素,将它们依次插入 nums 数组中。每一次插入操作的 代价 是以下两者的 较小值 :
+
+- nums 中 严格小于 instructions[i] 的数字数目。
+- nums 中 严格大于 instructions[i] 的数字数目。
+
+比方说,如果要将 3 插入到 nums = [1,2,3,5] ,那么插入操作的 代价 为 min(2, 1) (元素 1 和 2 小于 3 ,元素 5 大于 3 ),插入后 nums 变成 [1,2,3,3,5] 。请你返回将 instructions 中所有元素依次插入 nums 后的 总最小代价 。由于答案会很大,请将它对 10^9 + 7 取余 后返回。
+
+## 解题思路
+
+- 给出一个数组,要求将其中的元素从头开始往另外一个空数组中插入,每次插入前,累加代价值 cost = min(**strictly less than**, **strictly greater than**)。最后输出累加值。
+- 这一题虽然是 Hard 题,但是读完题以后就可以判定这是模板题了。可以用线段树和树状数组来解决。这里简单说说线段树的思路吧,先将待插入的数组排序,获得总的区间。每次循环做 4 步:2 次 `query` 分别得到 `strictlyLessThan` 和 `strictlyGreaterThan` ,再比较出两者中的最小值累加,最后一步就是 `update`。
+- 由于题目给的数据比较大,所以建立线段树之前记得要先离散化。这一题核心代码不超过 10 行,其他的都是模板代码。具体实现见代码。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "github.com/halfrost/LeetCode-Go/template"
+ "sort"
+)
+
+// 解法一 线段树 SegmentTree
+func createSortedArray(instructions []int) int {
+ if len(instructions) == 0 {
+ return 0
+ }
+ st, res, mod := template.SegmentCountTree{}, 0, 1000000007
+ numsMap, numsArray, tmpArray := discretization1649(instructions)
+ // 初始化线段树,节点内的值都赋值为 0,即计数为 0
+ st.Init(tmpArray, func(i, j int) int {
+ return 0
+ })
+ for i := 0; i < len(instructions); i++ {
+ strictlyLessThan := st.Query(0, numsMap[instructions[i]]-1)
+ strictlyGreaterThan := st.Query(numsMap[instructions[i]]+1, numsArray[len(numsArray)-1])
+ res = (res + min(strictlyLessThan, strictlyGreaterThan)) % mod
+ st.UpdateCount(numsMap[instructions[i]])
+ }
+ return res
+}
+
+func discretization1649(instructions []int) (map[int]int, []int, []int) {
+ tmpArray, numsArray, numsMap := []int{}, []int{}, map[int]int{}
+ for i := 0; i < len(instructions); i++ {
+ numsMap[instructions[i]] = instructions[i]
+ }
+ for _, v := range numsMap {
+ numsArray = append(numsArray, v)
+ }
+ sort.Ints(numsArray)
+ for i, num := range numsArray {
+ numsMap[num] = i
+ }
+ for i := range numsArray {
+ tmpArray = append(tmpArray, i)
+ }
+ return numsMap, numsArray, tmpArray
+}
+
+func min(a int, b int) int {
+ if a > b {
+ return b
+ }
+ return a
+}
+
+// 解法二 树状数组 Binary Indexed Tree
+func createSortedArray1(instructions []int) int {
+ b := newBIT(make([]int, 100001))
+ var res int
+ cnt := map[int]int{}
+ for i, n := range instructions {
+ less := b.get(n - 1)
+ greater := i - less - cnt[n]
+ res = (res + min(less, greater)) % (1e9 + 7)
+ b.update(n, 1)
+ cnt[n]++
+ }
+
+ return res % (1e9 + 7)
+}
+
+func max(x, y int) int {
+ if x > y {
+ return x
+ }
+ return y
+}
+
+type BIT struct {
+ data []int
+}
+
+func newBIT(nums []int) *BIT {
+ data := make([]int, len(nums)+1)
+ b := &BIT{data}
+ for i, n := range nums {
+ b.update(i, n)
+ }
+
+ return b
+}
+
+func (b *BIT) update(i, num int) {
+ i++
+ for i < len(b.data) {
+ b.data[i] += num
+ i += (i & -i)
+ }
+}
+
+func (b *BIT) get(i int) int {
+ i++
+ var sum int
+ for i > 0 {
+ sum += b.data[i]
+ i -= (i & -i)
+ }
+ return sum
+}
+```
\ No newline at end of file
diff --git a/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb.go b/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb.go
new file mode 100644
index 00000000..cd0c245e
--- /dev/null
+++ b/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb.go
@@ -0,0 +1,56 @@
+package leetcode
+
+func decrypt(code []int, k int) []int {
+ if k == 0 {
+ for i := 0; i < len(code); i++ {
+ code[i] = 0
+ }
+ return code
+ }
+ count, sum, res := k, 0, make([]int, len(code))
+ if k > 0 {
+ for i := 0; i < len(code); i++ {
+ for j := i + 1; j < len(code); j++ {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count--
+ }
+ if count > 0 {
+ for j := 0; j < len(code); j++ {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count--
+ }
+ }
+ res[i] = sum
+ sum, count = 0, k
+ }
+ }
+ if k < 0 {
+ for i := 0; i < len(code); i++ {
+ for j := i - 1; j >= 0; j-- {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count++
+ }
+ if count < 0 {
+ for j := len(code) - 1; j >= 0; j-- {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count++
+ }
+ }
+ res[i] = sum
+ sum, count = 0, k
+ }
+ }
+ return res
+}
diff --git a/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb_test.go b/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb_test.go
new file mode 100644
index 00000000..87ce3aef
--- /dev/null
+++ b/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1652 struct {
+ para1652
+ ans1652
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1652 struct {
+ code []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1652 struct {
+ one []int
+}
+
+func Test_Problem1652(t *testing.T) {
+
+ qs := []question1652{
+
+ {
+ para1652{[]int{5, 7, 1, 4}, 3},
+ ans1652{[]int{12, 10, 16, 13}},
+ },
+
+ {
+ para1652{[]int{1, 2, 3, 4}, 0},
+ ans1652{[]int{0, 0, 0, 0}},
+ },
+
+ {
+ para1652{[]int{2, 4, 9, 3}, -2},
+ ans1652{[]int{12, 5, 6, 13}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1652------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1652, q.para1652
+ fmt.Printf("【input】:%v 【output】:%v \n", p, decrypt(p.code, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1652.Defuse-the-Bomb/README.md b/leetcode/1652.Defuse-the-Bomb/README.md
new file mode 100644
index 00000000..cc47f853
--- /dev/null
+++ b/leetcode/1652.Defuse-the-Bomb/README.md
@@ -0,0 +1,125 @@
+# [1652. Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)
+
+
+## 题目
+
+You have a bomb to defuse, and your time is running out! Your informer will provide you with a **circular** array `code` of length of `n` and a key `k`.
+
+To decrypt the code, you must replace every number. All the numbers are replaced **simultaneously**.
+
+- If `k > 0`, replace the `ith` number with the sum of the **next** `k` numbers.
+- If `k < 0`, replace the `ith` number with the sum of the **previous** `k` numbers.
+- If `k == 0`, replace the `ith` number with `0`.
+
+As `code` is circular, the next element of `code[n-1]` is `code[0]`, and the previous element of `code[0]` is `code[n-1]`.
+
+Given the **circular** array `code` and an integer key `k`, return *the decrypted code to defuse the bomb*!
+
+**Example 1:**
+
+```
+Input: code = [5,7,1,4], k = 3
+Output: [12,10,16,13]
+Explanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.
+```
+
+**Example 2:**
+
+```
+Input: code = [1,2,3,4], k = 0
+Output: [0,0,0,0]
+Explanation: When k is zero, the numbers are replaced by 0.
+```
+
+**Example 3:**
+
+```
+Input: code = [2,4,9,3], k = -2
+Output: [12,5,6,13]
+Explanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.
+```
+
+**Constraints:**
+
+- `n == code.length`
+- `1 <= n <= 100`
+- `1 <= code[i] <= 100`
+- `(n - 1) <= k <= n - 1`
+
+## 题目大意
+
+你有一个炸弹需要拆除,时间紧迫!你的情报员会给你一个长度为 n 的 循环 数组 code 以及一个密钥 k 。为了获得正确的密码,你需要替换掉每一个数字。所有数字会 同时 被替换。
+
+- 如果 k > 0 ,将第 i 个数字用 接下来 k 个数字之和替换。
+- 如果 k < 0 ,将第 i 个数字用 之前 k 个数字之和替换。
+- 如果 k == 0 ,将第 i 个数字用 0 替换。
+
+由于 code 是循环的, code[n-1] 下一个元素是 code[0] ,且 code[0] 前一个元素是 code[n-1] 。
+
+给你 循环 数组 code 和整数密钥 k ,请你返回解密后的结果来拆除炸弹!
+
+## 解题思路
+
+- 给出一个 code 数组,要求按照规则替换每个字母。
+- 简单题,按照题意描述循环即可。
+
+## 代码
+
+```go
+package leetcode
+
+func decrypt(code []int, k int) []int {
+ if k == 0 {
+ for i := 0; i < len(code); i++ {
+ code[i] = 0
+ }
+ return code
+ }
+ count, sum, res := k, 0, make([]int, len(code))
+ if k > 0 {
+ for i := 0; i < len(code); i++ {
+ for j := i + 1; j < len(code); j++ {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count--
+ }
+ if count > 0 {
+ for j := 0; j < len(code); j++ {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count--
+ }
+ }
+ res[i] = sum
+ sum, count = 0, k
+ }
+ }
+ if k < 0 {
+ for i := 0; i < len(code); i++ {
+ for j := i - 1; j >= 0; j-- {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count++
+ }
+ if count < 0 {
+ for j := len(code) - 1; j >= 0; j-- {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count++
+ }
+ }
+ res[i] = sum
+ sum, count = 0, k
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced.go b/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced.go
new file mode 100644
index 00000000..1d5bc988
--- /dev/null
+++ b/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced.go
@@ -0,0 +1,42 @@
+package leetcode
+
+// 解法一 DP
+func minimumDeletions(s string) int {
+ prev, res, bCount := 0, 0, 0
+ for _, c := range s {
+ if c == 'a' {
+ res = min(prev+1, bCount)
+ prev = res
+ } else {
+ bCount++
+ }
+ }
+ return res
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+// 解法二 模拟
+func minimumDeletions1(s string) int {
+ aCount, bCount, res := 0, 0, 0
+ for i := 0; i < len(s); i++ {
+ if s[i] == 'a' {
+ aCount++
+ }
+ }
+ res = aCount
+ for i := 0; i < len(s); i++ {
+ if s[i] == 'a' {
+ aCount--
+ } else {
+ bCount++
+ }
+ res = min(res, aCount+bCount)
+ }
+ return res
+}
diff --git a/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced_test.go b/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced_test.go
new file mode 100644
index 00000000..672ef5cd
--- /dev/null
+++ b/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced_test.go
@@ -0,0 +1,57 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1653 struct {
+ para1653
+ ans1653
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1653 struct {
+ s string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1653 struct {
+ one int
+}
+
+func Test_Problem1653(t *testing.T) {
+
+ qs := []question1653{
+
+ {
+ para1653{"aababbab"},
+ ans1653{2},
+ },
+
+ {
+ para1653{"bbaaaaabb"},
+ ans1653{2},
+ },
+
+ {
+ para1653{"b"},
+ ans1653{0},
+ },
+
+ {
+ para1653{"ababaaaabbbbbaaababbbbbbaaabbaababbabbbbaabbbbaabbabbabaabbbababaa"},
+ ans1653{25},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1653------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1653, q.para1653
+ fmt.Printf("【input】:%v 【output】:%v \n", p, minimumDeletions(p.s))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/README.md b/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/README.md
new file mode 100644
index 00000000..f162b23e
--- /dev/null
+++ b/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/README.md
@@ -0,0 +1,90 @@
+# [1653. Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/)
+
+
+## 题目
+
+You are given a string `s` consisting only of characters `'a'` and `'b'`.
+
+You can delete any number of characters in `s` to make `s` **balanced**. `s` is **balanced** if there is no pair of indices `(i,j)` such that `i < j` and `s[i] = 'b'` and `s[j]= 'a'`.
+
+Return *the **minimum** number of deletions needed to make* `s` ***balanced***.
+
+**Example 1:**
+
+```
+Input: s = "aababbab"
+Output: 2
+Explanation: You can either:
+Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
+Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
+```
+
+**Example 2:**
+
+```
+Input: s = "bbaaaaabb"
+Output: 2
+Explanation: The only solution is to delete the first two characters.
+```
+
+**Constraints:**
+
+- `1 <= s.length <= 105`
+- `s[i]` is `'a'` or `'b'`.
+
+## 题目大意
+
+给你一个字符串 s ,它仅包含字符 'a' 和 'b' 。你可以删除 s 中任意数目的字符,使得 s 平衡 。我们称 s 平衡的 当不存在下标对 (i,j) 满足 i < j 且 s[i] = 'b' 同时 s[j]= 'a' 。请你返回使 s 平衡 的 最少 删除次数。
+
+## 解题思路
+
+- 给定一个字符串,要求删除最少次数,使得字母 a 都排在字母 b 的前面。
+- 很容易想到的一个解题思路是 DP。定义 `dp[i]` 为字符串下标 [ 0, i ] 这个区间内使得字符串平衡的最少删除次数。当 `s[i] == 'a'` 的时候,有 2 种情况,一种是 `s[i]` 前面全是 `[aa……aa]` 的情况,这个时候只需要把其中的所有的字母 `b` 删除即可。还有一种情况是 `s[i]` 前面有字母 `a` 也有字母 `b`,即 `[aaa……abb……b]`,这种情况就需要考虑 `dp[i-1]` 了。当前字母是 `a`,那么肯定要删除字母 `a`,来维持前面有一段字母 `b` 的情况。当 `s[i] == 'b'` 的时候,不管是 `[aa……aa]` 这种情况,还是 `[aaa……abb……b]` 这种情况,当前字母 `b` 都可以直接附加在后面,也能保证整个字符串是平衡的。所以状态转移方程为 `dp[i+1] = min(dp[i] + 1, bCount), s[i] == 'a'`,`dp[i+1] = dp[i], s[i] == 'b'`。最终答案存在 `dp[n]` 中。由于前后项的递推关系中只用到一次前一项,所以我们还可以优化一下空间,用一个变量保存前一项的结果。优化以后的代码见解法一。
+- 这一题还有一个模拟的思路。题目要求找到最小删除字数,那么就是要找到一个“临界点”,在这个临界点的左边删除所有的字母 b,在这个临界点的右边删除所有的字母 a。在所有的“临界点”中找到删除最少的次数。代码实现见解法二。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 DP
+func minimumDeletions(s string) int {
+ prev, res, bCount := 0, 0, 0
+ for _, c := range s {
+ if c == 'a' {
+ res = min(prev+1, bCount)
+ prev = res
+ } else {
+ bCount++
+ }
+ }
+ return res
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+// 解法二 模拟
+func minimumDeletions1(s string) int {
+ aCount, bCount, res := 0, 0, 0
+ for i := 0; i < len(s); i++ {
+ if s[i] == 'a' {
+ aCount++
+ }
+ }
+ res = aCount
+ for i := 0; i < len(s); i++ {
+ if s[i] == 'a' {
+ aCount--
+ } else {
+ bCount++
+ }
+ res = min(res, aCount+bCount)
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home.go b/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home.go
new file mode 100644
index 00000000..fcfda83b
--- /dev/null
+++ b/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home.go
@@ -0,0 +1,29 @@
+package leetcode
+
+func minimumJumps(forbidden []int, a int, b int, x int) int {
+ visited := make([]bool, 6000)
+ for i := range forbidden {
+ visited[forbidden[i]] = true
+ }
+ queue, res := [][2]int{{0, 0}}, -1
+ for len(queue) > 0 {
+ length := len(queue)
+ res++
+ for i := 0; i < length; i++ {
+ cur, isBack := queue[i][0], queue[i][1]
+ if cur == x {
+ return res
+ }
+ if isBack == 0 && cur-b > 0 && !visited[cur-b] {
+ visited[cur-b] = true
+ queue = append(queue, [2]int{cur - b, 1})
+ }
+ if cur+a < len(visited) && !visited[cur+a] {
+ visited[cur+a] = true
+ queue = append(queue, [2]int{cur + a, 0})
+ }
+ }
+ queue = queue[length:]
+ }
+ return -1
+}
diff --git a/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home_test.go b/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home_test.go
new file mode 100644
index 00000000..b08d6b74
--- /dev/null
+++ b/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home_test.go
@@ -0,0 +1,60 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1654 struct {
+ para1654
+ ans1654
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1654 struct {
+ forbidden []int
+ a int
+ b int
+ x int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1654 struct {
+ one int
+}
+
+func Test_Problem1654(t *testing.T) {
+
+ qs := []question1654{
+
+ {
+ para1654{[]int{14, 4, 18, 1, 15}, 3, 15, 9},
+ ans1654{3},
+ },
+
+ {
+ para1654{[]int{8, 3, 16, 6, 12, 20}, 15, 13, 11},
+ ans1654{-1},
+ },
+
+ {
+ para1654{[]int{1, 6, 2, 14, 5, 17, 4}, 16, 9, 7},
+ ans1654{2},
+ },
+
+ {
+ para1654{[]int{1998}, 1999, 2000, 2000},
+ ans1654{3998},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1654------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1654, q.para1654
+ fmt.Printf("【input】:%v 【output】:%v \n", p, minimumJumps(p.forbidden, p.a, p.b, p.x))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1654.Minimum-Jumps-to-Reach-Home/README.md b/leetcode/1654.Minimum-Jumps-to-Reach-Home/README.md
new file mode 100644
index 00000000..790c9cf3
--- /dev/null
+++ b/leetcode/1654.Minimum-Jumps-to-Reach-Home/README.md
@@ -0,0 +1,101 @@
+# [1654. Minimum Jumps to Reach Home](https://leetcode.com/problems/minimum-jumps-to-reach-home/)
+
+
+## 题目
+
+A certain bug's home is on the x-axis at position `x`. Help them get there from position `0`.
+
+The bug jumps according to the following rules:
+
+- It can jump exactly `a` positions **forward** (to the right).
+- It can jump exactly `b` positions **backward** (to the left).
+- It cannot jump backward twice in a row.
+- It cannot jump to any `forbidden` positions.
+
+The bug may jump forward **beyond** its home, but it **cannot jump** to positions numbered with **negative** integers.
+
+Given an array of integers `forbidden`, where `forbidden[i]` means that the bug cannot jump to the position `forbidden[i]`, and integers `a`, `b`, and `x`, return *the minimum number of jumps needed for the bug to reach its home*. If there is no possible sequence of jumps that lands the bug on position `x`, return `1.`
+
+**Example 1:**
+
+```
+Input: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9
+Output: 3
+Explanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.
+```
+
+**Example 2:**
+
+```
+Input: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11
+Output: -1
+```
+
+**Example 3:**
+
+```
+Input: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7
+Output: 2
+Explanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.
+
+```
+
+**Constraints:**
+
+- `1 <= forbidden.length <= 1000`
+- `1 <= a, b, forbidden[i] <= 2000`
+- `0 <= x <= 2000`
+- All the elements in `forbidden` are distinct.
+- Position `x` is not forbidden.
+
+## 题目大意
+
+有一只跳蚤的家在数轴上的位置 x 处。请你帮助它从位置 0 出发,到达它的家。
+
+跳蚤跳跃的规则如下:
+
+- 它可以 往前 跳恰好 a 个位置(即往右跳)。
+- 它可以 往后 跳恰好 b 个位置(即往左跳)。
+- 它不能 连续 往后跳 2 次。
+- 它不能跳到任何 forbidden 数组中的位置。
+
+跳蚤可以往前跳 超过 它的家的位置,但是它 不能跳到负整数 的位置。给你一个整数数组 forbidden ,其中 forbidden[i] 是跳蚤不能跳到的位置,同时给你整数 a, b 和 x ,请你返回跳蚤到家的最少跳跃次数。如果没有恰好到达 x 的可行方案,请你返回 -1 。
+
+## 解题思路
+
+- 给出坐标 x ,可以往前跳的步长 a,往后跳的步长 b。要求输出能跳回家的最少跳跃次数。
+- 求最少跳跃次数,思路用 BFS 求解,最先到达坐标 x 的方案即是最少跳跃次数。对`forbidden` 的处理是把记忆化数组里面把他们标记为 true。禁止连续往后跳 2 次的限制,要求我们在 BFS 入队的时候再记录一下跳跃方向,每次往后跳的时候判断前一跳是否是往后跳,如果是往后跳,此次就不能往后跳了。
+
+## 代码
+
+```go
+package leetcode
+
+func minimumJumps(forbidden []int, a int, b int, x int) int {
+ visited := make([]bool, 6000)
+ for i := range forbidden {
+ visited[forbidden[i]] = true
+ }
+ queue, res := [][2]int{{0, 0}}, -1
+ for len(queue) > 0 {
+ length := len(queue)
+ res++
+ for i := 0; i < length; i++ {
+ cur, isBack := queue[i][0], queue[i][1]
+ if cur == x {
+ return res
+ }
+ if isBack == 0 && cur-b > 0 && !visited[cur-b] {
+ visited[cur-b] = true
+ queue = append(queue, [2]int{cur - b, 1})
+ }
+ if cur+a < len(visited) && !visited[cur+a] {
+ visited[cur+a] = true
+ queue = append(queue, [2]int{cur + a, 0})
+ }
+ }
+ queue = queue[length:]
+ }
+ return -1
+}
+```
\ No newline at end of file
diff --git a/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers.go b/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers.go
new file mode 100644
index 00000000..f0f57da2
--- /dev/null
+++ b/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers.go
@@ -0,0 +1,30 @@
+package leetcode
+
+func canDistribute(nums []int, quantity []int) bool {
+ freq := make(map[int]int)
+ for _, n := range nums {
+ freq[n]++
+ }
+ return dfs(freq, quantity)
+}
+
+func dfs(freq map[int]int, quantity []int) bool {
+ if len(quantity) == 0 {
+ return true
+ }
+ visited := make(map[int]bool)
+ for i := range freq {
+ if visited[freq[i]] {
+ continue
+ }
+ visited[freq[i]] = true
+ if freq[i] >= quantity[0] {
+ freq[i] -= quantity[0]
+ if dfs(freq, quantity[1:]) {
+ return true
+ }
+ freq[i] += quantity[0]
+ }
+ }
+ return false
+}
diff --git a/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers_test.go b/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers_test.go
new file mode 100644
index 00000000..d1c7bd26
--- /dev/null
+++ b/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers_test.go
@@ -0,0 +1,63 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1655 struct {
+ para1655
+ ans1655
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1655 struct {
+ nums []int
+ quantity []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1655 struct {
+ one bool
+}
+
+func Test_Problem1655(t *testing.T) {
+
+ qs := []question1655{
+
+ {
+ para1655{[]int{1, 2, 3, 4}, []int{2}},
+ ans1655{false},
+ },
+
+ {
+ para1655{[]int{1, 2, 3, 3}, []int{2}},
+ ans1655{true},
+ },
+
+ {
+ para1655{[]int{1, 1, 2, 2}, []int{2, 2}},
+ ans1655{true},
+ },
+
+ {
+ para1655{[]int{1, 1, 2, 3}, []int{2, 2}},
+ ans1655{false},
+ },
+
+ {
+ para1655{[]int{1, 1, 1, 1, 1}, []int{2, 3}},
+ ans1655{true},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1655------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1655, q.para1655
+ fmt.Printf("【input】:%v 【output】:%v \n", p, canDistribute(p.nums, p.quantity))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1655.Distribute-Repeating-Integers/README.md b/leetcode/1655.Distribute-Repeating-Integers/README.md
new file mode 100644
index 00000000..1c1faaed
--- /dev/null
+++ b/leetcode/1655.Distribute-Repeating-Integers/README.md
@@ -0,0 +1,112 @@
+# [1655. Distribute Repeating Integers](https://leetcode.com/problems/distribute-repeating-integers/)
+
+
+## 题目
+
+You are given an array of `n` integers, `nums`, where there are at most `50` unique values in the array. You are also given an array of `m` customer order quantities, `quantity`, where `quantity[i]` is the amount of integers the `ith` customer ordered. Determine if it is possible to distribute `nums` such that:
+
+- The `ith` customer gets **exactly** `quantity[i]` integers,
+- The integers the `ith` customer gets are **all equal**, and
+- Every customer is satisfied.
+
+Return `true` *if it is possible to distribute* `nums` *according to the above conditions*.
+
+**Example 1:**
+
+```
+Input: nums = [1,2,3,4], quantity = [2]
+Output: false
+Explanation: The 0th customer cannot be given two different integers.
+```
+
+**Example 2:**
+
+```
+Input: nums = [1,2,3,3], quantity = [2]
+Output: true
+Explanation: The 0th customer is given [3,3]. The integers [1,2] are not used.
+```
+
+**Example 3:**
+
+```
+Input: nums = [1,1,2,2], quantity = [2,2]
+Output: true
+Explanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].
+```
+
+**Example 4:**
+
+```
+Input: nums = [1,1,2,3], quantity = [2,2]
+Output: false
+Explanation: Although the 0th customer could be given [1,1], the 1st customer cannot be satisfied.
+```
+
+**Example 5:**
+
+```
+Input: nums = [1,1,1,1,1], quantity = [2,3]
+Output: true
+Explanation: The 0th customer is given [1,1], and the 1st customer is given [1,1,1].
+```
+
+**Constraints:**
+
+- `n == nums.length`
+- `1 <= n <= 105`
+- `1 <= nums[i] <= 1000`
+- `m == quantity.length`
+- `1 <= m <= 10`
+- `1 <= quantity[i] <= 105`
+- There are at most `50` unique values in `nums`.
+
+## 题目大意
+
+给你一个长度为 n 的整数数组 nums ,这个数组中至多有 50 个不同的值。同时你有 m 个顾客的订单 quantity ,其中,整数 quantity[i] 是第 i 位顾客订单的数目。请你判断是否能将 nums 中的整数分配给这些顾客,且满足:
+
+- 第 i 位顾客 恰好 有 quantity[i] 个整数。
+- 第 i 位顾客拿到的整数都是 相同的 。
+- 每位顾客都满足上述两个要求。
+
+如果你可以分配 nums 中的整数满足上面的要求,那么请返回 true ,否则返回 false 。
+
+## 解题思路
+
+- 给定一个数组 nums,订单数组 quantity,要求按照订单满足顾客的需求。如果能满足输出 true,不能满足输出 false。
+- 用 DFS 记忆化暴力搜索。代码实现不难。(不知道此题为什么是 Hard)
+
+## 代码
+
+```go
+package leetcode
+
+func canDistribute(nums []int, quantity []int) bool {
+ freq := make(map[int]int)
+ for _, n := range nums {
+ freq[n]++
+ }
+ return dfs(freq, quantity)
+}
+
+func dfs(freq map[int]int, quantity []int) bool {
+ if len(quantity) == 0 {
+ return true
+ }
+ visited := make(map[int]bool)
+ for i := range freq {
+ if visited[freq[i]] {
+ continue
+ }
+ visited[freq[i]] = true
+ if freq[i] >= quantity[0] {
+ freq[i] -= quantity[0]
+ if dfs(freq, quantity[1:]) {
+ return true
+ }
+ freq[i] += quantity[0]
+ }
+ }
+ return false
+}
+```
\ No newline at end of file
diff --git a/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream.go b/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream.go
new file mode 100644
index 00000000..bb6035d9
--- /dev/null
+++ b/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream.go
@@ -0,0 +1,37 @@
+package leetcode
+
+type OrderedStream struct {
+ ptr int
+ stream []string
+}
+
+func Constructor(n int) OrderedStream {
+ ptr, stream := 1, make([]string, n+1)
+ return OrderedStream{ptr: ptr, stream: stream}
+}
+
+func (this *OrderedStream) Insert(id int, value string) []string {
+ this.stream[id] = value
+ res := []string{}
+ if this.ptr == id || this.stream[this.ptr] != "" {
+ res = append(res, this.stream[this.ptr])
+ for i := id + 1; i < len(this.stream); i++ {
+ if this.stream[i] != "" {
+ res = append(res, this.stream[i])
+ } else {
+ this.ptr = i
+ return res
+ }
+ }
+ }
+ if len(res) > 0 {
+ return res
+ }
+ return []string{}
+}
+
+/**
+ * Your OrderedStream object will be instantiated and called as such:
+ * obj := Constructor(n);
+ * param_1 := obj.Insert(id,value);
+ */
diff --git a/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream_test.go b/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream_test.go
new file mode 100644
index 00000000..870fc070
--- /dev/null
+++ b/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream_test.go
@@ -0,0 +1,21 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+func Test_Problem1656(t *testing.T) {
+ obj := Constructor(5)
+ fmt.Printf("obj = %v\n", obj)
+ param1 := obj.Insert(3, "ccccc")
+ fmt.Printf("param_1 = %v obj = %v\n", param1, obj)
+ param1 = obj.Insert(1, "aaaaa")
+ fmt.Printf("param_1 = %v obj = %v\n", param1, obj)
+ param1 = obj.Insert(2, "bbbbb")
+ fmt.Printf("param_1 = %v obj = %v\n", param1, obj)
+ param1 = obj.Insert(5, "eeeee")
+ fmt.Printf("param_1 = %v obj = %v\n", param1, obj)
+ param1 = obj.Insert(4, "ddddd")
+ fmt.Printf("param_1 = %v obj = %v\n", param1, obj)
+}
diff --git a/leetcode/1656.Design-an-Ordered-Stream/README.md b/leetcode/1656.Design-an-Ordered-Stream/README.md
new file mode 100644
index 00000000..96d52e60
--- /dev/null
+++ b/leetcode/1656.Design-an-Ordered-Stream/README.md
@@ -0,0 +1,106 @@
+# [1656. Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)
+
+## 题目
+
+There is a stream of `n` `(id, value)` pairs arriving in an **arbitrary** order, where `id` is an integer between `1` and `n` and `value` is a string. No two pairs have the same `id`.
+
+Design a stream that returns the values in **increasing order of their IDs** by returning a **chunk** (list) of values after each insertion. The concatenation of all the **chunks** should result in a list of the sorted values.
+
+Implement the `OrderedStream` class:
+
+- `OrderedStream(int n)` Constructs the stream to take `n` values.
+- `String[] insert(int id, String value)` Inserts the pair `(id, value)` into the stream, then returns the **largest possible chunk** of currently inserted values that appear next in the order.
+
+**Example:**
+
+
+
+```
+Input
+["OrderedStream", "insert", "insert", "insert", "insert", "insert"]
+[[5], [3, "ccccc"], [1, "aaaaa"], [2, "bbbbb"], [5, "eeeee"], [4, "ddddd"]]
+Output
+[null, [], ["aaaaa"], ["bbbbb", "ccccc"], [], ["ddddd", "eeeee"]]
+
+Explanation
+// Note that the values ordered by ID is ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"].
+OrderedStream os = new OrderedStream(5);
+os.insert(3, "ccccc"); // Inserts (3, "ccccc"), returns [].
+os.insert(1, "aaaaa"); // Inserts (1, "aaaaa"), returns ["aaaaa"].
+os.insert(2, "bbbbb"); // Inserts (2, "bbbbb"), returns ["bbbbb", "ccccc"].
+os.insert(5, "eeeee"); // Inserts (5, "eeeee"), returns [].
+os.insert(4, "ddddd"); // Inserts (4, "ddddd"), returns ["ddddd", "eeeee"].
+// Concatentating all the chunks returned:
+// [] + ["aaaaa"] + ["bbbbb", "ccccc"] + [] + ["ddddd", "eeeee"] = ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"]
+// The resulting order is the same as the order above.
+
+```
+
+**Constraints:**
+
+- `1 <= n <= 1000`
+- `1 <= id <= n`
+- `value.length == 5`
+- `value` consists only of lowercase letters.
+- Each call to `insert` will have a unique `id.`
+- Exactly `n` calls will be made to `insert`.
+
+## 题目大意
+
+有 n 个 (id, value) 对,其中 id 是 1 到 n 之间的一个整数,value 是一个字符串。不存在 id 相同的两个 (id, value) 对。
+
+设计一个流,以 任意 顺序获取 n 个 (id, value) 对,并在多次调用时 按 id 递增的顺序 返回一些值。
+
+实现 OrderedStream 类:
+
+- OrderedStream(int n) 构造一个能接收 n 个值的流,并将当前指针 ptr 设为 1 。
+- String[] insert(int id, String value) 向流中存储新的 (id, value) 对。存储后:
+如果流存储有 id = ptr 的 (id, value) 对,则找出从 id = ptr 开始的 最长 id 连续递增序列 ,并 按顺序 返回与这些 id 关联的值的列表。然后,将 ptr 更新为最后那个 id + 1 。
+否则,返回一个空列表。
+
+## 解题思路
+
+- 设计一个具有插入操作的 Ordered Stream。insert 操作先在指定位置插入 value,然后返回当前指针 ptr 到最近一个空位置的最长连续递增字符串。如果字符串不为空,ptr 移动到非空 value 的后一个下标位置处。
+- 简单题。按照题目描述模拟即可。注意控制好 ptr 的位置。
+
+## 代码
+
+```go
+package leetcode
+
+type OrderedStream struct {
+ ptr int
+ stream []string
+}
+
+func Constructor(n int) OrderedStream {
+ ptr, stream := 1, make([]string, n+1)
+ return OrderedStream{ptr: ptr, stream: stream}
+}
+
+func (this *OrderedStream) Insert(id int, value string) []string {
+ this.stream[id] = value
+ res := []string{}
+ if this.ptr == id || this.stream[this.ptr] != "" {
+ res = append(res, this.stream[this.ptr])
+ for i := id + 1; i < len(this.stream); i++ {
+ if this.stream[i] != "" {
+ res = append(res, this.stream[i])
+ } else {
+ this.ptr = i
+ return res
+ }
+ }
+ }
+ if len(res) > 0 {
+ return res
+ }
+ return []string{}
+}
+
+/**
+ * Your OrderedStream object will be instantiated and called as such:
+ * obj := Constructor(n);
+ * param_1 := obj.Insert(id,value);
+ */
+```
\ No newline at end of file
diff --git a/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close.go b/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close.go
new file mode 100644
index 00000000..9fa3d947
--- /dev/null
+++ b/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close.go
@@ -0,0 +1,33 @@
+package leetcode
+
+import (
+ "sort"
+)
+
+func closeStrings(word1 string, word2 string) bool {
+ if len(word1) != len(word2) {
+ return false
+ }
+ freqCount1, freqCount2 := make([]int, 26), make([]int, 26)
+ for _, c := range word1 {
+ freqCount1[c-97]++
+ }
+ for _, c := range word2 {
+ freqCount2[c-97]++
+ }
+ for i := 0; i < 26; i++ {
+ if (freqCount1[i] == freqCount2[i]) ||
+ (freqCount1[i] > 0 && freqCount2[i] > 0) {
+ continue
+ }
+ return false
+ }
+ sort.Ints(freqCount1)
+ sort.Ints(freqCount2)
+ for i := 0; i < 26; i++ {
+ if freqCount1[i] != freqCount2[i] {
+ return false
+ }
+ }
+ return true
+}
diff --git a/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close_test.go b/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close_test.go
new file mode 100644
index 00000000..cfc98254
--- /dev/null
+++ b/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close_test.go
@@ -0,0 +1,68 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1657 struct {
+ para1657
+ ans1657
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1657 struct {
+ word1 string
+ word2 string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1657 struct {
+ one bool
+}
+
+func Test_Problem1657(t *testing.T) {
+
+ qs := []question1657{
+
+ {
+ para1657{"abc", "bca"},
+ ans1657{true},
+ },
+
+ {
+ para1657{"a", "aa"},
+ ans1657{false},
+ },
+
+ {
+ para1657{"cabbba", "abbccc"},
+ ans1657{true},
+ },
+
+ {
+ para1657{"cabbba", "aabbss"},
+ ans1657{false},
+ },
+
+ {
+ para1657{"uau", "ssx"},
+ ans1657{false},
+ },
+
+ {
+ para1657{"uuukuuuukkuusuususuuuukuskuusuuusuusuuuuuuk", "kssskkskkskssskksskskksssssksskksskskksksuu"},
+ ans1657{false},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1657------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1657, q.para1657
+ fmt.Printf("【input】:%v 【output】:%v \n", p, closeStrings(p.word1, p.word2))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1657.Determine-if-Two-Strings-Are-Close/README.md b/leetcode/1657.Determine-if-Two-Strings-Are-Close/README.md
new file mode 100644
index 00000000..711c758f
--- /dev/null
+++ b/leetcode/1657.Determine-if-Two-Strings-Are-Close/README.md
@@ -0,0 +1,114 @@
+# [1657. Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/)
+
+
+## 题目
+
+Two strings are considered **close** if you can attain one from the other using the following operations:
+
+- Operation 1: Swap any two **existing** characters.
+ - For example, `abcde -> aecdb`
+- Operation 2: Transform **every** occurrence of one **existing** character into another **existing** character, and do the same with the other character.
+ - For example, `aacabb -> bbcbaa` (all `a`'s turn into `b`'s, and all `b`'s turn into `a`'s)
+
+You can use the operations on either string as many times as necessary.
+
+Given two strings, `word1` and `word2`, return `true` *if* `word1` *and* `word2` *are **close**, and* `false` *otherwise.*
+
+**Example 1:**
+
+```
+Input: word1 = "abc", word2 = "bca"
+Output: true
+Explanation: You can attain word2 from word1 in 2 operations.
+Apply Operation 1: "abc" -> "acb"
+Apply Operation 1: "acb" -> "bca"
+
+```
+
+**Example 2:**
+
+```
+Input: word1 = "a", word2 = "aa"
+Output: false
+Explanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.
+
+```
+
+**Example 3:**
+
+```
+Input: word1 = "cabbba", word2 = "abbccc"
+Output: true
+Explanation: You can attain word2 from word1 in 3 operations.
+Apply Operation 1: "cabbba" -> "caabbb"
+Apply Operation 2: "caabbb" -> "baaccc"
+Apply Operation 2: "baaccc" -> "abbccc"
+
+```
+
+**Example 4:**
+
+```
+Input: word1 = "cabbba", word2 = "aabbss"
+Output: false
+Explanation: It is impossible to attain word2 from word1, or vice versa, in any amount of operations.
+
+```
+
+**Constraints:**
+
+- `1 <= word1.length, word2.length <= 105`
+- `word1` and `word2` contain only lowercase English letters.
+
+## 题目大意
+
+如果可以使用以下操作从一个字符串得到另一个字符串,则认为两个字符串 接近 :
+
+- 操作 1:交换任意两个 现有 字符。例如,abcde -> aecdb
+- 操作 2:将一个 现有 字符的每次出现转换为另一个 现有 字符,并对另一个字符执行相同的操作。例如,aacabb -> bbcbaa(所有 a 转化为 b ,而所有的 b 转换为 a )
+
+你可以根据需要对任意一个字符串多次使用这两种操作。给你两个字符串,word1 和 word2 。如果 word1 和 word2 接近 ,就返回 true ;否则,返回 false 。
+
+## 解题思路
+
+- 判断 2 个字符串是否“接近”。“接近”的定义是能否通过交换 2 个字符或者 2 个字母互换,从一个字符串变换成另外一个字符串,如果存在这样的变换,即是“接近”。
+- 先统计 2 个字符串的 26 个字母的频次,如果频次有不相同的,直接返回 false。在频次相同的情况下,再从小到大排序,再次扫描判断频次是否相同。
+- 注意几种特殊情况:频次相同,再判断字母交换是否合法存在,如果字母不存在,输出 false。例如测试文件中的 case 5 。出现频次个数相同,但是频次不同。例如测试文件中的 case 6 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "sort"
+)
+
+func closeStrings(word1 string, word2 string) bool {
+ if len(word1) != len(word2) {
+ return false
+ }
+ freqCount1, freqCount2 := make([]int, 26), make([]int, 26)
+ for _, c := range word1 {
+ freqCount1[c-97]++
+ }
+ for _, c := range word2 {
+ freqCount2[c-97]++
+ }
+ for i := 0; i < 26; i++ {
+ if (freqCount1[i] == freqCount2[i]) ||
+ (freqCount1[i] > 0 && freqCount2[i] > 0) {
+ continue
+ }
+ return false
+ }
+ sort.Ints(freqCount1)
+ sort.Ints(freqCount2)
+ for i := 0; i < 26; i++ {
+ if freqCount1[i] != freqCount2[i] {
+ return false
+ }
+ }
+ return true
+}
+```
\ No newline at end of file
diff --git a/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/1658. Minimum Operations to Reduce X to Zero.go b/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/1658. Minimum Operations to Reduce X to Zero.go
new file mode 100644
index 00000000..a0db0774
--- /dev/null
+++ b/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/1658. Minimum Operations to Reduce X to Zero.go
@@ -0,0 +1,40 @@
+package leetcode
+
+func minOperations(nums []int, x int) int {
+ total := 0
+ for _, n := range nums {
+ total += n
+ }
+ target := total - x
+ if target < 0 {
+ return -1
+ }
+ if target == 0 {
+ return len(nums)
+ }
+ left, right, sum, res := 0, 0, 0, -1
+ for right < len(nums) {
+ if sum < target {
+ sum += nums[right]
+ right++
+ }
+ for sum >= target {
+ if sum == target {
+ res = max(res, right-left)
+ }
+ sum -= nums[left]
+ left++
+ }
+ }
+ if res == -1 {
+ return -1
+ }
+ return len(nums) - res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/1658. Minimum Operations to Reduce X to Zero_test.go b/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/1658. Minimum Operations to Reduce X to Zero_test.go
new file mode 100644
index 00000000..f781c28a
--- /dev/null
+++ b/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/1658. Minimum Operations to Reduce X to Zero_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1658 struct {
+ para1658
+ ans1658
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1658 struct {
+ nums []int
+ x int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1658 struct {
+ one int
+}
+
+func Test_Problem1658(t *testing.T) {
+
+ qs := []question1658{
+
+ {
+ para1658{[]int{1, 1, 4, 2, 3}, 5},
+ ans1658{2},
+ },
+
+ {
+ para1658{[]int{5, 6, 7, 8, 9}, 4},
+ ans1658{-1},
+ },
+
+ {
+ para1658{[]int{3, 2, 20, 1, 1, 3}, 10},
+ ans1658{5},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1658------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1658, q.para1658
+ fmt.Printf("【input】:%v 【output】:%v \n", p, minOperations(p.nums, p.x))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/README.md b/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/README.md
new file mode 100644
index 00000000..3fb34d44
--- /dev/null
+++ b/leetcode/1658.Minimum-Operations-to-Reduce-X-to-Zero/README.md
@@ -0,0 +1,96 @@
+# [1658. Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/)
+
+
+## 题目
+
+You are given an integer array `nums` and an integer `x`. In one operation, you can either remove the leftmost or the rightmost element from the array `nums` and subtract its value from `x`. Note that this **modifies** the array for future operations.
+
+Return *the **minimum number** of operations to reduce* `x` *to **exactly*** `0` *if it's possible, otherwise, return* `1`.
+
+**Example 1:**
+
+```
+Input: nums = [1,1,4,2,3], x = 5
+Output: 2
+Explanation: The optimal solution is to remove the last two elements to reduce x to zero.
+
+```
+
+**Example 2:**
+
+```
+Input: nums = [5,6,7,8,9], x = 4
+Output: -1
+
+```
+
+**Example 3:**
+
+```
+Input: nums = [3,2,20,1,1,3], x = 10
+Output: 5
+Explanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.
+
+```
+
+**Constraints:**
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 104`
+- `1 <= x <= 109`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个整数 x 。每一次操作时,你应当移除数组 nums 最左边或最右边的元素,然后从 x 中减去该元素的值。请注意,需要 修改 数组以供接下来的操作使用。如果可以将 x 恰好 减到 0 ,返回 最小操作数 ;否则,返回 -1 。
+
+## 解题思路
+
+- 给定一个数组 nums 和一个整数 x,要求从数组两端分别移除一些数,使得这些数加起来正好等于整数 x,要求输出最小操作数。
+- 要求输出最小操作数,即数组两头的数字个数最少,并且加起来和正好等于整数 x。由于在数组的两头,用 2 个指针分别操作不太方便。我当时解题的时候的思路是把它变成循环数组,这样两边的指针就在一个区间内了。利用滑动窗口找到一个最小的窗口,使得窗口内的累加和等于整数 k。这个方法可行,但是代码挺多的。
+- 有没有更优美的方法呢?有的。要想两头的长度最少,也就是中间这段的长度最大。这样就转换成直接在数组上使用滑动窗口求解,累加和等于一个固定值的连续最长的子数组。
+- 和这道题类似思路的题目,209,1040(循环数组),325。强烈推荐这 3 题。
+
+## 代码
+
+```go
+package leetcode
+
+func minOperations(nums []int, x int) int {
+ total := 0
+ for _, n := range nums {
+ total += n
+ }
+ target := total - x
+ if target < 0 {
+ return -1
+ }
+ if target == 0 {
+ return len(nums)
+ }
+ left, right, sum, res := 0, 0, 0, -1
+ for right < len(nums) {
+ if sum < target {
+ sum += nums[right]
+ right++
+ }
+ for sum >= target {
+ if sum == target {
+ res = max(res, right-left)
+ }
+ sum -= nums[left]
+ left++
+ }
+ }
+ if res == -1 {
+ return -1
+ }
+ return len(nums) - res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness.go b/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness.go
new file mode 100644
index 00000000..c0b50602
--- /dev/null
+++ b/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness.go
@@ -0,0 +1,107 @@
+package leetcode
+
+import (
+ "math"
+)
+
+func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int {
+ // lineStatus 将每一行中 3 种状态进行编码,空白 - 0,内向人 - 1,外向人 - 2,每行状态用三进制表示
+ // lineStatusList[729][6] 每一行的三进制表示
+ // introvertsCountInner[729] 每一个 lineStatus 包含的内向人数
+ // extrovertsCountInner[729] 每一个 lineStatus 包含的外向人数
+ // scoreInner[729] 每一个 lineStatus 包含的行内得分(只统计 lineStatus 本身的得分,不包括它与上一行的)
+ // scoreOuter[729][729] 每一个 lineStatus 包含的行外得分
+ // dp[上一行的 lineStatus][当前处理到的行][剩余的内向人数][剩余的外向人数]
+ n3, lineStatus, introvertsCountInner, extrovertsCountInner, scoreInner, scoreOuter, lineStatusList, dp := math.Pow(3.0, float64(n)), 0, [729]int{}, [729]int{}, [729]int{}, [729][729]int{}, [729][6]int{}, [729][6][7][7]int{}
+ for i := 0; i < 729; i++ {
+ lineStatusList[i] = [6]int{}
+ }
+ for i := 0; i < 729; i++ {
+ dp[i] = [6][7][7]int{}
+ for j := 0; j < 6; j++ {
+ dp[i][j] = [7][7]int{}
+ for k := 0; k < 7; k++ {
+ dp[i][j][k] = [7]int{-1, -1, -1, -1, -1, -1, -1}
+ }
+ }
+ }
+ // 预处理
+ for lineStatus = 0; lineStatus < int(n3); lineStatus++ {
+ tmp := lineStatus
+ for i := 0; i < n; i++ {
+ lineStatusList[lineStatus][i] = tmp % 3
+ tmp /= 3
+ }
+ introvertsCountInner[lineStatus], extrovertsCountInner[lineStatus], scoreInner[lineStatus] = 0, 0, 0
+ for i := 0; i < n; i++ {
+ if lineStatusList[lineStatus][i] != 0 {
+ // 个人分数
+ if lineStatusList[lineStatus][i] == 1 {
+ introvertsCountInner[lineStatus]++
+ scoreInner[lineStatus] += 120
+ } else if lineStatusList[lineStatus][i] == 2 {
+ extrovertsCountInner[lineStatus]++
+ scoreInner[lineStatus] += 40
+ }
+ // 行内分数
+ if i-1 >= 0 {
+ scoreInner[lineStatus] += closeScore(lineStatusList[lineStatus][i], lineStatusList[lineStatus][i-1])
+ }
+ }
+ }
+ }
+ // 行外分数
+ for lineStatus0 := 0; lineStatus0 < int(n3); lineStatus0++ {
+ for lineStatus1 := 0; lineStatus1 < int(n3); lineStatus1++ {
+ scoreOuter[lineStatus0][lineStatus1] = 0
+ for i := 0; i < n; i++ {
+ scoreOuter[lineStatus0][lineStatus1] += closeScore(lineStatusList[lineStatus0][i], lineStatusList[lineStatus1][i])
+ }
+ }
+ }
+ return dfs(0, 0, introvertsCount, extrovertsCount, m, int(n3), &dp, &introvertsCountInner, &extrovertsCountInner, &scoreInner, &scoreOuter)
+}
+
+// 如果 x 和 y 相邻,需要加上的分数
+func closeScore(x, y int) int {
+ if x == 0 || y == 0 {
+ return 0
+ }
+ // 两个内向的人,每个人要 -30,一共 -60
+ if x == 1 && y == 1 {
+ return -60
+ }
+ if x == 2 && y == 2 {
+ return 40
+ }
+ return -10
+}
+
+// dfs(上一行的 lineStatus,当前处理到的行,剩余的内向人数,剩余的外向人数)
+func dfs(lineStatusLast, row, introvertsCount, extrovertsCount, m, n3 int, dp *[729][6][7][7]int, introvertsCountInner, extrovertsCountInner, scoreInner *[729]int, scoreOuter *[729][729]int) int {
+ // 边界条件:如果已经处理完,或者没有人了
+ if row == m || introvertsCount+extrovertsCount == 0 {
+ return 0
+ }
+ // 记忆化
+ if dp[lineStatusLast][row][introvertsCount][extrovertsCount] != -1 {
+ return dp[lineStatusLast][row][introvertsCount][extrovertsCount]
+ }
+ best := 0
+ for lineStatus := 0; lineStatus < n3; lineStatus++ {
+ if introvertsCountInner[lineStatus] > introvertsCount || extrovertsCountInner[lineStatus] > extrovertsCount {
+ continue
+ }
+ score := scoreInner[lineStatus] + scoreOuter[lineStatus][lineStatusLast]
+ best = max(best, score+dfs(lineStatus, row+1, introvertsCount-introvertsCountInner[lineStatus], extrovertsCount-extrovertsCountInner[lineStatus], m, n3, dp, introvertsCountInner, extrovertsCountInner, scoreInner, scoreOuter))
+ }
+ dp[lineStatusLast][row][introvertsCount][extrovertsCount] = best
+ return best
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness_test.go b/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness_test.go
new file mode 100644
index 00000000..909e36b0
--- /dev/null
+++ b/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness_test.go
@@ -0,0 +1,55 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1659 struct {
+ para1659
+ ans1659
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1659 struct {
+ m int
+ n int
+ introvertsCount int
+ extrovertsCount int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1659 struct {
+ one int
+}
+
+func Test_Problem1659(t *testing.T) {
+
+ qs := []question1659{
+
+ {
+ para1659{2, 3, 1, 2},
+ ans1659{240},
+ },
+
+ {
+ para1659{3, 1, 2, 1},
+ ans1659{260},
+ },
+
+ {
+ para1659{2, 2, 4, 0},
+ ans1659{240},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1659------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1659, q.para1659
+ fmt.Printf("【input】:%v 【output】:%v \n", p, getMaxGridHappiness(p.m, p.n, p.introvertsCount, p.extrovertsCount))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1659.Maximize-Grid-Happiness/README.md b/leetcode/1659.Maximize-Grid-Happiness/README.md
new file mode 100644
index 00000000..6f880d26
--- /dev/null
+++ b/leetcode/1659.Maximize-Grid-Happiness/README.md
@@ -0,0 +1,185 @@
+# [1659. Maximize Grid Happiness](https://leetcode.com/problems/maximize-grid-happiness/)
+
+## 题目
+
+You are given four integers, `m`, `n`, `introvertsCount`, and `extrovertsCount`. You have an `m x n` grid, and there are two types of people: introverts and extroverts. There are `introvertsCount` introverts and `extrovertsCount` extroverts.
+
+You should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you **do not** have to have all the people living in the grid.
+
+The **happiness** of each person is calculated as follows:
+
+- Introverts **start** with `120` happiness and **lose** `30` happiness for each neighbor (introvert or extrovert).
+- Extroverts **start** with `40` happiness and **gain** `20` happiness for each neighbor (introvert or extrovert).
+
+Neighbors live in the directly adjacent cells north, east, south, and west of a person's cell.
+
+The **grid happiness** is the **sum** of each person's happiness. Return *the **maximum possible grid happiness**.*
+
+**Example 1:**
+
+
+
+```
+Input: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2
+Output: 240
+Explanation: Assume the grid is 1-indexed with coordinates (row, column).
+We can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).
+- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120
+- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60
+- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60
+The grid happiness is 120 + 60 + 60 = 240.
+The above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.
+```
+
+**Example 2:**
+
+```
+Input: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1
+Output: 260
+Explanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).
+- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90
+- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80
+- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90
+The grid happiness is 90 + 80 + 90 = 260.
+```
+
+**Example 3:**
+
+```
+Input: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0
+Output: 240
+```
+
+**Constraints:**
+
+- `1 <= m, n <= 5`
+- `0 <= introvertsCount, extrovertsCount <= min(m * n, 6)`
+
+## 题目大意
+
+给你四个整数 m、n、introvertsCount 和 extrovertsCount 。有一个 m x n 网格,和两种类型的人:内向的人和外向的人。总共有 introvertsCount 个内向的人和 extrovertsCount 个外向的人。请你决定网格中应当居住多少人,并为每个人分配一个网格单元。 注意,不必 让所有人都生活在网格中。每个人的 幸福感 计算如下:
+
+- 内向的人 开始 时有 120 个幸福感,但每存在一个邻居(内向的或外向的)他都会 失去 30 个幸福感。
+- 外向的人 开始 时有 40 个幸福感,每存在一个邻居(内向的或外向的)他都会 得到 20 个幸福感。
+
+邻居是指居住在一个人所在单元的上、下、左、右四个直接相邻的单元中的其他人。网格幸福感 是每个人幸福感的 总和 。 返回 最大可能的网格幸福感 。
+
+## 解题思路
+
+- 给出 `m` x `n` 网格和两种人,要求如何安排这两种人能使得网格的得分最大。两种人有各自的初始分,相邻可能会加分也有可能减分。
+- 这一题状态很多。首先每个格子有 3 种状态,那么每一行有 3^6 = 729 种不同的状态。每行行内分数变化值可能是 -60(两个内向),+40(两个外向),-10(一个内向一个外向)。两行行间分数变化值可能是 -60(两个内向),+40(两个外向),-10(一个内向一个外向)。那么我们可以把每行的状态压缩成一个三进制,那么网格就变成了一维,每两个三进制之间的关系是行间关系,每个三进制内部还需要根据内向和外向的人数决定行内最终分数。定义 `dp[lineStatusLast][row][introvertsCount][extrovertsCount]` 代表在上一行 `row - 1` 的状态是 `lineStatusLast` 的情况下,当前枚举到了第 `row` 行,内向还有 `introvertsCount` 个人,外向还有 `extrovertsCount` 个人能获得的最大分数。状态转移方程是 `dp[lineStatusLast(row-1)][row][introvertsCount][extrovertsCount] = max{dp[lineStatusLast(row)][row+1][introvertsCount - countIC(lineStatusLast(row)) ][extrovertsCount - countEC(lineStatusLast(row)) ] + scoreInner(lineStatusLast(row)) + scoreOuter(lineStatusLast(row-1),lineStatusLast(row))}` ,这里有 2 个统计函数,`countIC` 是统计当前行状态三进制里面有多少个内向人。`countEC` 是统计当前行状态三进制里面有多少个外向人。`scoreInner` 是计算当前行状态三进制的行内分数。`scoreOuter` 是计算 `row -1` 行和 `row` 行之间的行间分数。
+- 由于这个状态转移方程的计算量是巨大的。所以需要预先初始化一些计算结果。比如把 729 中行状态分别对应的行内、行间的分数都计算好,在动态规划状态转移的时候,直接查表获取分数即可。这样我们在深搜的时候,利用 dp 的记忆化,可以大幅减少时间复杂度。
+- 题目中还提到,人数可以不用完。如果 `introvertsCount = 0`, `extrovertsCount = 0` ,即人数都用完了的情况,这时候 `dp = 0`。如果 `row = m`,即已经枚举完了所有行,那么不管剩下多少人,这一行的 `dp = 0` 。
+- 初始化的时候,注意,特殊处理 0 的情况,0 行 0 列都初始化为 -1 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math"
+)
+
+func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int {
+ // lineStatus 将每一行中 3 种状态进行编码,空白 - 0,内向人 - 1,外向人 - 2,每行状态用三进制表示
+ // lineStatusList[729][6] 每一行的三进制表示
+ // introvertsCountInner[729] 每一个 lineStatus 包含的内向人数
+ // extrovertsCountInner[729] 每一个 lineStatus 包含的外向人数
+ // scoreInner[729] 每一个 lineStatus 包含的行内得分(只统计 lineStatus 本身的得分,不包括它与上一行的)
+ // scoreOuter[729][729] 每一个 lineStatus 包含的行外得分
+ // dp[上一行的 lineStatus][当前处理到的行][剩余的内向人数][剩余的外向人数]
+ n3, lineStatus, introvertsCountInner, extrovertsCountInner, scoreInner, scoreOuter, lineStatusList, dp := math.Pow(3.0, float64(n)), 0, [729]int{}, [729]int{}, [729]int{}, [729][729]int{}, [729][6]int{}, [729][6][7][7]int{}
+ for i := 0; i < 729; i++ {
+ lineStatusList[i] = [6]int{}
+ }
+ for i := 0; i < 729; i++ {
+ dp[i] = [6][7][7]int{}
+ for j := 0; j < 6; j++ {
+ dp[i][j] = [7][7]int{}
+ for k := 0; k < 7; k++ {
+ dp[i][j][k] = [7]int{-1, -1, -1, -1, -1, -1, -1}
+ }
+ }
+ }
+ // 预处理
+ for lineStatus = 0; lineStatus < int(n3); lineStatus++ {
+ tmp := lineStatus
+ for i := 0; i < n; i++ {
+ lineStatusList[lineStatus][i] = tmp % 3
+ tmp /= 3
+ }
+ introvertsCountInner[lineStatus], extrovertsCountInner[lineStatus], scoreInner[lineStatus] = 0, 0, 0
+ for i := 0; i < n; i++ {
+ if lineStatusList[lineStatus][i] != 0 {
+ // 个人分数
+ if lineStatusList[lineStatus][i] == 1 {
+ introvertsCountInner[lineStatus]++
+ scoreInner[lineStatus] += 120
+ } else if lineStatusList[lineStatus][i] == 2 {
+ extrovertsCountInner[lineStatus]++
+ scoreInner[lineStatus] += 40
+ }
+ // 行内分数
+ if i-1 >= 0 {
+ scoreInner[lineStatus] += closeScore(lineStatusList[lineStatus][i], lineStatusList[lineStatus][i-1])
+ }
+ }
+ }
+ }
+ // 行外分数
+ for lineStatus0 := 0; lineStatus0 < int(n3); lineStatus0++ {
+ for lineStatus1 := 0; lineStatus1 < int(n3); lineStatus1++ {
+ scoreOuter[lineStatus0][lineStatus1] = 0
+ for i := 0; i < n; i++ {
+ scoreOuter[lineStatus0][lineStatus1] += closeScore(lineStatusList[lineStatus0][i], lineStatusList[lineStatus1][i])
+ }
+ }
+ }
+ return dfs(0, 0, introvertsCount, extrovertsCount, m, int(n3), &dp, &introvertsCountInner, &extrovertsCountInner, &scoreInner, &scoreOuter)
+}
+
+// 如果 x 和 y 相邻,需要加上的分数
+func closeScore(x, y int) int {
+ if x == 0 || y == 0 {
+ return 0
+ }
+ // 两个内向的人,每个人要 -30,一共 -60
+ if x == 1 && y == 1 {
+ return -60
+ }
+ if x == 2 && y == 2 {
+ return 40
+ }
+ return -10
+}
+
+// dfs(上一行的 lineStatus,当前处理到的行,剩余的内向人数,剩余的外向人数)
+func dfs(lineStatusLast, row, introvertsCount, extrovertsCount, m, n3 int, dp *[729][6][7][7]int, introvertsCountInner, extrovertsCountInner, scoreInner *[729]int, scoreOuter *[729][729]int) int {
+ // 边界条件:如果已经处理完,或者没有人了
+ if row == m || introvertsCount+extrovertsCount == 0 {
+ return 0
+ }
+ // 记忆化
+ if dp[lineStatusLast][row][introvertsCount][extrovertsCount] != -1 {
+ return dp[lineStatusLast][row][introvertsCount][extrovertsCount]
+ }
+ best := 0
+ for lineStatus := 0; lineStatus < n3; lineStatus++ {
+ if introvertsCountInner[lineStatus] > introvertsCount || extrovertsCountInner[lineStatus] > extrovertsCount {
+ continue
+ }
+ score := scoreInner[lineStatus] + scoreOuter[lineStatus][lineStatusLast]
+ best = max(best, score+dfs(lineStatus, row+1, introvertsCount-introvertsCountInner[lineStatus], extrovertsCount-extrovertsCountInner[lineStatus], m, n3, dp, introvertsCountInner, extrovertsCountInner, scoreInner, scoreOuter))
+ }
+ dp[lineStatusLast][row][introvertsCount][extrovertsCount] = best
+ return best
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent.go b/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent.go
new file mode 100644
index 00000000..f85e3b05
--- /dev/null
+++ b/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent.go
@@ -0,0 +1,12 @@
+package leetcode
+
+func arrayStringsAreEqual(word1 []string, word2 []string) bool {
+ str1, str2 := "", ""
+ for i := 0; i < len(word1); i++ {
+ str1 += word1[i]
+ }
+ for i := 0; i < len(word2); i++ {
+ str2 += word2[i]
+ }
+ return str1 == str2
+}
diff --git a/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent_test.go b/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent_test.go
new file mode 100644
index 00000000..271b0dea
--- /dev/null
+++ b/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1662 struct {
+ para1662
+ ans1662
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1662 struct {
+ word1 []string
+ word2 []string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1662 struct {
+ one bool
+}
+
+func Test_Problem1662(t *testing.T) {
+
+ qs := []question1662{
+
+ {
+ para1662{[]string{"ab", "c"}, []string{"a", "bc"}},
+ ans1662{true},
+ },
+
+ {
+ para1662{[]string{"a", "cb"}, []string{"ab", "c"}},
+ ans1662{false},
+ },
+
+ {
+ para1662{[]string{"abc", "d", "defg"}, []string{"abcddefg"}},
+ ans1662{true},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1662------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1662, q.para1662
+ fmt.Printf("【input】:%v 【output】:%v \n", p, arrayStringsAreEqual(p.word1, p.word2))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/README.md b/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/README.md
new file mode 100644
index 00000000..d1e47d01
--- /dev/null
+++ b/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/README.md
@@ -0,0 +1,65 @@
+# [1662. Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)
+
+
+## 题目
+
+Given two string arrays `word1` and `word2`, return **`true` *if the two arrays **represent** the same string, and* `false` *otherwise.*
+
+A string is **represented** by an array if the array elements concatenated **in order** forms the string.
+
+**Example 1:**
+
+```
+Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
+Output: true
+Explanation:
+word1 represents string "ab" + "c" -> "abc"
+word2 represents string "a" + "bc" -> "abc"
+The strings are the same, so return true.
+```
+
+**Example 2:**
+
+```
+Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
+Output: false
+```
+
+**Example 3:**
+
+```
+Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"]
+Output: true
+```
+
+**Constraints:**
+
+- `1 <= word1.length, word2.length <= 103`
+- `1 <= word1[i].length, word2[i].length <= 103`
+- `1 <= sum(word1[i].length), sum(word2[i].length) <= 103`
+- `word1[i]` and `word2[i]` consist of lowercase letters.
+
+## 题目大意
+
+给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。数组表示的字符串 是由数组中的所有元素 按顺序 连接形成的字符串。
+
+## 解题思路
+
+- 简单题,依次拼接 2 个数组内的字符串,然后比较 str1 和 str2 是否相同即可。
+
+## 代码
+
+```go
+package leetcode
+
+func arrayStringsAreEqual(word1 []string, word2 []string) bool {
+ str1, str2 := "", ""
+ for i := 0; i < len(word1); i++ {
+ str1 += word1[i]
+ }
+ for i := 0; i < len(word2); i++ {
+ str2 += word2[i]
+ }
+ return str1 == str2
+}
+```
\ No newline at end of file
diff --git a/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value.go b/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value.go
new file mode 100644
index 00000000..f1ae2dca
--- /dev/null
+++ b/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value.go
@@ -0,0 +1,55 @@
+package leetcode
+
+// 解法一 贪心
+func getSmallestString(n int, k int) string {
+ res := make([]rune, n)
+ for i := n - 1; i >= 0; i-- {
+ diff := k - i
+ if diff >= 26 {
+ // Need to add z
+ res[i] = 'z'
+ k = k - 26
+ } else {
+ res[i] = rune('a' + diff - 1)
+ k = k - diff
+ }
+ }
+ return string(res)
+}
+
+// 解法二 DFS
+func getSmallestString1(n int, k int) string {
+ if n == 0 {
+ return ""
+ }
+ res, c := "", []byte{}
+ findSmallestString(0, n, k, 0, c, &res)
+ return res
+}
+
+func findSmallestString(value int, length, k, index int, str []byte, res *string) {
+ if len(str) == length && value == k {
+ tmp := string(str)
+ if (*res) == "" {
+ *res = tmp
+ }
+ if tmp < *res && *res != "" {
+ *res = tmp
+ }
+ return
+ }
+ if len(str) >= index && (*res) != "" && str[index-1] > (*res)[index-1] {
+ return
+ }
+ for j := 0; j < 26; j++ {
+ if k-value > (length-len(str))*26 || value > k {
+ return
+ }
+ str = append(str, byte(int('a')+j))
+ value += j + 1
+ findSmallestString(value, length, k, index+1, str, res)
+ str = str[:len(str)-1]
+ value -= j + 1
+
+ }
+}
diff --git a/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value_test.go b/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value_test.go
new file mode 100644
index 00000000..f3c07a4c
--- /dev/null
+++ b/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1663 struct {
+ para1663
+ ans1663
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1663 struct {
+ n int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1663 struct {
+ one string
+}
+
+func Test_Problem1663(t *testing.T) {
+
+ qs := []question1663{
+
+ {
+ para1663{3, 27},
+ ans1663{"aay"},
+ },
+
+ {
+ para1663{5, 73},
+ ans1663{"aaszz"},
+ },
+
+ {
+ para1663{24, 552},
+ ans1663{"aaszz"},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1663------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1663, q.para1663
+ fmt.Printf("【input】:%v 【output】:%v \n", p, getSmallestString(p.n, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/README.md b/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/README.md
new file mode 100644
index 00000000..e0ab8917
--- /dev/null
+++ b/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/README.md
@@ -0,0 +1,104 @@
+# [1663. Smallest String With A Given Numeric Value](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/)
+
+## 题目
+
+The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on.
+
+The **numeric value** of a **string** consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string `"abe"` is equal to `1 + 2 + 5 = 8`.
+
+You are given two integers `n` and `k`. Return *the **lexicographically smallest string** with **length** equal to `n` and **numeric value** equal to `k`.*
+
+Note that a string `x` is lexicographically smaller than string `y` if `x` comes before `y` in dictionary order, that is, either `x` is a prefix of `y`, or if `i` is the first position such that `x[i] != y[i]`, then `x[i]` comes before `y[i]` in alphabetic order.
+
+**Example 1:**
+
+```
+Input: n = 3, k = 27
+Output: "aay"
+Explanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.
+```
+
+**Example 2:**
+
+```
+Input: n = 5, k = 73
+Output: "aaszz"
+```
+
+**Constraints:**
+
+- `1 <= n <= 105`
+- `n <= k <= 26 * n`
+
+## 题目大意
+
+小写字符 的 数值 是它在字母表中的位置(从 1 开始),因此 a 的数值为 1 ,b 的数值为 2 ,c 的数值为 3 ,以此类推。字符串由若干小写字符组成,字符串的数值 为各字符的数值之和。例如,字符串 "abe" 的数值等于 1 + 2 + 5 = 8 。给你两个整数 n 和 k 。返回 长度 等于 n 且 数值 等于 k 的 字典序最小 的字符串。注意,如果字符串 x 在字典排序中位于 y 之前,就认为 x 字典序比 y 小,有以下两种情况:
+
+- x 是 y 的一个前缀;
+- 如果 i 是 x[i] != y[i] 的第一个位置,且 x[i] 在字母表中的位置比 y[i] 靠前。
+
+## 解题思路
+
+- 给出 n 和 k,要求找到字符串长度为 n,字母在字母表内位置总和为 k 的最小字典序字符串。
+- 这一题笔者读完题,比赛的时候直接用 DFS 撸了一版。赛后看了时间复杂度马马虎虎,感觉还有优化的空间。DFS 会遍历出所有的解,实际上这一题只要求最小字典序,所以 DFS 剪枝的时候要加上判断字典序的判断,如果新添加进来的字母比已经保存的字符串的相应位置上的字母字典序大,那么就直接 return,这个答案一定不会是最小字典序。代码见解法二
+- 想到这里,其实 DFS 不必要,直接用 for 循环就可找到最小字典序的字符串。代码见解法一。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 贪心
+func getSmallestString(n int, k int) string {
+ res := make([]rune, n)
+ for i := n - 1; i >= 0; i-- {
+ diff := k - i
+ if diff >= 26 {
+ // Need to add z
+ res[i] = 'z'
+ k = k - 26
+ } else {
+ res[i] = rune('a' + diff - 1)
+ k = k - diff
+ }
+ }
+ return string(res)
+}
+
+// 解法二 DFS
+func getSmallestString1(n int, k int) string {
+ if n == 0 {
+ return ""
+ }
+ res, c := "", []byte{}
+ findSmallestString(0, n, k, 0, c, &res)
+ return res
+}
+
+func findSmallestString(value int, length, k, index int, str []byte, res *string) {
+ if len(str) == length && value == k {
+ tmp := string(str)
+ if (*res) == "" {
+ *res = tmp
+ }
+ if tmp < *res && *res != "" {
+ *res = tmp
+ }
+ return
+ }
+ if len(str) >= index && (*res) != "" && str[index-1] > (*res)[index-1] {
+ return
+ }
+ for j := 0; j < 26; j++ {
+ if k-value > (length-len(str))*26 || value > k {
+ return
+ }
+ str = append(str, byte(int('a')+j))
+ value += j + 1
+ findSmallestString(value, length, k, index+1, str, res)
+ str = str[:len(str)-1]
+ value -= j + 1
+
+ }
+}
+```
\ No newline at end of file
diff --git a/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array.go b/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array.go
new file mode 100644
index 00000000..c66641a0
--- /dev/null
+++ b/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array.go
@@ -0,0 +1,45 @@
+package leetcode
+
+// 解法一 超简洁写法
+func waysToMakeFair(nums []int) int {
+ sum, res := [2]int{}, 0
+ for i := 0; i < len(nums); i++ {
+ sum[i%2] += nums[i]
+ }
+ for i := 0; i < len(nums); i++ {
+ sum[i%2] -= nums[i]
+ if sum[i%2] == sum[1-(i%2)] {
+ res++
+ }
+ sum[1-(i%2)] += nums[i]
+ }
+ return res
+}
+
+// 解法二 前缀和,后缀和
+func waysToMakeFair1(nums []int) int {
+ evenPrefix, oddPrefix, evenSuffix, oddSuffix, res := 0, 0, 0, 0, 0
+ for i := 0; i < len(nums); i++ {
+ if i%2 == 0 {
+ evenSuffix += nums[i]
+ } else {
+ oddSuffix += nums[i]
+ }
+ }
+ for i := 0; i < len(nums); i++ {
+ if i%2 == 0 {
+ evenSuffix -= nums[i]
+ } else {
+ oddSuffix -= nums[i]
+ }
+ if (evenPrefix + oddSuffix) == (oddPrefix + evenSuffix) {
+ res++
+ }
+ if i%2 == 0 {
+ evenPrefix += nums[i]
+ } else {
+ oddPrefix += nums[i]
+ }
+ }
+ return res
+}
diff --git a/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array_test.go b/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array_test.go
new file mode 100644
index 00000000..670e994e
--- /dev/null
+++ b/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array_test.go
@@ -0,0 +1,57 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1664 struct {
+ para1664
+ ans1664
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1664 struct {
+ nums []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1664 struct {
+ one int
+}
+
+func Test_Problem1664(t *testing.T) {
+
+ qs := []question1664{
+
+ {
+ para1664{[]int{6, 1, 7, 4, 1}},
+ ans1664{0},
+ },
+
+ {
+ para1664{[]int{2, 1, 6, 4}},
+ ans1664{1},
+ },
+
+ {
+ para1664{[]int{1, 1, 1}},
+ ans1664{3},
+ },
+
+ {
+ para1664{[]int{1, 2, 3}},
+ ans1664{0},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1664------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1664, q.para1664
+ fmt.Printf("【input】:%v 【output】:%v \n", p, waysToMakeFair(p.nums))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1664.Ways-to-Make-a-Fair-Array/README.md b/leetcode/1664.Ways-to-Make-a-Fair-Array/README.md
new file mode 100644
index 00000000..9c40f823
--- /dev/null
+++ b/leetcode/1664.Ways-to-Make-a-Fair-Array/README.md
@@ -0,0 +1,116 @@
+# [1664. Ways to Make a Fair Array](https://leetcode.com/problems/ways-to-make-a-fair-array/)
+
+
+## 题目
+
+You are given an integer array `nums`. You can choose **exactly one** index (**0-indexed**) and remove the element. Notice that the index of the elements may change after the removal.
+
+For example, if `nums = [6,1,7,4,1]`:
+
+- Choosing to remove index `1` results in `nums = [6,7,4,1]`.
+- Choosing to remove index `2` results in `nums = [6,1,4,1]`.
+- Choosing to remove index `4` results in `nums = [6,1,7,4]`.
+
+An array is **fair** if the sum of the odd-indexed values equals the sum of the even-indexed values.
+
+Return the ***number** of indices that you could choose such that after the removal,* `nums` *is **fair**.*
+
+**Example 1:**
+
+```
+Input: nums = [2,1,6,4]
+Output: 1
+Explanation:
+Remove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.
+Remove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.
+Remove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.
+Remove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.
+There is 1 index that you can remove to make nums fair.
+```
+
+**Example 2:**
+
+```
+Input: nums = [1,1,1]
+Output: 3
+Explanation: You can remove any index and the remaining array is fair.
+```
+
+**Example 3:**
+
+```
+Input: nums = [1,2,3]
+Output: 0
+Explanation: You cannot make a fair array after removing any index.
+```
+
+**Constraints:**
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 104`
+
+## 题目大意
+
+给你一个整数数组 nums 。你需要选择 恰好 一个下标(下标从 0 开始)并删除对应的元素。请注意剩下元素的下标可能会因为删除操作而发生改变。
+
+比方说,如果 nums = [6,1,7,4,1] ,那么:
+
+- 选择删除下标 1 ,剩下的数组为 nums = [6,7,4,1] 。
+- 选择删除下标 2 ,剩下的数组为 nums = [6,1,4,1] 。
+- 选择删除下标 4 ,剩下的数组为 nums = [6,1,7,4] 。
+
+如果一个数组满足奇数下标元素的和与偶数下标元素的和相等,该数组就是一个 平衡数组 。请你返回删除操作后,剩下的数组 nums 是 平衡数组 的 方案数 。
+
+## 解题思路
+
+- 给定一个数组 nums,要求输出仅删除一个元素以后能使得整个数组平衡的方案数。平衡的定义是奇数下标元素总和等于偶数下标元素总和。
+- 这一题如果暴力解答,会超时。原因是每次删除元素以后,都重新计算奇偶数位总和比较耗时。应该利用前面计算过的累加和,推导出此次删除元素以后的情况。这样修改以后就不超时了。具体的,如果删除的是元素是奇数位,这个下标的前缀和不变,要变化的是后面的。删除元素后面,原来偶数位的总和变成了奇数位了,原来奇数位的总和变成偶数位了。删除元素后面这半段的总和可以用前缀和计算出来,奇数位的总和减去删除元素的前缀和,就得到了删除元素后面的后缀和。通过这个办法就可以得到删除元素后面的,奇数位总和,偶数位总和。注意这个后缀和是包含了删除元素的。所以最后需要判断删除元素是奇数位还是偶数位,如果是奇数位,那么在计算出来的偶数和上再减去这个删除元素;如果是偶数位,就在计算出来的奇数和上再减去这个删除元素。代码见解法二。
+- 这一题还有一种更简洁的写法,就是解法一了。通过了解法二的思考,我们可以知道,每次变换以后的操作可以抽象出来,即三步,减去一个数,判断是否相等,再加上一个数。只不过这三步在解法二中都去判断了奇偶性。如果我们不判断奇偶性,那么代码就可以写成解法一的样子。为什么可以不用管奇偶性呢?因为每次删除一个元素以后,下次再删除,奇偶就发生颠倒了,上次的奇数和到了下次就是偶数和了。想通这一点就可以把代码写成解法一的样子。
+
+## 代码
+
+```go
+// 解法一 超简洁写法
+func waysToMakeFair(nums []int) int {
+ sum, res := [2]int{}, 0
+ for i := 0; i < len(nums); i++ {
+ sum[i%2] += nums[i]
+ }
+ for i := 0; i < len(nums); i++ {
+ sum[i%2] -= nums[i]
+ if sum[i%2] == sum[1-(i%2)] {
+ res++
+ }
+ sum[1-(i%2)] += nums[i]
+ }
+ return res
+}
+
+// 解法二 前缀和,后缀和
+func waysToMakeFair1(nums []int) int {
+ evenPrefix, oddPrefix, evenSuffix, oddSuffix, res := 0, 0, 0, 0, 0
+ for i := 0; i < len(nums); i++ {
+ if i%2 == 0 {
+ evenSuffix += nums[i]
+ } else {
+ oddSuffix += nums[i]
+ }
+ }
+ for i := 0; i < len(nums); i++ {
+ if i%2 == 0 {
+ evenSuffix -= nums[i]
+ } else {
+ oddSuffix -= nums[i]
+ }
+ if (evenPrefix + oddSuffix) == (oddPrefix + evenSuffix) {
+ res++
+ }
+ if i%2 == 0 {
+ evenPrefix += nums[i]
+ } else {
+ oddPrefix += nums[i]
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks.go b/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks.go
new file mode 100644
index 00000000..f44dfcd9
--- /dev/null
+++ b/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks.go
@@ -0,0 +1,47 @@
+package leetcode
+
+import (
+ "sort"
+)
+
+func minimumEffort(tasks [][]int) int {
+ sort.Sort(Task(tasks))
+ res, cur := 0, 0
+ for _, t := range tasks {
+ if t[1] > cur {
+ res += t[1] - cur
+ cur = t[1] - t[0]
+ } else {
+ cur -= t[0]
+ }
+ }
+ return res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+// Task define
+type Task [][]int
+
+func (task Task) Len() int {
+ return len(task)
+}
+
+func (task Task) Less(i, j int) bool {
+ t1, t2 := task[i][1]-task[i][0], task[j][1]-task[j][0]
+ if t1 != t2 {
+ return t2 < t1
+ }
+ return task[j][1] < task[i][1]
+}
+
+func (task Task) Swap(i, j int) {
+ t := task[i]
+ task[i] = task[j]
+ task[j] = t
+}
diff --git a/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks_test.go b/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks_test.go
new file mode 100644
index 00000000..ce076238
--- /dev/null
+++ b/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1665 struct {
+ para1665
+ ans1665
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1665 struct {
+ tasks [][]int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1665 struct {
+ one int
+}
+
+func Test_Problem1665(t *testing.T) {
+
+ qs := []question1665{
+
+ {
+ para1665{[][]int{{1, 2}, {2, 4}, {4, 8}}},
+ ans1665{8},
+ },
+
+ {
+ para1665{[][]int{{1, 3}, {2, 4}, {10, 11}, {10, 12}, {8, 9}}},
+ ans1665{32},
+ },
+
+ {
+ para1665{[][]int{{1, 7}, {2, 8}, {3, 9}, {4, 10}, {5, 11}, {6, 12}}},
+ ans1665{27},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1665------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1665, q.para1665
+ fmt.Printf("【input】:%v 【output】:%v \n", p, minimumEffort(p.tasks))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/README.md b/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/README.md
new file mode 100644
index 00000000..c2bd57e6
--- /dev/null
+++ b/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/README.md
@@ -0,0 +1,128 @@
+# [1665. Minimum Initial Energy to Finish Tasks](https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/)
+
+## 题目
+
+You are given an array `tasks` where `tasks[i] = [actuali, minimumi]`:
+
+- `actuali` is the actual amount of energy you **spend to finish** the `ith` task.
+- `minimumi` is the minimum amount of energy you **require to begin** the `ith` task.
+
+For example, if the task is `[10, 12]` and your current energy is `11`, you cannot start this task. However, if your current energy is `13`, you can complete this task, and your energy will be `3` after finishing it.
+
+You can finish the tasks in **any order** you like.
+
+Return *the **minimum** initial amount of energy you will need* *to finish all the tasks*.
+
+**Example 1:**
+
+```
+Input: tasks = [[1,2],[2,4],[4,8]]
+Output: 8
+Explanation:
+Starting with 8 energy, we finish the tasks in the following order:
+ - 3rd task. Now energy = 8 - 4 = 4.
+ - 2nd task. Now energy = 4 - 2 = 2.
+ - 1st task. Now energy = 2 - 1 = 1.
+Notice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.
+```
+
+**Example 2:**
+
+```
+Input: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]
+Output: 32
+Explanation:
+Starting with 32 energy, we finish the tasks in the following order:
+ - 1st task. Now energy = 32 - 1 = 31.
+ - 2nd task. Now energy = 31 - 2 = 29.
+ - 3rd task. Now energy = 29 - 10 = 19.
+ - 4th task. Now energy = 19 - 10 = 9.
+ - 5th task. Now energy = 9 - 8 = 1.
+```
+
+**Example 3:**
+
+```
+Input: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]
+Output: 27
+Explanation:
+Starting with 27 energy, we finish the tasks in the following order:
+ - 5th task. Now energy = 27 - 5 = 22.
+ - 2nd task. Now energy = 22 - 2 = 20.
+ - 3rd task. Now energy = 20 - 3 = 17.
+ - 1st task. Now energy = 17 - 1 = 16.
+ - 4th task. Now energy = 16 - 4 = 12.
+ - 6th task. Now energy = 12 - 6 = 6.
+
+```
+
+**Constraints:**
+
+- `1 <= tasks.length <= 105`
+- `1 <= actuali <= minimumi <= 104`
+
+## 题目大意
+
+给你一个任务数组 tasks ,其中 tasks[i] = [actuali, minimumi] :
+
+- actual i 是完成第 i 个任务 需要耗费 的实际能量。
+- minimum i 是开始第 i 个任务前需要达到的最低能量。
+
+比方说,如果任务为 [10, 12] 且你当前的能量为 11 ,那么你不能开始这个任务。如果你当前的能量为 13 ,你可以完成这个任务,且完成它后剩余能量为 3 。你可以按照 任意顺序 完成任务。请你返回完成所有任务的 最少 初始能量。
+
+## 解题思路
+
+- 给出一个 task 数组,每个元素代表一个任务,每个任务有实际消费能量值和开始这个任务需要的最低能量。要求输出能完成所有任务的最少初始能量。
+- 这一题直觉是贪心。先将任务按照 `minimum - actual` 进行排序。先完成差值大的任务,那么接下来的能量能最大限度的满足接下来的任务。这样可能完成所有任务的可能性越大。循环任务数组的时候,保存当前能量在 `cur` 中,如果当前能量不够开启下一个任务,那么这个差值就是需要弥补的,这些能量就是最少初始能量中的,所以加上这些差值能量。如果当前能量可以开启下一个任务,那么就更新当前能量,减去实际消耗的能量以后,再继续循环。循环结束就能得到最少初始能量了。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "sort"
+)
+
+func minimumEffort(tasks [][]int) int {
+ sort.Sort(Task(tasks))
+ res, cur := 0, 0
+ for _, t := range tasks {
+ if t[1] > cur {
+ res += t[1] - cur
+ cur = t[1] - t[0]
+ } else {
+ cur -= t[0]
+ }
+ }
+ return res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+// Task define
+type Task [][]int
+
+func (task Task) Len() int {
+ return len(task)
+}
+
+func (task Task) Less(i, j int) bool {
+ t1, t2 := task[i][1]-task[i][0], task[j][1]-task[j][0]
+ if t1 != t2 {
+ return t2 < t1
+ }
+ return task[j][1] < task[i][1]
+}
+
+func (task Task) Swap(i, j int) {
+ t := task[i]
+ task[i] = task[j]
+ task[j] = t
+}
+```
\ No newline at end of file
diff --git a/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring.go b/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring.go
new file mode 100644
index 00000000..1ef762ab
--- /dev/null
+++ b/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring.go
@@ -0,0 +1,18 @@
+package leetcode
+
+import (
+ "strings"
+)
+
+func maxRepeating(sequence string, word string) int {
+ for i := len(sequence) / len(word); i >= 0; i-- {
+ tmp := ""
+ for j := 0; j < i; j++ {
+ tmp += word
+ }
+ if strings.Contains(sequence, tmp) {
+ return i
+ }
+ }
+ return 0
+}
diff --git a/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring_test.go b/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring_test.go
new file mode 100644
index 00000000..ee5aadd5
--- /dev/null
+++ b/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1668 struct {
+ para1668
+ ans1668
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1668 struct {
+ sequence string
+ word string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1668 struct {
+ one int
+}
+
+func Test_Problem1668(t *testing.T) {
+
+ qs := []question1668{
+
+ {
+ para1668{"ababc", "ab"},
+ ans1668{2},
+ },
+
+ {
+ para1668{"ababc", "ba"},
+ ans1668{1},
+ },
+
+ {
+ para1668{"ababc", "ac"},
+ ans1668{0},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1668------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1668, q.para1668
+ fmt.Printf("【input】:%v 【output】:%v \n", p, maxRepeating(p.sequence, p.word))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1668.Maximum-Repeating-Substring/README.md b/leetcode/1668.Maximum-Repeating-Substring/README.md
new file mode 100644
index 00000000..b25e75de
--- /dev/null
+++ b/leetcode/1668.Maximum-Repeating-Substring/README.md
@@ -0,0 +1,69 @@
+# [1668. Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring/)
+
+
+## 题目
+
+For a string `sequence`, a string `word` is **`k`-repeating** if `word` concatenated `k` times is a substring of `sequence`. The `word`'s **maximum `k`-repeating value** is the highest value `k` where `word` is `k`-repeating in `sequence`. If `word` is not a substring of `sequence`, `word`'s maximum `k`-repeating value is `0`.
+
+Given strings `sequence` and `word`, return *the **maximum `k`-repeating value** of `word` in `sequence`*.
+
+**Example 1:**
+
+```
+Input: sequence = "ababc", word = "ab"
+Output: 2
+Explanation: "abab" is a substring in "ababc".
+```
+
+**Example 2:**
+
+```
+Input: sequence = "ababc", word = "ba"
+Output: 1
+Explanation: "ba" is a substring in "ababc". "baba" is not a substring in "ababc".
+```
+
+**Example 3:**
+
+```
+Input: sequence = "ababc", word = "ac"
+Output: 0
+Explanation: "ac" is not a substring in "ababc".
+```
+
+**Constraints:**
+
+- `1 <= sequence.length <= 100`
+- `1 <= word.length <= 100`
+- `sequence` and `word` contains only lowercase English letters.
+
+## 题目大意
+
+给你一个字符串 sequence ,如果字符串 word 连续重复 k 次形成的字符串是 sequence 的一个子字符串,那么单词 word 的 重复值为 k 。单词 word 的 最大重复值 是单词 word 在 sequence 中最大的重复值。如果 word 不是 sequence 的子串,那么重复值 k 为 0 。给你一个字符串 sequence 和 word ,请你返回 最大重复值 k 。
+
+## 解题思路
+
+- 循环叠加构造 `word`,每次构造出新的 `word` 都在 `sequence` 查找一次,如果找到就输出叠加次数,否则继续叠加构造,直到字符串长度和 `sequence` 一样长,最终都没有找到则输出 0 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "strings"
+)
+
+func maxRepeating(sequence string, word string) int {
+ for i := len(sequence) / len(word); i >= 0; i-- {
+ tmp := ""
+ for j := 0; j < i; j++ {
+ tmp += word
+ }
+ if strings.Contains(sequence, tmp) {
+ return i
+ }
+ }
+ return 0
+}
+```
\ No newline at end of file
diff --git a/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists.go b/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists.go
new file mode 100644
index 00000000..9536270e
--- /dev/null
+++ b/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists.go
@@ -0,0 +1,37 @@
+package leetcode
+
+import (
+ "github.com/halfrost/LeetCode-Go/structures"
+)
+
+// ListNode define
+type ListNode = structures.ListNode
+
+/**
+ * Definition for singly-linked list.
+ * type ListNode struct {
+ * Val int
+ * Next *ListNode
+ * }
+ */
+
+func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {
+ n := list1
+ var startRef, endRef *ListNode
+ for i := 0; i <= b; i++ {
+ if i == a-1 {
+ startRef = n
+ }
+ if i == b {
+ endRef = n
+ }
+ n = n.Next
+ }
+ startRef.Next = list2
+ n = list2
+ for n.Next != nil {
+ n = n.Next
+ }
+ n.Next = endRef.Next
+ return list1
+}
diff --git a/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists_test.go b/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists_test.go
new file mode 100644
index 00000000..b7d63a0e
--- /dev/null
+++ b/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists_test.go
@@ -0,0 +1,62 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/halfrost/LeetCode-Go/structures"
+)
+
+type question1669 struct {
+ para1669
+ ans1669
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1669 struct {
+ one []int
+ a int
+ b int
+ another []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1669 struct {
+ one []int
+}
+
+func Test_Problem1669(t *testing.T) {
+
+ qs := []question1669{
+
+ {
+ para1669{[]int{0, 1, 2, 3, 4, 5}, 3, 4, []int{1000000, 1000001, 1000002}},
+ ans1669{[]int{0, 1, 2, 1000000, 1000001, 1000002, 5}},
+ },
+
+ {
+ para1669{[]int{0, 1, 2, 3, 4, 5, 6}, 2, 5, []int{1000000, 1000001, 1000002, 1000003, 1000004}},
+ ans1669{[]int{0, 1, 1000000, 1000001, 1000002, 1000003, 1000004, 6}},
+ },
+
+ {
+ para1669{[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 3, 5, []int{1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006}},
+ ans1669{[]int{0, 1, 2, 1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006, 6, 7, 8, 9}},
+ },
+
+ {
+ para1669{[]int{0, 1, 2}, 1, 1, []int{1000000, 1000001, 1000002, 1000003}},
+ ans1669{[]int{0, 1000000, 1000001, 1000002, 1000003, 2}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1669------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1669, q.para1669
+ fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(mergeInBetween(structures.Ints2List(p.one), p.a, p.b, structures.Ints2List(p.another))))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1669.Merge-In-Between-Linked-Lists/README.md b/leetcode/1669.Merge-In-Between-Linked-Lists/README.md
new file mode 100644
index 00000000..3b221b0f
--- /dev/null
+++ b/leetcode/1669.Merge-In-Between-Linked-Lists/README.md
@@ -0,0 +1,75 @@
+# [1669. Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists/)
+
+
+## 题目
+
+You are given two linked lists: `list1` and `list2` of sizes `n` and `m` respectively.
+
+Remove `list1`'s nodes from the `ath` node to the `bth` node, and put `list2` in their place.
+
+The blue edges and nodes in the following figure incidate the result:
+
+
+
+*Build the result list and return its head.*
+
+**Example 1:**
+
+
+
+```
+Input: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]
+Output: [0,1,2,1000000,1000001,1000002,5]
+Explanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.
+
+```
+
+**Example 2:**
+
+
+
+```
+Input: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]
+Output: [0,1,1000000,1000001,1000002,1000003,1000004,6]
+Explanation: The blue edges and nodes in the above figure indicate the result.
+
+```
+
+**Constraints:**
+
+- `3 <= list1.length <= 104`
+- `1 <= a <= b < list1.length - 1`
+- `1 <= list2.length <= 104`
+
+## 题目大意
+
+给你两个链表 list1 和 list2 ,它们包含的元素分别为 n 个和 m 个。请你将 list1 中第 a 个节点到第 b 个节点删除,并将list2 接在被删除节点的位置。
+
+## 解题思路
+
+- 简单题,考查链表的基本操作。此题注意 a == b 的情况。
+
+## 代码
+
+```go
+func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {
+ n := list1
+ var startRef, endRef *ListNode
+ for i := 0; i <= b; i++ {
+ if i == a-1 {
+ startRef = n
+ }
+ if i == b {
+ endRef = n
+ }
+ n = n.Next
+ }
+ startRef.Next = list2
+ n = list2
+ for n.Next != nil {
+ n = n.Next
+ }
+ n.Next = endRef.Next
+ return list1
+}
+```
\ No newline at end of file
diff --git a/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue.go b/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue.go
new file mode 100644
index 00000000..63e8326b
--- /dev/null
+++ b/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue.go
@@ -0,0 +1,94 @@
+package leetcode
+
+import (
+ "container/list"
+)
+
+type FrontMiddleBackQueue struct {
+ list *list.List
+ middle *list.Element
+}
+
+func Constructor() FrontMiddleBackQueue {
+ return FrontMiddleBackQueue{list: list.New()}
+}
+
+func (this *FrontMiddleBackQueue) PushFront(val int) {
+ e := this.list.PushFront(val)
+ if this.middle == nil {
+ this.middle = e
+ } else if this.list.Len()%2 == 0 && this.middle.Prev() != nil {
+ this.middle = this.middle.Prev()
+ }
+}
+
+func (this *FrontMiddleBackQueue) PushMiddle(val int) {
+ if this.middle == nil {
+ this.PushFront(val)
+ } else {
+ if this.list.Len()%2 != 0 {
+ this.middle = this.list.InsertBefore(val, this.middle)
+ } else {
+ this.middle = this.list.InsertAfter(val, this.middle)
+ }
+ }
+}
+
+func (this *FrontMiddleBackQueue) PushBack(val int) {
+ e := this.list.PushBack(val)
+ if this.middle == nil {
+ this.middle = e
+ } else if this.list.Len()%2 != 0 && this.middle.Next() != nil {
+ this.middle = this.middle.Next()
+ }
+}
+
+func (this *FrontMiddleBackQueue) PopFront() int {
+ if this.list.Len() == 0 {
+ return -1
+ }
+ e := this.list.Front()
+ if this.list.Len() == 1 {
+ this.middle = nil
+ } else if this.list.Len()%2 == 0 && this.middle.Next() != nil {
+ this.middle = this.middle.Next()
+ }
+ return this.list.Remove(e).(int)
+}
+
+func (this *FrontMiddleBackQueue) PopMiddle() int {
+ if this.middle == nil {
+ return -1
+ }
+ e := this.middle
+ if this.list.Len()%2 != 0 {
+ this.middle = e.Prev()
+ } else {
+ this.middle = e.Next()
+ }
+ return this.list.Remove(e).(int)
+}
+
+func (this *FrontMiddleBackQueue) PopBack() int {
+ if this.list.Len() == 0 {
+ return -1
+ }
+ e := this.list.Back()
+ if this.list.Len() == 1 {
+ this.middle = nil
+ } else if this.list.Len()%2 != 0 && this.middle.Prev() != nil {
+ this.middle = this.middle.Prev()
+ }
+ return this.list.Remove(e).(int)
+}
+
+/**
+ * Your FrontMiddleBackQueue object will be instantiated and called as such:
+ * obj := Constructor();
+ * obj.PushFront(val);
+ * obj.PushMiddle(val);
+ * obj.PushBack(val);
+ * param_4 := obj.PopFront();
+ * param_5 := obj.PopMiddle();
+ * param_6 := obj.PopBack();
+ */
diff --git a/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue_test.go b/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue_test.go
new file mode 100644
index 00000000..e2b30c0e
--- /dev/null
+++ b/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue_test.go
@@ -0,0 +1,112 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+func Test_Problem1670(t *testing.T) {
+ obj := Constructor()
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushFront(1)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushBack(2)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.PushMiddle(3)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.PushMiddle(4)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ param1 := obj.PopFront()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopBack()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopFront()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ fmt.Printf("-----------------------------------------------------------------\n")
+ obj = Constructor()
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushFront(1)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushFront(2)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushFront(3)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushFront(4)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ param1 = obj.PopBack()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopBack()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopBack()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopBack()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ fmt.Printf("-----------------------------------------------------------------\n")
+ obj = Constructor()
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushMiddle(1)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.PushMiddle(2)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.PushMiddle(3)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ fmt.Printf("-----------------------------------------------------------------\n")
+ obj = Constructor()
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushMiddle(8)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopFront()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopBack()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ obj.PushMiddle(1)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ obj.PushMiddle(10)
+ fmt.Printf("obj = %v\n", MList2Ints(&obj))
+ fmt.Printf("-----------------------------------------------------------------\n")
+ obj = Constructor()
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v\n", param1, MList2Ints(&obj))
+ obj.PushMiddle(3)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushFront(6)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushMiddle(6)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ obj.PushMiddle(3)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v %v\n", param1, MList2Ints(&obj), obj)
+ obj.PushMiddle(7)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ param1 = obj.PopMiddle()
+ fmt.Printf("param1 = %v obj = %v %v\n", param1, MList2Ints(&obj), obj)
+ obj.PushMiddle(8)
+ fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
+ // ["FrontMiddleBackQueue","popMiddle","pushMiddle","pushFront","pushMiddle","pushMiddle","popMiddle","pushMiddle","popMiddle","pushMiddle"]
+ // [[],[],[3],[6],[6],[3],[],[7],[],[8]]
+}
+
+func MList2Ints(this *FrontMiddleBackQueue) []int {
+ array := []int{}
+ for e := this.list.Front(); e != nil; e = e.Next() {
+ value, _ := e.Value.(int)
+ array = append(array, value)
+ }
+ return array
+}
diff --git a/leetcode/1670.Design-Front-Middle-Back-Queue/README.md b/leetcode/1670.Design-Front-Middle-Back-Queue/README.md
new file mode 100644
index 00000000..2046abf8
--- /dev/null
+++ b/leetcode/1670.Design-Front-Middle-Back-Queue/README.md
@@ -0,0 +1,172 @@
+# [1670. Design Front Middle Back Queue](https://leetcode.com/problems/design-front-middle-back-queue/)
+
+
+## 题目
+
+Design a queue that supports `push` and `pop` operations in the front, middle, and back.
+
+Implement the `FrontMiddleBack` class:
+
+- `FrontMiddleBack()` Initializes the queue.
+- `void pushFront(int val)` Adds `val` to the **front** of the queue.
+- `void pushMiddle(int val)` Adds `val` to the **middle** of the queue.
+- `void pushBack(int val)` Adds `val` to the **back** of the queue.
+- `int popFront()` Removes the **front** element of the queue and returns it. If the queue is empty, return `1`.
+- `int popMiddle()` Removes the **middle** element of the queue and returns it. If the queue is empty, return `1`.
+- `int popBack()` Removes the **back** element of the queue and returns it. If the queue is empty, return `1`.
+
+**Notice** that when there are **two** middle position choices, the operation is performed on the **frontmost** middle position choice. For example:
+
+- Pushing `6` into the middle of `[1, 2, 3, 4, 5]` results in `[1, 2, 6, 3, 4, 5]`.
+- Popping the middle from `[1, 2, 3, 4, 5, 6]` returns `3` and results in `[1, 2, 4, 5, 6]`.
+
+**Example 1:**
+
+```
+Input:
+["FrontMiddleBackQueue", "pushFront", "pushBack", "pushMiddle", "pushMiddle", "popFront", "popMiddle", "popMiddle", "popBack", "popFront"]
+[[], [1], [2], [3], [4], [], [], [], [], []]
+Output:
+[null, null, null, null, null, 1, 3, 4, 2, -1]
+
+Explanation:
+FrontMiddleBackQueue q = new FrontMiddleBackQueue();
+q.pushFront(1); // [1]
+q.pushBack(2); // [1, 2]
+q.pushMiddle(3); // [1, 3, 2]
+q.pushMiddle(4); // [1, 4, 3, 2]
+q.popFront(); // return 1 -> [4, 3, 2]
+q.popMiddle(); // return 3 -> [4, 2]
+q.popMiddle(); // return 4 -> [2]
+q.popBack(); // return 2 -> []
+q.popFront(); // return -1 -> [] (The queue is empty)
+
+```
+
+**Constraints:**
+
+- `1 <= val <= 109`
+- At most `1000` calls will be made to `pushFront`, `pushMiddle`, `pushBack`, `popFront`, `popMiddle`, and `popBack`.
+
+## 题目大意
+
+请你设计一个队列,支持在前,中,后三个位置的 push 和 pop 操作。
+
+请你完成 FrontMiddleBack 类:
+
+- FrontMiddleBack() 初始化队列。
+- void pushFront(int val) 将 val 添加到队列的 最前面 。
+- void pushMiddle(int val) 将 val 添加到队列的 正中间 。
+- void pushBack(int val) 将 val 添加到队里的 最后面 。
+- int popFront() 将 最前面 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 -1 。
+- int popMiddle() 将 正中间 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 -1 。
+- int popBack() 将 最后面 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 -1 。
+
+请注意当有 两个 中间位置的时候,选择靠前面的位置进行操作。比方说:
+
+- 将 6 添加到 [1, 2, 3, 4, 5] 的中间位置,结果数组为 [1, 2, 6, 3, 4, 5] 。
+- 从 [1, 2, 3, 4, 5, 6] 的中间位置弹出元素,返回 3 ,数组变为 [1, 2, 4, 5, 6] 。
+
+## 解题思路
+
+- 简单题,利用 go 原生的双向队列 list 的实现,可以轻松实现这个“前中后队列”。
+- 具体实现见代码,几组特殊测试用例见测试文件。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "container/list"
+)
+
+type FrontMiddleBackQueue struct {
+ list *list.List
+ middle *list.Element
+}
+
+func Constructor() FrontMiddleBackQueue {
+ return FrontMiddleBackQueue{list: list.New()}
+}
+
+func (this *FrontMiddleBackQueue) PushFront(val int) {
+ e := this.list.PushFront(val)
+ if this.middle == nil {
+ this.middle = e
+ } else if this.list.Len()%2 == 0 && this.middle.Prev() != nil {
+ this.middle = this.middle.Prev()
+ }
+}
+
+func (this *FrontMiddleBackQueue) PushMiddle(val int) {
+ if this.middle == nil {
+ this.PushFront(val)
+ } else {
+ if this.list.Len()%2 != 0 {
+ this.middle = this.list.InsertBefore(val, this.middle)
+ } else {
+ this.middle = this.list.InsertAfter(val, this.middle)
+ }
+ }
+}
+
+func (this *FrontMiddleBackQueue) PushBack(val int) {
+ e := this.list.PushBack(val)
+ if this.middle == nil {
+ this.middle = e
+ } else if this.list.Len()%2 != 0 && this.middle.Next() != nil {
+ this.middle = this.middle.Next()
+ }
+}
+
+func (this *FrontMiddleBackQueue) PopFront() int {
+ if this.list.Len() == 0 {
+ return -1
+ }
+ e := this.list.Front()
+ if this.list.Len() == 1 {
+ this.middle = nil
+ } else if this.list.Len()%2 == 0 && this.middle.Next() != nil {
+ this.middle = this.middle.Next()
+ }
+ return this.list.Remove(e).(int)
+}
+
+func (this *FrontMiddleBackQueue) PopMiddle() int {
+ if this.middle == nil {
+ return -1
+ }
+ e := this.middle
+ if this.list.Len()%2 != 0 {
+ this.middle = e.Prev()
+ } else {
+ this.middle = e.Next()
+ }
+ return this.list.Remove(e).(int)
+}
+
+func (this *FrontMiddleBackQueue) PopBack() int {
+ if this.list.Len() == 0 {
+ return -1
+ }
+ e := this.list.Back()
+ if this.list.Len() == 1 {
+ this.middle = nil
+ } else if this.list.Len()%2 != 0 && this.middle.Prev() != nil {
+ this.middle = this.middle.Prev()
+ }
+ return this.list.Remove(e).(int)
+}
+
+/**
+ * Your FrontMiddleBackQueue object will be instantiated and called as such:
+ * obj := Constructor();
+ * obj.PushFront(val);
+ * obj.PushMiddle(val);
+ * obj.PushBack(val);
+ * param_4 := obj.PopFront();
+ * param_5 := obj.PopMiddle();
+ * param_6 := obj.PopBack();
+ */
+```
\ No newline at end of file
diff --git a/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth.go b/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth.go
new file mode 100644
index 00000000..3a851ad9
--- /dev/null
+++ b/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth.go
@@ -0,0 +1,15 @@
+package leetcode
+
+func maximumWealth(accounts [][]int) int {
+ res := 0
+ for _, banks := range accounts {
+ sAmount := 0
+ for _, amount := range banks {
+ sAmount += amount
+ }
+ if sAmount > res {
+ res = sAmount
+ }
+ }
+ return res
+}
diff --git a/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth_test.go b/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth_test.go
new file mode 100644
index 00000000..7c6e689f
--- /dev/null
+++ b/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1672 struct {
+ para1672
+ ans1672
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1672 struct {
+ accounts [][]int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1672 struct {
+ one int
+}
+
+func Test_Problem1672(t *testing.T) {
+
+ qs := []question1672{
+
+ {
+ para1672{[][]int{{1, 2, 3}, {3, 2, 1}}},
+ ans1672{6},
+ },
+
+ {
+ para1672{[][]int{{1, 5}, {7, 3}, {3, 5}}},
+ ans1672{10},
+ },
+
+ {
+ para1672{[][]int{{2, 8, 7}, {7, 1, 3}, {1, 9, 5}}},
+ ans1672{17},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1672------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1672, q.para1672
+ fmt.Printf("【input】:%v 【output】:%v\n", p, maximumWealth(p.accounts))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1672.Richest-Customer-Wealth/README.md b/leetcode/1672.Richest-Customer-Wealth/README.md
new file mode 100644
index 00000000..250cf480
--- /dev/null
+++ b/leetcode/1672.Richest-Customer-Wealth/README.md
@@ -0,0 +1,72 @@
+# [1672. Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/)
+
+
+## 题目
+
+You are given an `m x n` integer grid `accounts` where `accounts[i][j]` is the amount of money the `ith` customer has in the `jth` bank. Return *the **wealth** that the richest customer has.*
+
+A customer's **wealth** is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum **wealth**.
+
+**Example 1:**
+
+```
+Input: accounts = [[1,2,3],[3,2,1]]
+Output: 6
+Explanation:1st customer has wealth = 1 + 2 + 3 = 6
+2nd customer has wealth = 3 + 2 + 1 = 6
+Both customers are considered the richest with a wealth of 6 each, so return 6.
+```
+
+**Example 2:**
+
+```
+Input: accounts = [[1,5],[7,3],[3,5]]
+Output: 10
+Explanation:
+1st customer has wealth = 6
+2nd customer has wealth = 10
+3rd customer has wealth = 8
+The 2nd customer is the richest with a wealth of 10.
+```
+
+**Example 3:**
+
+```
+Input: accounts = [[2,8,7],[7,1,3],[1,9,5]]
+Output: 17
+```
+
+**Constraints:**
+
+- `m == accounts.length`
+- `n == accounts[i].length`
+- `1 <= m, n <= 50`
+- `1 <= accounts[i][j] <= 100`
+
+## 题目大意
+
+给你一个 m x n 的整数网格 accounts ,其中 accounts[i][j] 是第 i 位客户在第 j 家银行托管的资产数量。返回最富有客户所拥有的 资产总量 。客户的 资产总量 就是他们在各家银行托管的资产数量之和。最富有客户就是 资产总量 最大的客户。
+
+## 解题思路
+
+- 简单题。计算二维数组中每个一位数组的元素总和,然后动态维护这些一位数组和的最大值即可。
+
+## 代码
+
+```go
+package leetcode
+
+func maximumWealth(accounts [][]int) int {
+ res := 0
+ for _, banks := range accounts {
+ sAmount := 0
+ for _, amount := range banks {
+ sAmount += amount
+ }
+ if sAmount > res {
+ res = sAmount
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence.go b/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence.go
new file mode 100644
index 00000000..04f8fb52
--- /dev/null
+++ b/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence.go
@@ -0,0 +1,13 @@
+package leetcode
+
+// 单调栈
+func mostCompetitive(nums []int, k int) []int {
+ stack := make([]int, 0, len(nums))
+ for i := 0; i < len(nums); i++ {
+ for len(stack)+len(nums)-i > k && len(stack) > 0 && nums[i] < stack[len(stack)-1] {
+ stack = stack[:len(stack)-1]
+ }
+ stack = append(stack, nums[i])
+ }
+ return stack[:k]
+}
diff --git a/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence_test.go b/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence_test.go
new file mode 100644
index 00000000..33f2724d
--- /dev/null
+++ b/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence_test.go
@@ -0,0 +1,63 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1673 struct {
+ para1673
+ ans1673
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1673 struct {
+ nums []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1673 struct {
+ one []int
+}
+
+func Test_Problem1673(t *testing.T) {
+
+ qs := []question1673{
+
+ {
+ para1673{[]int{3, 5, 2, 6}, 2},
+ ans1673{[]int{2, 6}},
+ },
+
+ {
+ para1673{[]int{2, 4, 3, 3, 5, 4, 9, 6}, 4},
+ ans1673{[]int{2, 3, 3, 4}},
+ },
+
+ {
+ para1673{[]int{2, 4, 3, 3, 5, 4, 9, 6}, 4},
+ ans1673{[]int{2, 3, 3, 4}},
+ },
+
+ {
+ para1673{[]int{71, 18, 52, 29, 55, 73, 24, 42, 66, 8, 80, 2}, 3},
+ ans1673{[]int{8, 80, 2}},
+ },
+
+ {
+ para1673{[]int{84, 10, 71, 23, 66, 61, 62, 64, 34, 41, 80, 25, 91, 43, 4, 75, 65, 13, 37, 41, 46, 90, 55, 8, 85, 61, 95, 71}, 24},
+ ans1673{[]int{10, 23, 61, 62, 34, 41, 80, 25, 91, 43, 4, 75, 65, 13, 37, 41, 46, 90, 55, 8, 85, 61, 95, 71}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1673------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1673, q.para1673
+ fmt.Printf("【input】:%v 【output】:%v\n", p, mostCompetitive(p.nums, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1673.Find-the-Most-Competitive-Subsequence/README.md b/leetcode/1673.Find-the-Most-Competitive-Subsequence/README.md
new file mode 100644
index 00000000..74ced398
--- /dev/null
+++ b/leetcode/1673.Find-the-Most-Competitive-Subsequence/README.md
@@ -0,0 +1,62 @@
+# [1673. Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence/)
+
+
+## 题目
+
+Given an integer array `nums` and a positive integer `k`, return *the most **competitive** subsequence of* `nums` *of size* `k`.
+
+An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.
+
+We define that a subsequence `a` is more **competitive** than a subsequence `b` (of the same length) if in the first position where `a` and `b` differ, subsequence `a` has a number **less** than the corresponding number in `b`. For example, `[1,3,4]` is more competitive than `[1,3,5]` because the first position they differ is at the final number, and `4` is less than `5`.
+
+**Example 1:**
+
+```
+Input: nums = [3,5,2,6], k = 2
+Output: [2,6]
+Explanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.
+
+```
+
+**Example 2:**
+
+```
+Input: nums = [2,4,3,3,5,4,9,6], k = 4
+Output: [2,3,3,4]
+
+```
+
+**Constraints:**
+
+- `1 <= nums.length <= 105`
+- `0 <= nums[i] <= 109`
+- `1 <= k <= nums.length`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个正整数 k ,返回长度为 k 且最具 竞争力 的 nums 子序列。数组的子序列是从数组中删除一些元素(可能不删除元素)得到的序列。
+
+在子序列 a 和子序列 b 第一个不相同的位置上,如果 a 中的数字小于 b 中对应的数字,那么我们称子序列 a 比子序列 b(相同长度下)更具 竞争力 。 例如,[1,3,4] 比 [1,3,5] 更具竞争力,在第一个不相同的位置,也就是最后一个位置上, 4 小于 5 。
+
+## 解题思路
+
+- 这一题是单调栈的典型题型。利用单调栈,可以保证原数组中元素相对位置不变,这满足题意中删除元素但不移动元素的要求。单调栈又能保证每次进栈,元素是最小的。
+- 类似的题目还有第 42 题,第 84 题,第 496 题,第 503 题,第 856 题,第 901 题,第 907 题,第 1130 题,第 1425 题,第 1673 题。
+
+## 代码
+
+```go
+package leetcode
+
+// 单调栈
+func mostCompetitive(nums []int, k int) []int {
+ stack := make([]int, 0, len(nums))
+ for i := 0; i < len(nums); i++ {
+ for len(stack)+len(nums)-i > k && len(stack) > 0 && nums[i] < stack[len(stack)-1] {
+ stack = stack[:len(stack)-1]
+ }
+ stack = append(stack, nums[i])
+ }
+ return stack[:k]
+}
+```
\ No newline at end of file
diff --git a/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary.go b/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary.go
new file mode 100644
index 00000000..cd8ef3b4
--- /dev/null
+++ b/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary.go
@@ -0,0 +1,34 @@
+package leetcode
+
+func minMoves(nums []int, limit int) int {
+ diff := make([]int, limit*2+2) // nums[i] <= limit, b+limit+1 is maximum limit+limit+1
+ for j := 0; j < len(nums)/2; j++ {
+ a, b := min(nums[j], nums[len(nums)-j-1]), max(nums[j], nums[len(nums)-j-1])
+ // using prefix sum: most interesting point, and is the key to reduce complexity
+ diff[2] += 2
+ diff[a+1]--
+ diff[a+b]--
+ diff[a+b+1]++
+ diff[b+limit+1]++
+ }
+ cur, res := 0, len(nums)
+ for i := 2; i <= 2*limit; i++ {
+ cur += diff[i]
+ res = min(res, cur)
+ }
+ return res
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary_test.go b/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary_test.go
new file mode 100644
index 00000000..c111bf14
--- /dev/null
+++ b/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1674 struct {
+ para1674
+ ans1674
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1674 struct {
+ nums []int
+ limit int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1674 struct {
+ one int
+}
+
+func Test_Problem1674(t *testing.T) {
+
+ qs := []question1674{
+
+ {
+ para1674{[]int{1, 2, 4, 3}, 4},
+ ans1674{1},
+ },
+
+ {
+ para1674{[]int{1, 2, 2, 1}, 2},
+ ans1674{2},
+ },
+
+ {
+ para1674{[]int{1, 2, 1, 2}, 2},
+ ans1674{0},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1674------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1674, q.para1674
+ fmt.Printf("【input】:%v 【output】:%v\n", p, minMoves(p.nums, p.limit))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/README.md b/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/README.md
new file mode 100644
index 00000000..8e565e10
--- /dev/null
+++ b/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/README.md
@@ -0,0 +1,97 @@
+# [1674. Minimum Moves to Make Array Complementary](https://leetcode.com/problems/minimum-moves-to-make-array-complementary/)
+
+## 题目
+
+You are given an integer array `nums` of **even** length `n` and an integer `limit`. In one move, you can replace any integer from `nums` with another integer between `1` and `limit`, inclusive.
+
+The array `nums` is **complementary** if for all indices `i` (**0-indexed**), `nums[i] + nums[n - 1 - i]` equals the same number. For example, the array `[1,2,3,4]` is complementary because for all indices `i`, `nums[i] + nums[n - 1 - i] = 5`.
+
+Return the ***minimum** number of moves required to make* `nums` ***complementary***.
+
+**Example 1:**
+
+```
+Input: nums = [1,2,4,3], limit = 4
+Output: 1
+Explanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).
+nums[0] + nums[3] = 1 + 3 = 4.
+nums[1] + nums[2] = 2 + 2 = 4.
+nums[2] + nums[1] = 2 + 2 = 4.
+nums[3] + nums[0] = 3 + 1 = 4.
+Therefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.
+```
+
+**Example 2:**
+
+```
+Input: nums = [1,2,2,1], limit = 2
+Output: 2
+Explanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.
+```
+
+**Example 3:**
+
+```
+Input: nums = [1,2,1,2], limit = 2
+Output: 0
+Explanation: nums is already complementary.
+```
+
+**Constraints:**
+
+- `n == nums.length`
+- `2 <= n <= 105`
+- `1 <= nums[i] <= limit <= 105`
+- `n` is even.
+
+## 题目大意
+
+给你一个长度为 偶数 n 的整数数组 nums 和一个整数 limit 。每一次操作,你可以将 nums 中的任何整数替换为 1 到 limit 之间的另一个整数。
+
+如果对于所有下标 i(下标从 0 开始),nums[i] + nums[n - 1 - i] 都等于同一个数,则数组 nums 是 互补的 。例如,数组 [1,2,3,4] 是互补的,因为对于所有下标 i ,nums[i] + nums[n - 1 - i] = 5 。
+
+返回使数组 互补 的 最少 操作次数。
+
+## 解题思路
+
+- 这一题考察的是差分数组。通过分析题意,可以得出,针对每一个 `sum` 的取值范围是 `[2, 2* limt]`,定义 `a = min(nums[i], nums[n - i - 1])`,`b = max(nums[i], nums[n - i - 1])`,在这个区间内,又可以细分成 5 个区间,`[2, a + 1)`,`[a + 1, a + b)`,`[a + b + 1, a + b + 1)`,`[a + b + 1, b + limit + 1)`,`[b + limit + 1, 2 * limit)`,在这 5 个区间内使得数组互补的最小操作次数分别是 `2(减少 a, 减少 b)`,`1(减少 b)`,`0(不用操作)`,`1(增大 a)`,`+2(增大 a, 增大 b)`,换个表达方式,按照扫描线从左往右扫描,在这 5 个区间内使得数组互补的最小操作次数叠加变化分别是 `+2(减少 a, 减少 b)`,`-1(减少 a)`,`-1(不用操作)`,`+1(增大 a)`,`+1(增大 a, 增大 b)`,利用这前后两个区间的关系,就可以构造一个差分数组。差分数组反应的是前后两者的关系。如果想求得 0 ~ n 的总关系,只需要求一次前缀和即可。
+- 这道题要求输出最少的操作次数,所以利用差分数组 + 前缀和,累加前缀和的同时维护最小值。从左往右扫描完一遍以后,输出最小值即可。
+
+## 代码
+
+```go
+package leetcode
+
+func minMoves(nums []int, limit int) int {
+ diff := make([]int, limit*2+2) // nums[i] <= limit, b+limit+1 is maximum limit+limit+1
+ for j := 0; j < len(nums)/2; j++ {
+ a, b := min(nums[j], nums[len(nums)-j-1]), max(nums[j], nums[len(nums)-j-1])
+ // using prefix sum: most interesting point, and is the key to reduce complexity
+ diff[2] += 2
+ diff[a+1]--
+ diff[a+b]--
+ diff[a+b+1]++
+ diff[b+limit+1]++
+ }
+ cur, res := 0, len(nums)
+ for i := 2; i <= 2*limit; i++ {
+ cur += diff[i]
+ res = min(res, cur)
+ }
+ return res
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation.go b/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation.go
new file mode 100644
index 00000000..de161200
--- /dev/null
+++ b/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation.go
@@ -0,0 +1,22 @@
+package leetcode
+
+func interpret(command string) string {
+ if command == "" {
+ return ""
+ }
+ res := ""
+ for i := 0; i < len(command); i++ {
+ if command[i] == 'G' {
+ res += "G"
+ } else {
+ if command[i] == '(' && command[i+1] == 'a' {
+ res += "al"
+ i += 3
+ } else {
+ res += "o"
+ i++
+ }
+ }
+ }
+ return res
+}
diff --git a/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation_test.go b/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation_test.go
new file mode 100644
index 00000000..588368aa
--- /dev/null
+++ b/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation_test.go
@@ -0,0 +1,52 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1678 struct {
+ para1678
+ ans1678
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1678 struct {
+ command string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1678 struct {
+ one string
+}
+
+func Test_Problem1678(t *testing.T) {
+
+ qs := []question1678{
+
+ {
+ para1678{"G()(al)"},
+ ans1678{"Goal"},
+ },
+
+ {
+ para1678{"G()()()()(al)"},
+ ans1678{"Gooooal"},
+ },
+
+ {
+ para1678{"(al)G(al)()()G"},
+ ans1678{"alGalooG"},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1678------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1678, q.para1678
+ fmt.Printf("【input】:%v 【output】:%v\n", p, interpret(p.command))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1678.Goal-Parser-Interpretation/README.md b/leetcode/1678.Goal-Parser-Interpretation/README.md
new file mode 100644
index 00000000..4f8145f4
--- /dev/null
+++ b/leetcode/1678.Goal-Parser-Interpretation/README.md
@@ -0,0 +1,73 @@
+# [1678. Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation/)
+
+## 题目
+
+You own a **Goal Parser** that can interpret a string `command`. The `command` consists of an alphabet of `"G"`, `"()"` and/or `"(al)"` in some order. The Goal Parser will interpret `"G"` as the string `"G"`, `"()"` as the string `"o"`, and `"(al)"` as the string `"al"`. The interpreted strings are then concatenated in the original order.
+
+Given the string `command`, return *the **Goal Parser**'s interpretation of* `command`.
+
+**Example 1:**
+
+```
+Input: command = "G()(al)"
+Output: "Goal"
+Explanation: The Goal Parser interprets the command as follows:
+G -> G
+() -> o
+(al) -> al
+The final concatenated result is "Goal".
+```
+
+**Example 2:**
+
+```
+Input: command = "G()()()()(al)"
+Output: "Gooooal"
+```
+
+**Example 3:**
+
+```
+Input: command = "(al)G(al)()()G"
+Output: "alGalooG"
+```
+
+**Constraints:**
+
+- `1 <= command.length <= 100`
+- `command` consists of `"G"`, `"()"`, and/or `"(al)"` in some order.
+
+## 题目大意
+
+请你设计一个可以解释字符串 command 的 Goal 解析器 。command 由 "G"、"()" 和/或 "(al)" 按某种顺序组成。Goal 解析器会将 "G" 解释为字符串 "G"、"()" 解释为字符串 "o" ,"(al)" 解释为字符串 "al" 。然后,按原顺序将经解释得到的字符串连接成一个字符串。给你字符串 command ,返回 Goal 解析器 对 command 的解释结果。
+
+## 解题思路
+
+- 简单题,按照题意修改字符串即可。由于是简单题,这一题也不用考虑嵌套的情况。
+
+## 代码
+
+```go
+package leetcode
+
+func interpret(command string) string {
+ if command == "" {
+ return ""
+ }
+ res := ""
+ for i := 0; i < len(command); i++ {
+ if command[i] == 'G' {
+ res += "G"
+ } else {
+ if command[i] == '(' && command[i+1] == 'a' {
+ res += "al"
+ i += 3
+ } else {
+ res += "o"
+ i ++
+ }
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs.go b/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs.go
new file mode 100644
index 00000000..8a601ffa
--- /dev/null
+++ b/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs.go
@@ -0,0 +1,48 @@
+package leetcode
+
+// 解法一 优化版
+func maxOperations(nums []int, k int) int {
+ counter, res := make(map[int]int), 0
+ for _, n := range nums {
+ counter[n]++
+ }
+ if (k & 1) == 0 {
+ res += counter[k>>1] >> 1
+ // 能够由 2 个相同的数构成 k 的组合已经都排除出去了,剩下的一个单独的也不能组成 k 了
+ // 所以这里要把它的频次置为 0 。如果这里不置为 0,下面代码判断逻辑还需要考虑重复使用数字的情况
+ counter[k>>1] = 0
+ }
+ for num, freq := range counter {
+ if num <= k/2 {
+ remain := k - num
+ if counter[remain] < freq {
+ res += counter[remain]
+ } else {
+ res += freq
+ }
+ }
+ }
+ return res
+}
+
+// 解法二
+func maxOperations_(nums []int, k int) int {
+ counter, res := make(map[int]int), 0
+ for _, num := range nums {
+ counter[num]++
+ remain := k - num
+ if num == remain {
+ if counter[num] >= 2 {
+ res++
+ counter[num] -= 2
+ }
+ } else {
+ if counter[remain] > 0 {
+ res++
+ counter[remain]--
+ counter[num]--
+ }
+ }
+ }
+ return res
+}
diff --git a/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs_test.go b/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs_test.go
new file mode 100644
index 00000000..c9a96b2b
--- /dev/null
+++ b/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs_test.go
@@ -0,0 +1,58 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1679 struct {
+ para1679
+ ans1679
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1679 struct {
+ nums []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1679 struct {
+ one int
+}
+
+func Test_Problem1679(t *testing.T) {
+
+ qs := []question1679{
+
+ {
+ para1679{[]int{1, 2, 3, 4}, 5},
+ ans1679{2},
+ },
+
+ {
+ para1679{[]int{3, 1, 3, 4, 3}, 6},
+ ans1679{1},
+ },
+
+ {
+ para1679{[]int{2, 5, 4, 4, 1, 3, 4, 4, 1, 4, 4, 1, 2, 1, 2, 2, 3, 2, 4, 2}, 3},
+ ans1679{4},
+ },
+
+ {
+ para1679{[]int{2, 5, 5, 5, 1, 3, 4, 4, 1, 4, 4, 1, 3, 1, 3, 1, 3, 2, 4, 2}, 6},
+ ans1679{8},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1679------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1679, q.para1679
+ fmt.Printf("【input】:%v 【output】:%v\n", p, maxOperations(p.nums, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1679.Max-Number-of-K-Sum-Pairs/README.md b/leetcode/1679.Max-Number-of-K-Sum-Pairs/README.md
new file mode 100644
index 00000000..83ed4b31
--- /dev/null
+++ b/leetcode/1679.Max-Number-of-K-Sum-Pairs/README.md
@@ -0,0 +1,98 @@
+# [1679. Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/)
+
+
+## 题目
+
+You are given an integer array `nums` and an integer `k`.
+
+In one operation, you can pick two numbers from the array whose sum equals `k` and remove them from the array.
+
+Return *the maximum number of operations you can perform on the array*.
+
+**Example 1:**
+
+```
+Input: nums = [1,2,3,4], k = 5
+Output: 2
+Explanation: Starting with nums = [1,2,3,4]:
+- Remove numbers 1 and 4, then nums = [2,3]
+- Remove numbers 2 and 3, then nums = []
+There are no more pairs that sum up to 5, hence a total of 2 operations.
+```
+
+**Example 2:**
+
+```
+Input: nums = [3,1,3,4,3], k = 6
+Output: 1
+Explanation: Starting with nums = [3,1,3,4,3]:
+- Remove the first two 3's, then nums = [1,4,3]
+There are no more pairs that sum up to 6, hence a total of 1 operation.
+```
+
+**Constraints:**
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 109`
+- `1 <= k <= 109`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个整数 k 。每一步操作中,你需要从数组中选出和为 k 的两个整数,并将它们移出数组。返回你可以对数组执行的最大操作数。
+
+## 解题思路
+
+- 读完题第一感觉这道题是 TWO SUM 题目的加强版。需要找到所有满足和是 k 的数对。先考虑能不能找到两个数都是 k/2 ,如果能找到多个这样的数,可以先移除他们。其次在利用 TWO SUM 的思路,找出和为 k 的数对。利用 TWO SUM 里面 map 的做法,时间复杂度 O(n)。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 优化版
+func maxOperations(nums []int, k int) int {
+ counter, res := make(map[int]int), 0
+ for _, n := range nums {
+ counter[n]++
+ }
+ if (k & 1) == 0 {
+ res += counter[k>>1] >> 1
+ // 能够由 2 个相同的数构成 k 的组合已经都排除出去了,剩下的一个单独的也不能组成 k 了
+ // 所以这里要把它的频次置为 0 。如果这里不置为 0,下面代码判断逻辑还需要考虑重复使用数字的情况
+ counter[k>>1] = 0
+ }
+ for num, freq := range counter {
+ if num <= k/2 {
+ remain := k - num
+ if counter[remain] < freq {
+ res += counter[remain]
+ } else {
+ res += freq
+ }
+ }
+ }
+ return res
+}
+
+// 解法二
+func maxOperations_(nums []int, k int) int {
+ counter, res := make(map[int]int), 0
+ for _, num := range nums {
+ counter[num]++
+ remain := k - num
+ if num == remain {
+ if counter[num] >= 2 {
+ res++
+ counter[num] -= 2
+ }
+ } else {
+ if counter[remain] > 0 {
+ res++
+ counter[remain]--
+ counter[num]--
+ }
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1680.Concatenation-of-Consecutive-Binary-Numbers/1680. Concatenation of Consecutive Binary Numbers.go b/leetcode/1680.Concatenation-of-Consecutive-Binary-Numbers/1680. Concatenation of Consecutive Binary Numbers.go
new file mode 100644
index 00000000..eff4e12b
--- /dev/null
+++ b/leetcode/1680.Concatenation-of-Consecutive-Binary-Numbers/1680. Concatenation of Consecutive Binary Numbers.go
@@ -0,0 +1,26 @@
+package leetcode
+
+import (
+ "math/bits"
+)
+
+// 解法一 模拟
+func concatenatedBinary(n int) int {
+ res, mod, shift := 0, 1000000007, 0
+ for i := 1; i <= n; i++ {
+ if (i & (i - 1)) == 0 {
+ shift++
+ }
+ res = ((res << shift) + i) % mod
+ }
+ return res
+}
+
+// 解法二 位运算
+func concatenatedBinary1(n int) int {
+ res := 0
+ for i := 1; i <= n; i++ {
+ res = (res< k {
+ return -1
+ }
+ }
+ orders := []int{}
+ for i := range counts {
+ orders = append(orders, i)
+ }
+ sort.Ints(orders)
+ res := math.MaxInt32
+ generatePermutation1681(nums, counts, orders, 0, 0, eachSize, &res, []int{})
+ if res == math.MaxInt32 {
+ return -1
+ }
+ return res
+}
+
+func generatePermutation1681(nums, counts, order []int, index, sum, eachSize int, res *int, current []int) {
+ if len(current) > 0 && len(current)%eachSize == 0 {
+ sum += current[len(current)-1] - current[len(current)-eachSize]
+ index = 0
+ }
+ if sum >= *res {
+ return
+ }
+ if len(current) == len(nums) {
+ if sum < *res {
+ *res = sum
+ }
+ return
+ }
+ for i := index; i < len(counts); i++ {
+ if counts[order[i]] == 0 {
+ continue
+ }
+ counts[order[i]]--
+ current = append(current, order[i])
+ generatePermutation1681(nums, counts, order, i+1, sum, eachSize, res, current)
+ current = current[:len(current)-1]
+ counts[order[i]]++
+ // 这里是关键的剪枝
+ if index == 0 {
+ break
+ }
+ }
+}
diff --git a/leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility_test.go b/leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility_test.go
new file mode 100644
index 00000000..903c963b
--- /dev/null
+++ b/leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1681 struct {
+ para1681
+ ans1681
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1681 struct {
+ nums []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1681 struct {
+ one int
+}
+
+func Test_Problem1681(t *testing.T) {
+
+ qs := []question1681{
+
+ {
+ para1681{[]int{1, 2, 1, 4}, 2},
+ ans1681{4},
+ },
+
+ {
+ para1681{[]int{6, 3, 8, 1, 3, 1, 2, 2}, 4},
+ ans1681{6},
+ },
+
+ {
+ para1681{[]int{5, 3, 3, 6, 3, 3}, 3},
+ ans1681{-1},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1681------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1681, q.para1681
+ fmt.Printf("【input】:%v 【output】:%v\n", p, minimumIncompatibility(p.nums, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1681.Minimum-Incompatibility/README.md b/leetcode/1681.Minimum-Incompatibility/README.md
new file mode 100644
index 00000000..e2f5dc1d
--- /dev/null
+++ b/leetcode/1681.Minimum-Incompatibility/README.md
@@ -0,0 +1,122 @@
+# [1681. Minimum Incompatibility](https://leetcode.com/problems/minimum-incompatibility/)
+
+
+## 题目
+
+You are given an integer array `nums` and an integer `k`. You are asked to distribute this array into `k` subsets of **equal size** such that there are no two equal elements in the same subset.
+
+A subset's **incompatibility** is the difference between the maximum and minimum elements in that array.
+
+Return *the **minimum possible sum of incompatibilities** of the* `k` *subsets after distributing the array optimally, or return* `-1` *if it is not possible.*
+
+A subset is a group integers that appear in the array with no particular order.
+
+**Example 1:**
+
+```
+Input: nums = [1,2,1,4], k = 2
+Output: 4
+Explanation: The optimal distribution of subsets is [1,2] and [1,4].
+The incompatibility is (2-1) + (4-1) = 4.
+Note that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.
+```
+
+**Example 2:**
+
+```
+Input: nums = [6,3,8,1,3,1,2,2], k = 4
+Output: 6
+Explanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].
+The incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.
+
+```
+
+**Example 3:**
+
+```
+Input: nums = [5,3,3,6,3,3], k = 3
+Output: -1
+Explanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.
+
+```
+
+**Constraints:**
+
+- `1 <= k <= nums.length <= 16`
+- `nums.length` is divisible by `k`
+- `1 <= nums[i] <= nums.length`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个整数 k 。你需要将这个数组划分到 k 个相同大小的子集中,使得同一个子集里面没有两个相同的元素。一个子集的 不兼容性 是该子集里面最大值和最小值的差。
+
+请你返回将数组分成 k 个子集后,各子集 **不兼容性** 的 **和** 的 **最小值** ,如果无法分成分成 k 个子集,返回 -1 。子集的定义是数组中一些数字的集合,对数字顺序没有要求。
+
+## 解题思路
+
+- 读完题最直白的思路就是 DFS。做法类似第 77 题。这里就不赘述了。可以见第 77 题题解。
+- 这一题还需要用到贪心的思想。每次取数都取最小的数。这样可以不会让最大数和最小数在一个集合中。由于每次取数都是取最小的,那么能保证不兼容性每次都尽量最小。于是在 order 数组中定义取数的顺序。然后再把数组从小到大排列。这样每次按照 order 顺序取数,都是取的最小值。
+- 正常的 DFS 写完提交,耗时是很长的。大概是 1532ms。如何优化到极致呢?这里需要加上 2 个剪枝条件。第一个剪枝条件比较简单,如果累计 sum 比之前存储的 res 大,那么直接 return,不需要继续递归了。第二个剪枝条件就非常重要了,可以一下子减少很多次递归。每次取数产生新的集合的时候,要从第一个最小数开始取,一旦取了,后面就不需要再循环递归了。举个例子,[1,2,3,4],第一个数如果取 2,集合可以是 [[2,3],[1,4]] 或 [[2,4], [1,3]], 这个集合和[[1,3],[2,4]]、[[1,4], [2,3]] 情况一样。可以看到如果取出第一个最小值以后,后面的循环是不必要的了。所以在取下标为 0 的数的时候,递归到底层以后,返回就可以直接 break,不用接下去的循环了,接下去的循环和递归是不必要的。每组组内的顺序我们并不关心,只要最大值和最小值在分组内即可。另外组间顺序我们也不关心。所以可以把排列问题 O(n!) 时间复杂度降低到组合问题 O(2^n)。加了这 2 个剪枝条件以后,耗时就变成了 0ms 了。beats 100%
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math"
+ "sort"
+)
+
+func minimumIncompatibility(nums []int, k int) int {
+ sort.Ints(nums)
+ eachSize, counts := len(nums)/k, make([]int, len(nums)+1)
+ for i := range nums {
+ counts[nums[i]]++
+ if counts[nums[i]] > k {
+ return -1
+ }
+ }
+ orders := []int{}
+ for i := range counts {
+ orders = append(orders, i)
+ }
+ sort.Ints(orders)
+ res := math.MaxInt32
+ generatePermutation1681(nums, counts, orders, 0, 0, eachSize, &res, []int{})
+ if res == math.MaxInt32 {
+ return -1
+ }
+ return res
+}
+
+func generatePermutation1681(nums, counts, order []int, index, sum, eachSize int, res *int, current []int) {
+ if len(current) > 0 && len(current)%eachSize == 0 {
+ sum += current[len(current)-1] - current[len(current)-eachSize]
+ index = 0
+ }
+ if sum >= *res {
+ return
+ }
+ if len(current) == len(nums) {
+ if sum < *res {
+ *res = sum
+ }
+ return
+ }
+ for i := index; i < len(counts); i++ {
+ if counts[order[i]] == 0 {
+ continue
+ }
+ counts[order[i]]--
+ current = append(current, order[i])
+ generatePermutation1681(nums, counts, order, i+1, sum, eachSize, res, current)
+ current = current[:len(current)-1]
+ counts[order[i]]++
+ // 这里是关键的剪枝
+ if index == 0 {
+ break
+ }
+ }
+}
+```
\ No newline at end of file
diff --git a/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings.go b/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings.go
new file mode 100644
index 00000000..80b40a08
--- /dev/null
+++ b/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings.go
@@ -0,0 +1,21 @@
+package leetcode
+
+func countConsistentStrings(allowed string, words []string) int {
+ allowedMap, res, flag := map[rune]int{}, 0, true
+ for _, str := range allowed {
+ allowedMap[str]++
+ }
+ for i := 0; i < len(words); i++ {
+ flag = true
+ for j := 0; j < len(words[i]); j++ {
+ if _, ok := allowedMap[rune(words[i][j])]; !ok {
+ flag = false
+ break
+ }
+ }
+ if flag {
+ res++
+ }
+ }
+ return res
+}
diff --git a/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings_test.go b/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings_test.go
new file mode 100644
index 00000000..c94501b6
--- /dev/null
+++ b/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1684 struct {
+ para1684
+ ans1684
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1684 struct {
+ allowed string
+ words []string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1684 struct {
+ one int
+}
+
+func Test_Problem1684(t *testing.T) {
+
+ qs := []question1684{
+
+ {
+ para1684{"ab", []string{"ad", "bd", "aaab", "baa", "badab"}},
+ ans1684{2},
+ },
+
+ {
+ para1684{"abc", []string{"a", "b", "c", "ab", "ac", "bc", "abc"}},
+ ans1684{7},
+ },
+
+ {
+ para1684{"cad", []string{"cc", "acd", "b", "ba", "bac", "bad", "ac", "d"}},
+ ans1684{4},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1684------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1684, q.para1684
+ fmt.Printf("【input】:%v 【output】:%v\n", p, countConsistentStrings(p.allowed, p.words))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1684.Count-the-Number-of-Consistent-Strings/README.md b/leetcode/1684.Count-the-Number-of-Consistent-Strings/README.md
new file mode 100644
index 00000000..85a779c8
--- /dev/null
+++ b/leetcode/1684.Count-the-Number-of-Consistent-Strings/README.md
@@ -0,0 +1,79 @@
+# [1684. Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings/)
+
+
+## 题目
+
+You are given a string `allowed` consisting of **distinct** characters and an array of strings `words`. A string is **consistent** if all characters in the string appear in the string `allowed`.
+
+Return *the number of **consistent** strings in the array* `words`.
+
+**Example 1:**
+
+```
+Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
+Output: 2
+Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.
+
+```
+
+**Example 2:**
+
+```
+Input: allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]
+Output: 7
+Explanation: All strings are consistent.
+
+```
+
+**Example 3:**
+
+```
+Input: allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]
+Output: 4
+Explanation: Strings "cc", "acd", "ac", and "d" are consistent.
+
+```
+
+**Constraints:**
+
+- `1 <= words.length <= 104`
+- `1 <= allowed.length <= 26`
+- `1 <= words[i].length <= 10`
+- The characters in `allowed` are **distinct**.
+- `words[i]` and `allowed` contain only lowercase English letters.
+
+## 题目大意
+
+给你一个由不同字符组成的字符串 `allowed` 和一个字符串数组 `words` 。如果一个字符串的每一个字符都在 `allowed` 中,就称这个字符串是 一致字符串 。
+
+请你返回 `words` 数组中 一致字符串 的数目。
+
+## 解题思路
+
+- 简单题。先将 `allowed` 转化成 map。将 `words` 数组中每个单词的字符都在 map 中查找一遍,如果都存在就累加 res。如果有不存在的字母,不累加。最终输出 res 即可。
+
+## 代码
+
+```go
+package leetcode
+
+func countConsistentStrings(allowed string, words []string) int {
+ allowedMap, res, flag := map[rune]int{}, 0, true
+ for _, str := range allowed {
+ allowedMap[str]++
+ }
+ for i := 0; i < len(words); i++ {
+ flag = true
+ for j := 0; j < len(words[i]); j++ {
+ if _, ok := allowedMap[rune(words[i][j])]; !ok {
+ flag = false
+ break
+ }
+ }
+ if flag {
+ res++
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/1685. Sum of Absolute Differences in a Sorted Array.go b/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/1685. Sum of Absolute Differences in a Sorted Array.go
new file mode 100644
index 00000000..b2682093
--- /dev/null
+++ b/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/1685. Sum of Absolute Differences in a Sorted Array.go
@@ -0,0 +1,42 @@
+package leetcode
+
+//解法一 优化版 prefixSum + sufixSum
+func getSumAbsoluteDifferences(nums []int) []int {
+ size := len(nums)
+ sufixSum := make([]int, size)
+ sufixSum[size-1] = nums[size-1]
+ for i := size - 2; i >= 0; i-- {
+ sufixSum[i] = sufixSum[i+1] + nums[i]
+ }
+ ans, preSum := make([]int, size), 0
+ for i := 0; i < size; i++ {
+ // 后面可以加到的值
+ res, sum := 0, sufixSum[i]-nums[i]
+ res += (sum - (size-i-1)*nums[i])
+ // 前面可以加到的值
+ res += (i*nums[i] - preSum)
+ ans[i] = res
+ preSum += nums[i]
+ }
+ return ans
+}
+
+// 解法二 prefixSum
+func getSumAbsoluteDifferences1(nums []int) []int {
+ preSum, res, sum := []int{}, []int{}, nums[0]
+ preSum = append(preSum, nums[0])
+ for i := 1; i < len(nums); i++ {
+ sum += nums[i]
+ preSum = append(preSum, sum)
+ }
+ for i := 0; i < len(nums); i++ {
+ if i == 0 {
+ res = append(res, preSum[len(nums)-1]-preSum[0]-nums[i]*(len(nums)-1))
+ } else if i > 0 && i < len(nums)-1 {
+ res = append(res, preSum[len(nums)-1]-preSum[i]-preSum[i-1]+nums[i]*i-nums[i]*(len(nums)-1-i))
+ } else {
+ res = append(res, nums[i]*len(nums)-preSum[len(nums)-1])
+ }
+ }
+ return res
+}
diff --git a/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/1685. Sum of Absolute Differences in a Sorted Array_test.go b/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/1685. Sum of Absolute Differences in a Sorted Array_test.go
new file mode 100644
index 00000000..70ba45b4
--- /dev/null
+++ b/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/1685. Sum of Absolute Differences in a Sorted Array_test.go
@@ -0,0 +1,47 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1685 struct {
+ para1685
+ ans1685
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1685 struct {
+ nums []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1685 struct {
+ one []int
+}
+
+func Test_Problem1685(t *testing.T) {
+
+ qs := []question1685{
+
+ {
+ para1685{[]int{2, 3, 5}},
+ ans1685{[]int{4, 3, 5}},
+ },
+
+ {
+ para1685{[]int{1, 4, 6, 8, 10}},
+ ans1685{[]int{24, 15, 13, 15, 21}},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1685------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1685, q.para1685
+ fmt.Printf("【input】:%v 【output】:%v\n", p, getSumAbsoluteDifferences(p.nums))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/README.md b/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/README.md
new file mode 100644
index 00000000..2de2fe4c
--- /dev/null
+++ b/leetcode/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array/README.md
@@ -0,0 +1,88 @@
+# [1685. Sum of Absolute Differences in a Sorted Array](https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array/)
+
+
+## 题目
+
+You are given an integer array `nums` sorted in **non-decreasing** order.
+
+Build and return *an integer array* `result` *with the same length as* `nums` *such that* `result[i]` *is equal to the **summation of absolute differences** between* `nums[i]` *and all the other elements in the array.*
+
+In other words, `result[i]` is equal to `sum(|nums[i]-nums[j]|)` where `0 <= j < nums.length` and `j != i` (**0-indexed**).
+
+**Example 1:**
+
+```
+Input: nums = [2,3,5]
+Output: [4,3,5]
+Explanation: Assuming the arrays are 0-indexed, then
+result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
+result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
+result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.
+```
+
+**Example 2:**
+
+```
+Input: nums = [1,4,6,8,10]
+Output: [24,15,13,15,21]
+```
+
+**Constraints:**
+
+- `2 <= nums.length <= 105`
+- `1 <= nums[i] <= nums[i + 1] <= 104`
+
+## 题目大意
+
+给你一个 非递减 有序整数数组 `nums` 。请你建立并返回一个整数数组 `result`,它跟 `nums` 长度相同,且`result[i]` 等于 `nums[i]` 与数组中所有其他元素差的绝对值之和。换句话说, `result[i]` 等于 `sum(|nums[i]-nums[j]|)` ,其中 `0 <= j < nums.length` 且 `j != i` (下标从 0 开始)。
+
+## 解题思路
+
+- 利用前缀和思路解题。题目中说明了是有序数组,所以在计算绝对值的时候可以拆开绝对值符号。假设要计算当前 `result[i]`,以 `i` 为界,把原数组 `nums` 分成了 3 段。`nums[0 ~ i-1]` 和 `nums[i+1 ~ n]`,前面一段 `nums[0 ~ i-1]` 中的每个元素都比 `nums[i]` 小,拆掉绝对值以后,`sum(|nums[i]-nums[j]|) = nums[i] * i - prefixSum[0 ~ i-1]`,后面一段 `nums[i+1 ~ n]` 中的每个元素都比 `nums[i]` 大,拆掉绝对值以后,`sum(|nums[i]-nums[j]|) = prefixSum[i+1 ~ n] - nums[i] * (n - 1 - i)`。特殊的情况,`i = 0` 和 `i = n` 的情况特殊处理一下就行。
+
+## 代码
+
+```go
+package leetcode
+
+//解法一 优化版 prefixSum + sufixSum
+func getSumAbsoluteDifferences(nums []int) []int {
+ size := len(nums)
+ sufixSum := make([]int, size)
+ sufixSum[size-1] = nums[size-1]
+ for i := size - 2; i >= 0; i-- {
+ sufixSum[i] = sufixSum[i+1] + nums[i]
+ }
+ ans, preSum := make([]int, size), 0
+ for i := 0; i < size; i++ {
+ // 后面可以加到的值
+ res, sum := 0, sufixSum[i]-nums[i]
+ res += (sum - (size-i-1)*nums[i])
+ // 前面可以加到的值
+ res += (i*nums[i] - preSum)
+ ans[i] = res
+ preSum += nums[i]
+ }
+ return ans
+}
+
+// 解法二 prefixSum
+func getSumAbsoluteDifferences1(nums []int) []int {
+ preSum, res, sum := []int{}, []int{}, nums[0]
+ preSum = append(preSum, nums[0])
+ for i := 1; i < len(nums); i++ {
+ sum += nums[i]
+ preSum = append(preSum, sum)
+ }
+ for i := 0; i < len(nums); i++ {
+ if i == 0 {
+ res = append(res, preSum[len(nums)-1]-preSum[0]-nums[i]*(len(nums)-1))
+ } else if i > 0 && i < len(nums)-1 {
+ res = append(res, preSum[len(nums)-1]-preSum[i]-preSum[i-1]+nums[i]*i-nums[i]*(len(nums)-1-i))
+ } else {
+ res = append(res, nums[i]*len(nums)-preSum[len(nums)-1])
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament.go b/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament.go
new file mode 100644
index 00000000..67c8ac65
--- /dev/null
+++ b/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament.go
@@ -0,0 +1,21 @@
+package leetcode
+
+// 解法一
+func numberOfMatches(n int) int {
+ return n - 1
+}
+
+// 解法二 模拟
+func numberOfMatches1(n int) int {
+ sum := 0
+ for n != 1 {
+ if n&1 == 0 {
+ sum += n / 2
+ n = n / 2
+ } else {
+ sum += (n - 1) / 2
+ n = (n-1)/2 + 1
+ }
+ }
+ return sum
+}
diff --git a/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament_test.go b/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament_test.go
new file mode 100644
index 00000000..71e60e59
--- /dev/null
+++ b/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament_test.go
@@ -0,0 +1,47 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1688 struct {
+ para1688
+ ans1688
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1688 struct {
+ n int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1688 struct {
+ one int
+}
+
+func Test_Problem1688(t *testing.T) {
+
+ qs := []question1688{
+
+ {
+ para1688{7},
+ ans1688{6},
+ },
+
+ {
+ para1688{14},
+ ans1688{13},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1688------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1688, q.para1688
+ fmt.Printf("【input】:%v 【output】:%v\n", p, numberOfMatches(p.n))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1688.Count-of-Matches-in-Tournament/README.md b/leetcode/1688.Count-of-Matches-in-Tournament/README.md
new file mode 100644
index 00000000..b9b5f0a9
--- /dev/null
+++ b/leetcode/1688.Count-of-Matches-in-Tournament/README.md
@@ -0,0 +1,80 @@
+# [1688. Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament/)
+
+
+## 题目
+
+You are given an integer `n`, the number of teams in a tournament that has strange rules:
+
+- If the current number of teams is **even**, each team gets paired with another team. A total of `n / 2` matches are played, and `n / 2` teams advance to the next round.
+- If the current number of teams is **odd**, one team randomly advances in the tournament, and the rest gets paired. A total of `(n - 1) / 2` matches are played, and `(n - 1) / 2 + 1` teams advance to the next round.
+
+Return *the number of matches played in the tournament until a winner is decided.*
+
+**Example 1:**
+
+```
+Input: n = 7
+Output: 6
+Explanation: Details of the tournament:
+- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
+- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
+- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
+Total number of matches = 3 + 2 + 1 = 6.
+```
+
+**Example 2:**
+
+```
+Input: n = 14
+Output: 13
+Explanation: Details of the tournament:
+- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
+- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
+- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
+- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
+Total number of matches = 7 + 3 + 2 + 1 = 13.
+```
+
+**Constraints:**
+
+- `1 <= n <= 200`
+
+## 题目大意
+
+给你一个整数 n ,表示比赛中的队伍数。比赛遵循一种独特的赛制:
+
+- 如果当前队伍数是 偶数 ,那么每支队伍都会与另一支队伍配对。总共进行 n / 2 场比赛,且产生 n / 2 支队伍进入下一轮。
+- 如果当前队伍数为 奇数 ,那么将会随机轮空并晋级一支队伍,其余的队伍配对。总共进行 (n - 1) / 2 场比赛,且产生 (n - 1) / 2 + 1 支队伍进入下一轮。
+
+返回在比赛中进行的配对次数,直到决出获胜队伍为止。
+
+## 解题思路
+
+- 简单题,按照题目的规则模拟。
+- 这一题还有更加简洁的代码,见解法一。n 个队伍,一个冠军,需要淘汰 n-1 个队伍。每一场比赛淘汰一个队伍,因此进行了 n-1 场比赛。所以共有 n-1 个配对。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一
+func numberOfMatches(n int) int {
+ return n - 1
+}
+
+// 解法二 模拟
+func numberOfMatches1(n int) int {
+ sum := 0
+ for n != 1 {
+ if n&1 == 0 {
+ sum += n / 2
+ n = n / 2
+ } else {
+ sum += (n - 1) / 2
+ n = (n-1)/2 + 1
+ }
+ }
+ return sum
+}
+```
\ No newline at end of file
diff --git a/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers.go b/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers.go
new file mode 100644
index 00000000..a6313fa3
--- /dev/null
+++ b/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers.go
@@ -0,0 +1,11 @@
+package leetcode
+
+func minPartitions(n string) int {
+ res := 0
+ for i := 0; i < len(n); i++ {
+ if int(n[i]-'0') > res {
+ res = int(n[i] - '0')
+ }
+ }
+ return res
+}
diff --git a/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers_test.go b/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers_test.go
new file mode 100644
index 00000000..9acc0a74
--- /dev/null
+++ b/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers_test.go
@@ -0,0 +1,47 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1689 struct {
+ para1689
+ ans1689
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1689 struct {
+ n string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1689 struct {
+ one int
+}
+
+func Test_Problem1689(t *testing.T) {
+
+ qs := []question1689{
+
+ {
+ para1689{"32"},
+ ans1689{3},
+ },
+
+ {
+ para1689{"82734"},
+ ans1689{8},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1689------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1689, q.para1689
+ fmt.Printf("【input】:%v 【output】:%v\n", p, minPartitions(p.n))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/README.md b/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/README.md
new file mode 100644
index 00000000..2ac4daa2
--- /dev/null
+++ b/leetcode/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/README.md
@@ -0,0 +1,60 @@
+# [1689. Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/)
+
+## 题目
+
+A decimal number is called **deci-binary** if each of its digits is either `0` or `1` without any leading zeros. For example, `101` and `1100` are **deci-binary**, while `112` and `3001` are not.
+
+Given a string `n` that represents a positive decimal integer, return *the **minimum** number of positive **deci-binary** numbers needed so that they sum up to* `n`*.*
+
+**Example 1:**
+
+```
+Input: n = "32"
+Output: 3
+Explanation: 10 + 11 + 11 = 32
+```
+
+**Example 2:**
+
+```
+Input: n = "82734"
+Output: 8
+```
+
+**Example 3:**
+
+```
+Input: n = "27346209830709182346"
+Output: 9
+```
+
+**Constraints:**
+
+- `1 <= n.length <= 105`
+- `n` consists of only digits.
+- `n` does not contain any leading zeros and represents a positive integer.
+
+## 题目大意
+
+如果一个十进制数字不含任何前导零,且每一位上的数字不是 0 就是 1 ,那么该数字就是一个 十-二进制数 。例如,101 和 1100 都是 十-二进制数,而 112 和 3001 不是。给你一个表示十进制整数的字符串 n ,返回和为 n 的 十-二进制数 的最少数目。
+
+## 解题思路
+
+- 这一题也算是简单题,相通了以后,代码就 3 行。
+- 要想由 01 组成的十进制数组成 n,只需要在 n 这个数的各个数位上依次排上 0 和 1 即可。例如 n = 23423723,这是一个 8 位数。最大数字是 7,所以至少需要 7 个数累加能得到这个 n。这 7 个数的百位都为 1,其他数位按需求取 0 和 1 即可。例如万位是 2,那么这 7 个数中任找 2 个数的万位是 1 ,其他 5 个数的万位是 0 即可。
+
+## 代码
+
+```go
+package leetcode
+
+func minPartitions(n string) int {
+ res := 0
+ for i := 0; i < len(n); i++ {
+ if int(n[i]-'0') > res {
+ res = int(n[i] - '0')
+ }
+ }
+ return res
+}
+```
\ No newline at end of file
diff --git a/leetcode/1690.Stone-Game-VII/1690. Stone Game VII.go b/leetcode/1690.Stone-Game-VII/1690. Stone Game VII.go
new file mode 100644
index 00000000..c2ad93b4
--- /dev/null
+++ b/leetcode/1690.Stone-Game-VII/1690. Stone Game VII.go
@@ -0,0 +1,65 @@
+package leetcode
+
+// 解法一 优化空间版 DP
+func stoneGameVII(stones []int) int {
+ n := len(stones)
+ sum := make([]int, n)
+ dp := make([]int, n)
+ for i, d := range stones {
+ sum[i] = d
+ }
+ for i := 1; i < n; i++ {
+ for j := 0; j+i < n; j++ {
+ if (n-i)%2 == 1 {
+ d0 := dp[j] + sum[j]
+ d1 := dp[j+1] + sum[j+1]
+ if d0 > d1 {
+ dp[j] = d0
+ } else {
+ dp[j] = d1
+ }
+ } else {
+ d0 := dp[j] - sum[j]
+ d1 := dp[j+1] - sum[j+1]
+ if d0 < d1 {
+ dp[j] = d0
+ } else {
+ dp[j] = d1
+ }
+ }
+ sum[j] = sum[j] + stones[i+j]
+ }
+ }
+ return dp[0]
+}
+
+// 解法二 常规 DP
+func stoneGameVII1(stones []int) int {
+ prefixSum := make([]int, len(stones))
+ for i := 0; i < len(stones); i++ {
+ if i == 0 {
+ prefixSum[i] = stones[i]
+ } else {
+ prefixSum[i] = prefixSum[i-1] + stones[i]
+ }
+ }
+ dp := make([][]int, len(stones))
+ for i := range dp {
+ dp[i] = make([]int, len(stones))
+ dp[i][i] = 0
+ }
+ n := len(stones)
+ for l := 2; l <= n; l++ {
+ for i := 0; i+l <= n; i++ {
+ dp[i][i+l-1] = max(prefixSum[i+l-1]-prefixSum[i+1]+stones[i+1]-dp[i+1][i+l-1], prefixSum[i+l-2]-prefixSum[i]+stones[i]-dp[i][i+l-2])
+ }
+ }
+ return dp[0][n-1]
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/1690.Stone-Game-VII/1690. Stone Game VII_test.go b/leetcode/1690.Stone-Game-VII/1690. Stone Game VII_test.go
new file mode 100644
index 00000000..60656ac9
--- /dev/null
+++ b/leetcode/1690.Stone-Game-VII/1690. Stone Game VII_test.go
@@ -0,0 +1,47 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1690 struct {
+ para1690
+ ans1690
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1690 struct {
+ stones []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1690 struct {
+ one int
+}
+
+func Test_Problem1690(t *testing.T) {
+
+ qs := []question1690{
+
+ {
+ para1690{[]int{5, 3, 1, 4, 2}},
+ ans1690{6},
+ },
+
+ {
+ para1690{[]int{7, 90, 5, 1, 100, 10, 10, 2}},
+ ans1690{122},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1690------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1690, q.para1690
+ fmt.Printf("【input】:%v 【output】:%v\n", p, stoneGameVII(p.stones))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1690.Stone-Game-VII/README.md b/leetcode/1690.Stone-Game-VII/README.md
new file mode 100644
index 00000000..c7b618ac
--- /dev/null
+++ b/leetcode/1690.Stone-Game-VII/README.md
@@ -0,0 +1,130 @@
+# [1690. Stone Game VII](https://leetcode.com/problems/stone-game-vii/)
+
+## 题目
+
+Alice and Bob take turns playing a game, with **Alice starting first**.
+
+There are `n` stones arranged in a row. On each player's turn, they can **remove** either the leftmost stone or the rightmost stone from the row and receive points equal to the **sum** of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.
+
+Bob found that he will always lose this game (poor Bob, he always loses), so he decided to **minimize the score's difference**. Alice's goal is to **maximize the difference** in the score.
+
+Given an array of integers `stones` where `stones[i]` represents the value of the `ith` stone **from the left**, return *the **difference** in Alice and Bob's score if they both play **optimally**.*
+
+**Example 1:**
+
+```
+Input: stones = [5,3,1,4,2]
+Output: 6
+Explanation:
+- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].
+- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].
+- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].
+- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].
+- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].
+The score difference is 18 - 12 = 6.
+```
+
+**Example 2:**
+
+```
+Input: stones = [7,90,5,1,100,10,10,2]
+Output: 122
+```
+
+**Constraints:**
+
+- `n == stones.length`
+- `2 <= n <= 1000`
+- `1 <= stones[i] <= 1000`
+
+## 题目大意
+
+石子游戏中,爱丽丝和鲍勃轮流进行自己的回合,爱丽丝先开始 。有 n 块石子排成一排。每个玩家的回合中,可以从行中 移除 最左边的石头或最右边的石头,并获得与该行中剩余石头值之 和 相等的得分。当没有石头可移除时,得分较高者获胜。鲍勃发现他总是输掉游戏(可怜的鲍勃,他总是输),所以他决定尽力 减小得分的差值 。爱丽丝的目标是最大限度地 扩大得分的差值 。
+
+给你一个整数数组 stones ,其中 stones[i] 表示 从左边开始 的第 i 个石头的值,如果爱丽丝和鲍勃都 发挥出最佳水平 ,请返回他们 得分的差值 。
+
+## 解题思路
+
+- 首先考虑 Bob 缩小分值差距意味着什么,意味着他想让他和 Alice 相对分数最小。Bob 已经明确肯定是输,所以他的分数一定比 Alice 小,那么 Bob - Alice 分数相减一定是负数。相对分数越小,意味着差值越大。负数越大,差值越小。-50 和 -10,-10 数值大,相差小。所以 Bob 的操作是让相对分数越大。Alice 的目的也是这样,要让 Alice - Bob 的相对分数越大,这里是正数的越大。综上,两者的目的相同,都是让相对分数最大化。
+- 定义 `dp[i][j]` 代表在当前 `stone[i ~ j]` 区间内能获得的最大分差。状态转移方程为:
+
+ ```go
+ dp[i][j] = max(
+ sum(i + 1, j) - dp[i + 1][j], // 这一局取走 `stone[i]`,获得 sum(i + 1, j) 分数,再减去剩下对手能获得的分数,即是此局能获得的最大分差。
+ sum(i, j - 1) - dp[i][j - 1] // 这一局取走 `stone[j]`,获得 sum(i, j - 1) 分数,再减去剩下对手能获得的分数,即是此局能获得的最大分差。
+ )
+ ```
+
+ 计算 `sum(i + 1, j) = stone[i + 1] + stone[i + 2] + …… + stone[j]` 利用前缀和计算区间和。
+
+- 解法二是正常思路解答出来的代码。解法一是压缩了 DP 数组,在 DP 状态转移的时候,生成下一个 `dp[j]` 实际上是有规律的。利用这个规律可以少存一维数据,压缩空间。解法一的代码直接写出来,比较难想。先写出解法二的代码,然后找到递推规律,优化空间压缩一维,再写出解法一的代码。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 优化空间版 DP
+func stoneGameVII(stones []int) int {
+ n := len(stones)
+ sum := make([]int, n)
+ dp := make([]int, n)
+ for i, d := range stones {
+ sum[i] = d
+ }
+ for i := 1; i < n; i++ {
+ for j := 0; j+i < n; j++ {
+ if (n-i)%2 == 1 {
+ d0 := dp[j] + sum[j]
+ d1 := dp[j+1] + sum[j+1]
+ if d0 > d1 {
+ dp[j] = d0
+ } else {
+ dp[j] = d1
+ }
+ } else {
+ d0 := dp[j] - sum[j]
+ d1 := dp[j+1] - sum[j+1]
+ if d0 < d1 {
+ dp[j] = d0
+ } else {
+ dp[j] = d1
+ }
+ }
+ sum[j] = sum[j] + stones[i+j]
+ }
+ }
+ return dp[0]
+}
+
+// 解法二 常规 DP
+func stoneGameVII1(stones []int) int {
+ prefixSum := make([]int, len(stones))
+ for i := 0; i < len(stones); i++ {
+ if i == 0 {
+ prefixSum[i] = stones[i]
+ } else {
+ prefixSum[i] = prefixSum[i-1] + stones[i]
+ }
+ }
+ dp := make([][]int, len(stones))
+ for i := range dp {
+ dp[i] = make([]int, len(stones))
+ dp[i][i] = 0
+ }
+ n := len(stones)
+ for l := 2; l <= n; l++ {
+ for i := 0; i+l <= n; i++ {
+ dp[i][i+l-1] = max(prefixSum[i+l-1]-prefixSum[i+1]+stones[i+1]-dp[i+1][i+l-1], prefixSum[i+l-2]-prefixSum[i]+stones[i]-dp[i][i+l-2])
+ }
+ }
+ return dp[0][n-1]
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number.go b/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number.go
new file mode 100644
index 00000000..22a8d666
--- /dev/null
+++ b/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number.go
@@ -0,0 +1,37 @@
+package leetcode
+
+import (
+ "strings"
+)
+
+func reformatNumber(number string) string {
+ parts, nums := []string{}, []rune{}
+ for _, r := range number {
+ if r != '-' && r != ' ' {
+ nums = append(nums, r)
+ }
+ }
+ threeDigits, twoDigits := len(nums)/3, 0
+ switch len(nums) % 3 {
+ case 1:
+ threeDigits--
+ twoDigits = 2
+ case 2:
+ twoDigits = 1
+ default:
+ twoDigits = 0
+ }
+ for i := 0; i < threeDigits; i++ {
+ s := ""
+ s += string(nums[0:3])
+ nums = nums[3:]
+ parts = append(parts, s)
+ }
+ for i := 0; i < twoDigits; i++ {
+ s := ""
+ s += string(nums[0:2])
+ nums = nums[2:]
+ parts = append(parts, s)
+ }
+ return strings.Join(parts, "-")
+}
diff --git a/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number_test.go b/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number_test.go
new file mode 100644
index 00000000..8eb4f7a1
--- /dev/null
+++ b/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number_test.go
@@ -0,0 +1,67 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1694 struct {
+ para1694
+ ans1694
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1694 struct {
+ number string
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1694 struct {
+ one string
+}
+
+func Test_Problem1694(t *testing.T) {
+
+ qs := []question1694{
+
+ {
+ para1694{"1-23-45 6"},
+ ans1694{"123-456"},
+ },
+
+ {
+ para1694{"123 4-567"},
+ ans1694{"123-45-67"},
+ },
+
+ {
+ para1694{"123 4-5678"},
+ ans1694{"123-456-78"},
+ },
+
+ {
+ para1694{"12"},
+ ans1694{"12"},
+ },
+
+ {
+ para1694{"--17-5 229 35-39475 "},
+ ans1694{"175-229-353-94-75"},
+ },
+
+ {
+ para1694{"9964-"},
+ ans1694{"99-64"},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1694------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1694, q.para1694
+ fmt.Printf("【input】:%v 【output】:%v\n", p, reformatNumber(p.number))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1694.Reformat-Phone-Number/README.md b/leetcode/1694.Reformat-Phone-Number/README.md
new file mode 100644
index 00000000..670aae71
--- /dev/null
+++ b/leetcode/1694.Reformat-Phone-Number/README.md
@@ -0,0 +1,135 @@
+# [1694. Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number/)
+
+
+## 题目
+
+You are given a phone number as a string `number`. `number` consists of digits, spaces `' '`, and/or dashes `'-'`.
+
+You would like to reformat the phone number in a certain manner. Firstly, **remove** all spaces and dashes. Then, **group** the digits from left to right into blocks of length 3 **until** there are 4 or fewer digits. The final digits are then grouped as follows:
+
+- 2 digits: A single block of length 2.
+- 3 digits: A single block of length 3.
+- 4 digits: Two blocks of length 2 each.
+
+The blocks are then joined by dashes. Notice that the reformatting process should **never** produce any blocks of length 1 and produce **at most** two blocks of length 2.
+
+Return *the phone number after formatting.*
+
+**Example 1:**
+
+```
+Input: number = "1-23-45 6"
+Output: "123-456"
+Explanation: The digits are "123456".
+Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".
+Step 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is "456".
+Joining the blocks gives "123-456".
+
+```
+
+**Example 2:**
+
+```
+Input: number = "123 4-567"
+Output: "123-45-67"
+Explanation: The digits are "1234567".
+Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".
+Step 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are "45" and "67".
+Joining the blocks gives "123-45-67".
+
+```
+
+**Example 3:**
+
+```
+Input: number = "123 4-5678"
+Output: "123-456-78"
+Explanation: The digits are "12345678".
+Step 1: The 1st block is "123".
+Step 2: The 2nd block is "456".
+Step 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is "78".
+Joining the blocks gives "123-456-78".
+
+```
+
+**Example 4:**
+
+```
+Input: number = "12"
+Output: "12"
+
+```
+
+**Example 5:**
+
+```
+Input: number = "--17-5 229 35-39475 "
+Output: "175-229-353-94-75"
+
+```
+
+**Constraints:**
+
+- `2 <= number.length <= 100`
+- `number` consists of digits and the characters `'-'` and `' '`.
+- There are at least **two** digits in `number`.
+
+## 题目大意
+
+给你一个字符串形式的电话号码 number 。number 由数字、空格 ' '、和破折号 '-' 组成。
+
+请你按下述方式重新格式化电话号码。
+
+- 首先,删除 所有的空格和破折号。
+- 其次,将数组从左到右 每 3 个一组 分块,直到 剩下 4 个或更少数字。剩下的数字将按下述规定再分块:
+ - 2 个数字:单个含 2 个数字的块。
+ - 3 个数字:单个含 3 个数字的块。
+ - 4 个数字:两个分别含 2 个数字的块。
+
+最后用破折号将这些块连接起来。注意,重新格式化过程中 不应该 生成仅含 1 个数字的块,并且 最多 生成两个含 2 个数字的块。返回格式化后的电话号码。
+
+## 解题思路
+
+- 简单题。先判断号码是不是 2 位和 4 位,如果是,单独输出这 2 种情况。剩下的都是 3 位以上了,取余,判断剩余的数字是 2 个还是 4 个。这时不可能存在剩 1 位数的情况。除 3 余 1,即剩 4 位的情况,末尾 4 位需要 2 个一组输出。除 3 余 2,即剩 2 位的情况。处理好末尾,再逆序每 3 个一组连接 "-" 即可。可能需要注意的 case 见 test 文件。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "strings"
+)
+
+func reformatNumber(number string) string {
+ parts, nums := []string{}, []rune{}
+ for _, r := range number {
+ if r != '-' && r != ' ' {
+ nums = append(nums, r)
+ }
+ }
+ threeDigits, twoDigits := len(nums)/3, 0
+ switch len(nums) % 3 {
+ case 1:
+ threeDigits--
+ twoDigits = 2
+ case 2:
+ twoDigits = 1
+ default:
+ twoDigits = 0
+ }
+ for i := 0; i < threeDigits; i++ {
+ s := ""
+ s += string(nums[0:3])
+ nums = nums[3:]
+ parts = append(parts, s)
+ }
+ for i := 0; i < twoDigits; i++ {
+ s := ""
+ s += string(nums[0:2])
+ nums = nums[2:]
+ parts = append(parts, s)
+ }
+ return strings.Join(parts, "-")
+}
+```
\ No newline at end of file
diff --git a/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value.go b/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value.go
new file mode 100644
index 00000000..ccca3f96
--- /dev/null
+++ b/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value.go
@@ -0,0 +1,30 @@
+package leetcode
+
+func maximumUniqueSubarray(nums []int) int {
+ if len(nums) == 0 {
+ return 0
+ }
+ result, left, right, freq := 0, 0, -1, map[int]int{}
+ for left < len(nums) {
+ if right+1 < len(nums) && freq[nums[right+1]] == 0 {
+ freq[nums[right+1]]++
+ right++
+ } else {
+ freq[nums[left]]--
+ left++
+ }
+ sum := 0
+ for i := left; i <= right; i++ {
+ sum += nums[i]
+ }
+ result = max(result, sum)
+ }
+ return result
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value_test.go b/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value_test.go
new file mode 100644
index 00000000..bc088cda
--- /dev/null
+++ b/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value_test.go
@@ -0,0 +1,47 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1695 struct {
+ para1695
+ ans1695
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1695 struct {
+ nums []int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1695 struct {
+ one int
+}
+
+func Test_Problem1695(t *testing.T) {
+
+ qs := []question1695{
+
+ {
+ para1695{[]int{4, 2, 4, 5, 6}},
+ ans1695{17},
+ },
+
+ {
+ para1695{[]int{5, 2, 1, 2, 5, 2, 1, 2, 5}},
+ ans1695{8},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1695------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1695, q.para1695
+ fmt.Printf("【input】:%v 【output】:%v\n", p, maximumUniqueSubarray(p.nums))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1695.Maximum-Erasure-Value/README.md b/leetcode/1695.Maximum-Erasure-Value/README.md
new file mode 100644
index 00000000..a2dec532
--- /dev/null
+++ b/leetcode/1695.Maximum-Erasure-Value/README.md
@@ -0,0 +1,74 @@
+# [1695. Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/)
+
+
+## 题目
+
+You are given an array of positive integers `nums` and want to erase a subarray containing **unique elements**. The **score** you get by erasing the subarray is equal to the **sum** of its elements.
+
+Return *the **maximum score** you can get by erasing **exactly one** subarray.*
+
+An array `b` is called to be a subarray of `a` if it forms a contiguous subsequence of `a`, that is, if it is equal to `a[l],a[l+1],...,a[r]` for some `(l,r)`.
+
+**Example 1:**
+
+```
+Input: nums = [4,2,4,5,6]
+Output: 17
+Explanation: The optimal subarray here is [2,4,5,6].
+```
+
+**Example 2:**
+
+```
+Input: nums = [5,2,1,2,5,2,1,2,5]
+Output: 8
+Explanation: The optimal subarray here is [5,2,1] or [1,2,5].
+```
+
+**Constraints:**
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 104`
+
+## 题目大意
+
+给你一个正整数数组 nums ,请你从中删除一个含有 若干不同元素 的子数组。删除子数组的 得分 就是子数组各元素之 和 。返回 只删除一个 子数组可获得的 最大得分 。如果数组 b 是数组 a 的一个连续子序列,即如果它等于 a[l],a[l+1],...,a[r] ,那么它就是 a 的一个子数组。
+
+## 解题思路
+
+- 读完题立马能识别出这是经典的滑动窗口题。利用滑动窗口从左往右滑动窗口,滑动过程中统计频次,如果是不同元素,右边界窗口又移,否则左边窗口缩小。每次移动更新 max 值。最终扫完一遍以后,max 值即为所求。
+
+## 代码
+
+```go
+package leetcode
+
+func maximumUniqueSubarray(nums []int) int {
+ if len(nums) == 0 {
+ return 0
+ }
+ result, left, right, freq := 0, 0, -1, map[int]int{}
+ for left < len(nums) {
+ if right+1 < len(nums) && freq[nums[right+1]] == 0 {
+ freq[nums[right+1]]++
+ right++
+ } else {
+ freq[nums[left]]--
+ left++
+ }
+ sum := 0
+ for i := left; i <= right; i++ {
+ sum += nums[i]
+ }
+ result = max(result, sum)
+ }
+ return result
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/leetcode/1696.Jump-Game-VI/1696. Jump Game VI.go b/leetcode/1696.Jump-Game-VI/1696. Jump Game VI.go
new file mode 100644
index 00000000..b57b2500
--- /dev/null
+++ b/leetcode/1696.Jump-Game-VI/1696. Jump Game VI.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "math"
+)
+
+// 单调队列
+func maxResult(nums []int, k int) int {
+ dp := make([]int, len(nums))
+ dp[0] = nums[0]
+ for i := 1; i < len(dp); i++ {
+ dp[i] = math.MinInt32
+ }
+ window := make([]int, k)
+ for i := 1; i < len(nums); i++ {
+ dp[i] = nums[i] + dp[window[0]]
+ for len(window) > 0 && dp[window[len(window)-1]] <= dp[i] {
+ window = window[:len(window)-1]
+ }
+ for len(window) > 0 && i-k >= window[0] {
+ window = window[1:]
+ }
+ window = append(window, i)
+ }
+ return dp[len(nums)-1]
+}
+
+// 超时
+func maxResult1(nums []int, k int) int {
+ dp := make([]int, len(nums))
+ if k > len(nums) {
+ k = len(nums)
+ }
+ dp[0] = nums[0]
+ for i := 1; i < len(dp); i++ {
+ dp[i] = math.MinInt32
+ }
+ for i := 1; i < len(nums); i++ {
+ left, tmp := max(0, i-k), math.MinInt32
+ for j := left; j < i; j++ {
+ tmp = max(tmp, dp[j])
+ }
+ dp[i] = nums[i] + tmp
+ }
+ return dp[len(nums)-1]
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/leetcode/1696.Jump-Game-VI/1696. Jump Game VI_test.go b/leetcode/1696.Jump-Game-VI/1696. Jump Game VI_test.go
new file mode 100644
index 00000000..63a7dcc1
--- /dev/null
+++ b/leetcode/1696.Jump-Game-VI/1696. Jump Game VI_test.go
@@ -0,0 +1,53 @@
+package leetcode
+
+import (
+ "fmt"
+ "testing"
+)
+
+type question1690 struct {
+ para1690
+ ans1690
+}
+
+// para 是参数
+// one 代表第一个参数
+type para1690 struct {
+ nums []int
+ k int
+}
+
+// ans 是答案
+// one 代表第一个答案
+type ans1690 struct {
+ one int
+}
+
+func Test_Problem1690(t *testing.T) {
+
+ qs := []question1690{
+
+ // {
+ // para1690{[]int{1, -1, -2, 4, -7, 3}, 2},
+ // ans1690{7},
+ // },
+
+ // {
+ // para1690{[]int{10, -5, -2, 4, 0, 3}, 3},
+ // ans1690{17},
+ // },
+
+ {
+ para1690{[]int{1, -5, -20, 4, -1, 3, -6, -3}, 2},
+ ans1690{0},
+ },
+ }
+
+ fmt.Printf("------------------------Leetcode Problem 1690------------------------\n")
+
+ for _, q := range qs {
+ _, p := q.ans1690, q.para1690
+ fmt.Printf("【input】:%v 【output】:%v\n", p, maxResult(p.nums, p.k))
+ }
+ fmt.Printf("\n\n\n")
+}
diff --git a/leetcode/1696.Jump-Game-VI/README.md b/leetcode/1696.Jump-Game-VI/README.md
new file mode 100644
index 00000000..5a2ae245
--- /dev/null
+++ b/leetcode/1696.Jump-Game-VI/README.md
@@ -0,0 +1,109 @@
+# [1696. Jump Game VI](https://leetcode.com/problems/jump-game-vi/)
+
+## 题目
+
+You are given a **0-indexed** integer array `nums` and an integer `k`.
+
+You are initially standing at index `0`. In one move, you can jump at most `k` steps forward without going outside the boundaries of the array. That is, you can jump from index `i` to any index in the range `[i + 1, min(n - 1, i + k)]` **inclusive**.
+
+You want to reach the last index of the array (index `n - 1`). Your **score** is the **sum** of all `nums[j]` for each index `j` you visited in the array.
+
+Return *the **maximum score** you can get*.
+
+**Example 1:**
+
+```
+Input: nums = [1,-1,-2,4,-7,3], k = 2
+Output: 7
+Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.
+
+```
+
+**Example 2:**
+
+```
+Input: nums = [10,-5,-2,4,0,3], k = 3
+Output: 17
+Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.
+
+```
+
+**Example 3:**
+
+```
+Input: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2
+Output: 0
+
+```
+
+**Constraints:**
+
+- `1 <= nums.length, k <= 10^5`
+- `10^4 <= nums[i] <= 10^4`
+
+## 题目大意
+
+给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。一开始你在下标 0 处。每一步,你最多可以往前跳 k 步,但你不能跳出数组的边界。也就是说,你可以从下标 i 跳到 [i + 1, min(n - 1, i + k)] 包含 两个端点的任意位置。你的目标是到达数组最后一个位置(下标为 n - 1 ),你的 得分 为经过的所有数字之和。请你返回你能得到的 最大得分 。
+
+## 解题思路
+
+- 首先能想到的解题思路是动态规划。定义 `dp[i]` 为跳到第 `i` 个位子能获得的最大分数。题目要求的是 `dp[n-1]`,状态转移方程是:`dp[i] = nums[i] + max(dp[j]), max(0, i - k ) <= j < i`,这里需要注意 `j` 的下界,题目中说到不能跳到负数区间,所以左边界下界为 0 。求 `max(dp[j])` 需要遍历一次求得最大值,所以这个解法整体时间复杂度是 O((n - k) * k),但是提交以后提示超时了。
+- 分析一下超时原因。每次都要在 `[max(0, i - k ), i)` 区间内扫描找到最大值,下一轮的区间是 `[max(0, i - k + 1), i + 1)`,前后这两轮扫描的区间存在大量重合部分 `[max(0, i - k + 1), i)`,正是这部分反反复复的扫描导致算法低效。如何高效的在一个区间内找到最大值是本题的关键。利用单调队列可以完成此题。单调队列里面存一个区间内最大值的下标。这里单调队列有 2 个性质。性质一,队列的队首永远都是最大值,队列从大到小降序排列。如果来了一个比队首更大的值的下标,需要将单调队列清空,只存这个新的最大值的下标。性质二,队列的长度为 k。从队尾插入新值,并把队头的最大值“挤”出队首。拥有了这个单调队列以后,再进行 DP 状态转移,效率就很高了。每次只需取出队首的最大值即可。具体代码见下面。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math"
+)
+
+// 单调队列
+func maxResult(nums []int, k int) int {
+ dp := make([]int, len(nums))
+ dp[0] = nums[0]
+ for i := 1; i < len(dp); i++ {
+ dp[i] = math.MinInt32
+ }
+ window := make([]int, k)
+ for i := 1; i < len(nums); i++ {
+ dp[i] = nums[i] + dp[window[0]]
+ for len(window) > 0 && dp[window[len(window)-1]] <= dp[i] {
+ window = window[:len(window)-1]
+ }
+ for len(window) > 0 && i-k >= window[0] {
+ window = window[1:]
+ }
+ window = append(window, i)
+ }
+ return dp[len(nums)-1]
+}
+
+// 超时
+func maxResult1(nums []int, k int) int {
+ dp := make([]int, len(nums))
+ if k > len(nums) {
+ k = len(nums)
+ }
+ dp[0] = nums[0]
+ for i := 1; i < len(dp); i++ {
+ dp[i] = math.MinInt32
+ }
+ for i := 1; i < len(nums); i++ {
+ left, tmp := max(0, i-k), math.MinInt32
+ for j := left; j < i; j++ {
+ tmp = max(tmp, dp[j])
+ }
+ dp[i] = nums[i] + tmp
+ }
+ return dp[len(nums)-1]
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
\ No newline at end of file
diff --git a/template/LFUCache.go b/template/LFUCache.go
new file mode 100644
index 00000000..74a8a9a9
--- /dev/null
+++ b/template/LFUCache.go
@@ -0,0 +1,196 @@
+package template
+
+import "container/list"
+
+// LFUCache define
+type LFUCache struct {
+ nodes map[int]*list.Element
+ lists map[int]*list.List
+ capacity int
+ min int
+}
+
+type node struct {
+ key int
+ value int
+ frequency int
+}
+
+// Constructor define
+func Constructor(capacity int) LFUCache {
+ return LFUCache{nodes: make(map[int]*list.Element),
+ lists: make(map[int]*list.List),
+ capacity: capacity,
+ min: 0,
+ }
+}
+
+// Get define
+func (lfuCache *LFUCache) Get(key int) int {
+ value, ok := lfuCache.nodes[key]
+ if !ok {
+ return -1
+ }
+ currentNode := value.Value.(*node)
+ lfuCache.lists[currentNode.frequency].Remove(value)
+ currentNode.frequency++
+ if _, ok := lfuCache.lists[currentNode.frequency]; !ok {
+ lfuCache.lists[currentNode.frequency] = list.New()
+ }
+ newList := lfuCache.lists[currentNode.frequency]
+ newNode := newList.PushFront(currentNode)
+ lfuCache.nodes[key] = newNode
+ if currentNode.frequency-1 == lfuCache.min && lfuCache.lists[currentNode.frequency-1].Len() == 0 {
+ lfuCache.min++
+ }
+ return currentNode.value
+}
+
+// Put define
+func (lfuCache *LFUCache) Put(key int, value int) {
+ if lfuCache.capacity == 0 {
+ return
+ }
+ if currentValue, ok := lfuCache.nodes[key]; ok {
+ currentNode := currentValue.Value.(*node)
+ currentNode.value = value
+ lfuCache.Get(key)
+ return
+ }
+ if lfuCache.capacity == len(lfuCache.nodes) {
+ currentList := lfuCache.lists[lfuCache.min]
+ backNode := currentList.Back()
+ delete(lfuCache.nodes, backNode.Value.(*node).key)
+ currentList.Remove(backNode)
+ }
+ lfuCache.min = 1
+ currentNode := &node{
+ key: key,
+ value: value,
+ frequency: 1,
+ }
+ if _, ok := lfuCache.lists[1]; !ok {
+ lfuCache.lists[1] = list.New()
+ }
+ newList := lfuCache.lists[1]
+ newNode := newList.PushFront(currentNode)
+ lfuCache.nodes[key] = newNode
+}
+
+/**
+ * Your LFUCache object will be instantiated and called as such:
+ * obj := Constructor(capacity);
+ * param_1 := obj.Get(key);
+ * obj.Put(key,value);
+ */
+
+// Index Priority Queue
+// import "container/heap"
+
+// type LFUCache struct {
+// capacity int
+// pq PriorityQueue
+// hash map[int]*Item
+// counter int
+// }
+
+// func Constructor(capacity int) LFUCache {
+// lfu := LFUCache{
+// pq: PriorityQueue{},
+// hash: make(map[int]*Item, capacity),
+// capacity: capacity,
+// }
+// return lfu
+// }
+
+// func (this *LFUCache) Get(key int) int {
+// if this.capacity == 0 {
+// return -1
+// }
+// if item, ok := this.hash[key]; ok {
+// this.counter++
+// this.pq.update(item, item.value, item.frequency+1, this.counter)
+// return item.value
+// }
+// return -1
+// }
+
+// func (this *LFUCache) Put(key int, value int) {
+// if this.capacity == 0 {
+// return
+// }
+// // fmt.Printf("Put %d\n", key)
+// this.counter++
+// // 如果存在,增加 frequency,再调整堆
+// if item, ok := this.hash[key]; ok {
+// this.pq.update(item, value, item.frequency+1, this.counter)
+// return
+// }
+// // 如果不存在且缓存满了,需要删除。在 hashmap 和 pq 中删除。
+// if len(this.pq) == this.capacity {
+// item := heap.Pop(&this.pq).(*Item)
+// delete(this.hash, item.key)
+// }
+// // 新建结点,在 hashmap 和 pq 中添加。
+// item := &Item{
+// value: value,
+// key: key,
+// count: this.counter,
+// }
+// heap.Push(&this.pq, item)
+// this.hash[key] = item
+// }
+
+// // An Item is something we manage in a priority queue.
+// type Item struct {
+// value int // The value of the item; arbitrary.
+// key int
+// frequency int // The priority of the item in the queue.
+// count int // use for evicting the oldest element
+// // The index is needed by update and is maintained by the heap.Interface methods.
+// index int // The index of the item in the heap.
+// }
+
+// // A PriorityQueue implements heap.Interface and holds Items.
+// type PriorityQueue []*Item
+
+// func (pq PriorityQueue) Len() int { return len(pq) }
+
+// func (pq PriorityQueue) Less(i, j int) bool {
+// // We want Pop to give us the highest, not lowest, priority so we use greater than here.
+// if pq[i].frequency == pq[j].frequency {
+// return pq[i].count < pq[j].count
+// }
+// return pq[i].frequency < pq[j].frequency
+// }
+
+// func (pq PriorityQueue) Swap(i, j int) {
+// pq[i], pq[j] = pq[j], pq[i]
+// pq[i].index = i
+// pq[j].index = j
+// }
+
+// func (pq *PriorityQueue) Push(x interface{}) {
+// n := len(*pq)
+// item := x.(*Item)
+// item.index = n
+// *pq = append(*pq, item)
+// }
+
+// func (pq *PriorityQueue) Pop() interface{} {
+// old := *pq
+// n := len(old)
+// item := old[n-1]
+// old[n-1] = nil // avoid memory leak
+// item.index = -1 // for safety
+// *pq = old[0 : n-1]
+// return item
+// }
+
+// // update modifies the priority and value of an Item in the queue.
+// func (pq *PriorityQueue) update(item *Item, value int, frequency int, count int) {
+// item.value = value
+// item.count = count
+// item.frequency = frequency
+// heap.Fix(pq, item.index)
+// }
diff --git a/template/LRUCache.go b/template/LRUCache.go
new file mode 100644
index 00000000..581f42a8
--- /dev/null
+++ b/template/LRUCache.go
@@ -0,0 +1,139 @@
+package template
+
+// LRUCache define
+type LRUCache struct {
+ head, tail *Node
+ keys map[int]*Node
+ capacity int
+}
+
+// Node define
+type Node struct {
+ key, val int
+ prev, next *Node
+}
+
+// ConstructorLRU define
+func ConstructorLRU(capacity int) LRUCache {
+ return LRUCache{keys: make(map[int]*Node), capacity: capacity}
+}
+
+// Get define
+func (lruCache *LRUCache) Get(key int) int {
+ if node, ok := lruCache.keys[key]; ok {
+ lruCache.Remove(node)
+ lruCache.Add(node)
+ return node.val
+ }
+ return -1
+}
+
+// Put define
+func (lruCache *LRUCache) Put(key int, value int) {
+ node, ok := lruCache.keys[key]
+ if ok {
+ node.val = value
+ lruCache.Remove(node)
+ lruCache.Add(node)
+ return
+ }
+ node = &Node{key: key, val: value}
+ lruCache.keys[key] = node
+ lruCache.Add(node)
+ if len(lruCache.keys) > lruCache.capacity {
+ delete(lruCache.keys, lruCache.tail.key)
+ lruCache.Remove(lruCache.tail)
+ }
+}
+
+// Add define
+func (lruCache *LRUCache) Add(node *Node) {
+ node.prev = nil
+ node.next = lruCache.head
+ if lruCache.head != nil {
+ lruCache.head.prev = node
+ }
+ lruCache.head = node
+ if lruCache.tail == nil {
+ lruCache.tail = node
+ lruCache.tail.next = nil
+ }
+}
+
+// Remove define
+func (lruCache *LRUCache) Remove(node *Node) {
+ if node == lruCache.head {
+ lruCache.head = node.next
+ if node.next != nil {
+ node.next.prev = nil
+ }
+ node.next = nil
+ return
+ }
+ if node == lruCache.tail {
+ lruCache.tail = node.prev
+ node.prev.next = nil
+ node.prev = nil
+ return
+ }
+ node.prev.next = node.next
+ node.next.prev = node.prev
+}
+
+/**
+ * Your LRUCache object will be instantiated and called as such:
+ * obj := Constructor(capacity);
+ * param_1 := obj.Get(key);
+ * obj.Put(key,value);
+ */
+
+// 22%
+// import "container/list"
+
+// type LRUCache struct {
+// Cap int
+// Keys map[int]*list.Element
+// List *list.List
+// }
+
+// type pair struct {
+// K, V int
+// }
+
+// func Constructor(capacity int) LRUCache {
+// return LRUCache{
+// Cap: capacity,
+// Keys: make(map[int]*list.Element),
+// List: list.New(),
+// }
+// }
+
+// func (c *LRUCache) Get(key int) int {
+// if el, ok := c.Keys[key]; ok {
+// c.List.MoveToFront(el)
+// return el.Value.(pair).V
+// }
+// return -1
+// }
+
+// func (c *LRUCache) Put(key int, value int) {
+// if el, ok := c.Keys[key]; ok {
+// el.Value = pair{K: key, V: value}
+// c.List.MoveToFront(el)
+// } else {
+// el := c.List.PushFront(pair{K: key, V: value})
+// c.Keys[key] = el
+// }
+// if c.List.Len() > c.Cap {
+// el := c.List.Back()
+// c.List.Remove(el)
+// delete(c.Keys, el.Value.(pair).K)
+// }
+// }
+
+/**
+ * Your LRUCache object will be instantiated and called as such:
+ * obj := Constructor(capacity);
+ * param_1 := obj.Get(key);
+ * obj.Put(key,value);
+ */
diff --git a/website/config.toml b/website/config.toml
index 271cbc46..ce6e14c2 100644
--- a/website/config.toml
+++ b/website/config.toml
@@ -46,14 +46,18 @@ disablePathToLower = true
name = "Github"
url = "https://github.com/halfrost"
weight = 20
+[[menu.before]]
+ name = "WeChat Official Accounts"
+ url = "https://img.halfrost.com/wechat-qr-code.png"
+ weight = 30
[[menu.before]]
name = "Twitter"
url = "https://twitter.com/halffrost"
- weight = 30
+ weight = 40
[[menu.before]]
name = "Weibo"
url = "https://weibo.com/halfrost"
- weight = 40
+ weight = 50
#[[menu.after]]
# name = "Github"
# url = "https://github.com/alex-shpak/hugo-book"
diff --git a/website/content/ChapterFour/0001.Two-Sum.md b/website/content/ChapterFour/0001.Two-Sum.md
index 469d1d19..a45c6f51 100644
--- a/website/content/ChapterFour/0001.Two-Sum.md
+++ b/website/content/ChapterFour/0001.Two-Sum.md
@@ -47,4 +47,11 @@ func twoSum(nums []int, target int) []int {
return nil
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0002.Add-Two-Numbers.md b/website/content/ChapterFour/0002.Add-Two-Numbers.md
index c30fb0ef..090c9379 100644
--- a/website/content/ChapterFour/0002.Add-Two-Numbers.md
+++ b/website/content/ChapterFour/0002.Add-Two-Numbers.md
@@ -75,4 +75,11 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
return head.Next
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md b/website/content/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md
index 36e027da..19d3329b 100644
--- a/website/content/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md
+++ b/website/content/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md
@@ -122,3 +122,10 @@ func max(a int, b int) int {
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0004.Median-of-Two-Sorted-Arrays.md b/website/content/ChapterFour/0004.Median-of-Two-Sorted-Arrays.md
index 9ad0c55b..e8821397 100755
--- a/website/content/ChapterFour/0004.Median-of-Two-Sorted-Arrays.md
+++ b/website/content/ChapterFour/0004.Median-of-Two-Sorted-Arrays.md
@@ -96,3 +96,10 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0007.Reverse-Integer.md b/website/content/ChapterFour/0007.Reverse-Integer.md
index 801d5088..6f8273ec 100755
--- a/website/content/ChapterFour/0007.Reverse-Integer.md
+++ b/website/content/ChapterFour/0007.Reverse-Integer.md
@@ -53,3 +53,10 @@ func reverse7(x int) int {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0009.Palindrome-Number.md b/website/content/ChapterFour/0009.Palindrome-Number.md
index d01fc716..b74c69ef 100644
--- a/website/content/ChapterFour/0009.Palindrome-Number.md
+++ b/website/content/ChapterFour/0009.Palindrome-Number.md
@@ -66,4 +66,11 @@ func isPalindrome(x int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0011.Container-With-Most-Water.md b/website/content/ChapterFour/0011.Container-With-Most-Water.md
index c8d25a2e..9591c9ef 100644
--- a/website/content/ChapterFour/0011.Container-With-Most-Water.md
+++ b/website/content/ChapterFour/0011.Container-With-Most-Water.md
@@ -57,3 +57,10 @@ func maxArea(height []int) int {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0013.Roman-to-Integer.md b/website/content/ChapterFour/0013.Roman-to-Integer.md
index 44d758eb..5e5ece59 100644
--- a/website/content/ChapterFour/0013.Roman-to-Integer.md
+++ b/website/content/ChapterFour/0013.Roman-to-Integer.md
@@ -129,4 +129,11 @@ func romanToInt(s string) int {
return total
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0015.3Sum.md b/website/content/ChapterFour/0015.3Sum.md
index 454f3aee..ec6ca213 100644
--- a/website/content/ChapterFour/0015.3Sum.md
+++ b/website/content/ChapterFour/0015.3Sum.md
@@ -42,7 +42,44 @@ import (
"sort"
)
+// 解法一 最优解,双指针 + 排序
func threeSum(nums []int) [][]int {
+ sort.Ints(nums)
+ result, start, end, index, addNum, length := make([][]int, 0), 0, 0, 0, 0, len(nums)
+ if length > 0 && (nums[0] > 0 || nums[length-1] < 0) {
+ return result
+ }
+ for index = 1; index < length-1; index++ {
+ start, end = 0, length-1
+ if index > 1 && nums[index] == nums[index-1] {
+ start = index - 1
+ }
+ for start < index && end > index {
+ if start > 0 && nums[start] == nums[start-1] {
+ start++
+ continue
+ }
+ if end < length-1 && nums[end] == nums[end+1] {
+ end--
+ continue
+ }
+ addNum = nums[start] + nums[end] + nums[index]
+ if addNum == 0 {
+ result = append(result, []int{nums[start], nums[index], nums[end]})
+ start++
+ end--
+ } else if addNum > 0 {
+ end--
+ } else {
+ start++
+ }
+ }
+ }
+ return result
+}
+
+// 解法二
+func threeSum1(nums []int) [][]int {
res := [][]int{}
counter := map[int]int{}
for _, value := range nums {
@@ -76,8 +113,16 @@ func threeSum(nums []int) [][]int {
}
+
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0016.3Sum-Closest.md b/website/content/ChapterFour/0016.3Sum-Closest.md
index 19d44e56..117a1935 100644
--- a/website/content/ChapterFour/0016.3Sum-Closest.md
+++ b/website/content/ChapterFour/0016.3Sum-Closest.md
@@ -87,3 +87,10 @@ func abs(a int) int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md b/website/content/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md
index 8de0f911..e6cc6cf4 100755
--- a/website/content/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md
+++ b/website/content/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md
@@ -142,3 +142,10 @@ func letterFunc(res string, digits string) {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0018.4Sum.md b/website/content/ChapterFour/0018.4Sum.md
index e0f70941..59682039 100644
--- a/website/content/ChapterFour/0018.4Sum.md
+++ b/website/content/ChapterFour/0018.4Sum.md
@@ -95,3 +95,10 @@ func fourSum(nums []int, target int) [][]int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md b/website/content/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md
index 0cb4c9d0..28fe564c 100644
--- a/website/content/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md
+++ b/website/content/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md
@@ -98,3 +98,10 @@ func removeNthFromEnd1(head *ListNode, n int) *ListNode {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0020.Valid-Parentheses.md b/website/content/ChapterFour/0020.Valid-Parentheses.md
index 1df3ba11..77b1b83b 100644
--- a/website/content/ChapterFour/0020.Valid-Parentheses.md
+++ b/website/content/ChapterFour/0020.Valid-Parentheses.md
@@ -94,3 +94,10 @@ func isValid(s string) bool {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0021.Merge-Two-Sorted-Lists.md b/website/content/ChapterFour/0021.Merge-Two-Sorted-Lists.md
index cc559bc3..dd007fe2 100644
--- a/website/content/ChapterFour/0021.Merge-Two-Sorted-Lists.md
+++ b/website/content/ChapterFour/0021.Merge-Two-Sorted-Lists.md
@@ -51,3 +51,10 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0022.Generate-Parentheses.md b/website/content/ChapterFour/0022.Generate-Parentheses.md
index 0e340b39..2188ce03 100755
--- a/website/content/ChapterFour/0022.Generate-Parentheses.md
+++ b/website/content/ChapterFour/0022.Generate-Parentheses.md
@@ -58,3 +58,10 @@ func findGenerateParenthesis(lindex, rindex int, str string, res *[]string) {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0023.Merge-k-Sorted-Lists.md b/website/content/ChapterFour/0023.Merge-k-Sorted-Lists.md
index 3166c480..78a8c5e9 100644
--- a/website/content/ChapterFour/0023.Merge-k-Sorted-Lists.md
+++ b/website/content/ChapterFour/0023.Merge-k-Sorted-Lists.md
@@ -72,3 +72,10 @@ func mergeTwoLists1(l1 *ListNode, l2 *ListNode) *ListNode {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0024.Swap-Nodes-in-Pairs.md b/website/content/ChapterFour/0024.Swap-Nodes-in-Pairs.md
index 017a0eb4..7df959d3 100644
--- a/website/content/ChapterFour/0024.Swap-Nodes-in-Pairs.md
+++ b/website/content/ChapterFour/0024.Swap-Nodes-in-Pairs.md
@@ -69,3 +69,10 @@ func swapPairs(head *ListNode) *ListNode {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0025.Reverse-Nodes-in-k-Group.md b/website/content/ChapterFour/0025.Reverse-Nodes-in-k-Group.md
index 8d6ba27a..cca95bdf 100644
--- a/website/content/ChapterFour/0025.Reverse-Nodes-in-k-Group.md
+++ b/website/content/ChapterFour/0025.Reverse-Nodes-in-k-Group.md
@@ -72,3 +72,10 @@ func reverse(first *ListNode, last *ListNode) *ListNode {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md b/website/content/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md
index b7f1b479..0b32f0ad 100644
--- a/website/content/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md
+++ b/website/content/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md
@@ -126,3 +126,10 @@ func removeElement1(nums []int, start, val int) int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0027.Remove-Element.md b/website/content/ChapterFour/0027.Remove-Element.md
index d3ddc59d..0dc8bb08 100644
--- a/website/content/ChapterFour/0027.Remove-Element.md
+++ b/website/content/ChapterFour/0027.Remove-Element.md
@@ -80,10 +80,8 @@ func removeElement(nums []int, val int) int {
if nums[i] != val {
if i != j {
nums[i], nums[j] = nums[j], nums[i]
- j++
- } else {
- j++
}
+ j++
}
}
return j
@@ -91,3 +89,10 @@ func removeElement(nums []int, val int) int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0028.Implement-strStr.md b/website/content/ChapterFour/0028.Implement-strStr.md
index 4bcbaebb..9ab526ff 100644
--- a/website/content/ChapterFour/0028.Implement-strStr.md
+++ b/website/content/ChapterFour/0028.Implement-strStr.md
@@ -84,3 +84,10 @@ func strStr1(haystack string, needle string) int {
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0029.Divide-Two-Integers.md b/website/content/ChapterFour/0029.Divide-Two-Integers.md
index c3f4a834..5ca4689f 100755
--- a/website/content/ChapterFour/0029.Divide-Two-Integers.md
+++ b/website/content/ChapterFour/0029.Divide-Two-Integers.md
@@ -146,3 +146,10 @@ func divide1(divided int, divisor int) int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md b/website/content/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md
index d4eb4ef0..6f6e762b 100644
--- a/website/content/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md
+++ b/website/content/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md
@@ -96,3 +96,10 @@ func copyMap(s map[string]int) map[string]int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0033.Search-in-Rotated-Sorted-Array.md b/website/content/ChapterFour/0033.Search-in-Rotated-Sorted-Array.md
index ac935c4d..c31b5ed5 100755
--- a/website/content/ChapterFour/0033.Search-in-Rotated-Sorted-Array.md
+++ b/website/content/ChapterFour/0033.Search-in-Rotated-Sorted-Array.md
@@ -76,3 +76,10 @@ func search33(nums []int, target int) int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array.md b/website/content/ChapterFour/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array.md
index 6d991286..5e5f850c 100755
--- a/website/content/ChapterFour/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array.md
+++ b/website/content/ChapterFour/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array.md
@@ -119,3 +119,10 @@ func searchLastLessElement(nums []int, target int) int {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0035.Search-Insert-Position.md b/website/content/ChapterFour/0035.Search-Insert-Position.md
index 18339f1e..554f7c5f 100755
--- a/website/content/ChapterFour/0035.Search-Insert-Position.md
+++ b/website/content/ChapterFour/0035.Search-Insert-Position.md
@@ -63,3 +63,10 @@ func searchInsert(nums []int, target int) int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0036.Valid-Sudoku.md b/website/content/ChapterFour/0036.Valid-Sudoku.md
index 72e8ba47..b180ee60 100755
--- a/website/content/ChapterFour/0036.Valid-Sudoku.md
+++ b/website/content/ChapterFour/0036.Valid-Sudoku.md
@@ -166,3 +166,10 @@ func isValidSudoku1(board [][]byte) bool {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0037.Sudoku-Solver.md b/website/content/ChapterFour/0037.Sudoku-Solver.md
index 724076d3..da7a7c32 100755
--- a/website/content/ChapterFour/0037.Sudoku-Solver.md
+++ b/website/content/ChapterFour/0037.Sudoku-Solver.md
@@ -116,3 +116,10 @@ func checkSudoku(board *[][]byte, pos position, val int) bool {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0039.Combination-Sum.md b/website/content/ChapterFour/0039.Combination-Sum.md
index 6167df45..4f5be48c 100755
--- a/website/content/ChapterFour/0039.Combination-Sum.md
+++ b/website/content/ChapterFour/0039.Combination-Sum.md
@@ -85,3 +85,10 @@ func findcombinationSum(nums []int, target, index int, c []int, res *[][]int) {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0040.Combination-Sum-II.md b/website/content/ChapterFour/0040.Combination-Sum-II.md
index 9d0188a3..36ecc38a 100755
--- a/website/content/ChapterFour/0040.Combination-Sum-II.md
+++ b/website/content/ChapterFour/0040.Combination-Sum-II.md
@@ -87,3 +87,10 @@ func findcombinationSum2(nums []int, target, index int, c []int, res *[][]int) {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0041.First-Missing-Positive.md b/website/content/ChapterFour/0041.First-Missing-Positive.md
index 88564723..6e3915d0 100644
--- a/website/content/ChapterFour/0041.First-Missing-Positive.md
+++ b/website/content/ChapterFour/0041.First-Missing-Positive.md
@@ -64,3 +64,10 @@ func firstMissingPositive(nums []int) int {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0042.Trapping-Rain-Water.md b/website/content/ChapterFour/0042.Trapping-Rain-Water.md
index 1b0dd4b7..9af370ab 100644
--- a/website/content/ChapterFour/0042.Trapping-Rain-Water.md
+++ b/website/content/ChapterFour/0042.Trapping-Rain-Water.md
@@ -59,3 +59,10 @@ func trap(height []int) int {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0046.Permutations.md b/website/content/ChapterFour/0046.Permutations.md
index 6ddd55f4..1be0d0d2 100755
--- a/website/content/ChapterFour/0046.Permutations.md
+++ b/website/content/ChapterFour/0046.Permutations.md
@@ -64,3 +64,10 @@ func generatePermutation(nums []int, index int, p []int, res *[][]int, used *[]b
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0047.Permutations-II.md b/website/content/ChapterFour/0047.Permutations-II.md
index ff63b687..cd0a38d8 100755
--- a/website/content/ChapterFour/0047.Permutations-II.md
+++ b/website/content/ChapterFour/0047.Permutations-II.md
@@ -68,3 +68,10 @@ func generatePermutation47(nums []int, index int, p []int, res *[][]int, used *[
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0048.Rotate-Image.md b/website/content/ChapterFour/0048.Rotate-Image.md
index 48d11b65..2913142a 100755
--- a/website/content/ChapterFour/0048.Rotate-Image.md
+++ b/website/content/ChapterFour/0048.Rotate-Image.md
@@ -125,3 +125,10 @@ func rotate(matrix [][]int) {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0049.Group-Anagrams.md b/website/content/ChapterFour/0049.Group-Anagrams.md
index 8eca6bea..0fe588da 100644
--- a/website/content/ChapterFour/0049.Group-Anagrams.md
+++ b/website/content/ChapterFour/0049.Group-Anagrams.md
@@ -70,3 +70,10 @@ func groupAnagrams(strs []string) [][]string {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0050.Powx-n.md b/website/content/ChapterFour/0050.Powx-n.md
index 86ec7451..c4a4cc04 100755
--- a/website/content/ChapterFour/0050.Powx-n.md
+++ b/website/content/ChapterFour/0050.Powx-n.md
@@ -67,3 +67,10 @@ func myPow(x float64, n int) float64 {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0051.N-Queens.md b/website/content/ChapterFour/0051.N-Queens.md
index 9c9b2eba..a139bf0b 100755
--- a/website/content/ChapterFour/0051.N-Queens.md
+++ b/website/content/ChapterFour/0051.N-Queens.md
@@ -131,4 +131,11 @@ func generateBoard(n int, row *[]int) []string {
// }
// };
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0052.N-Queens-II.md b/website/content/ChapterFour/0052.N-Queens-II.md
index 36b5911b..16aa957d 100755
--- a/website/content/ChapterFour/0052.N-Queens-II.md
+++ b/website/content/ChapterFour/0052.N-Queens-II.md
@@ -104,4 +104,11 @@ func putQueen52(n, index int, col, dia1, dia2 *[]bool, row *[]int, res *int) {
// }
// };
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0053.Maximum-Subarray.md b/website/content/ChapterFour/0053.Maximum-Subarray.md
index a5c3a0a5..ada3aaa0 100755
--- a/website/content/ChapterFour/0053.Maximum-Subarray.md
+++ b/website/content/ChapterFour/0053.Maximum-Subarray.md
@@ -72,4 +72,11 @@ func maxSubArray1(nums []int) int {
return maxSum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0054.Spiral-Matrix.md b/website/content/ChapterFour/0054.Spiral-Matrix.md
index 4fd81dc5..f4207db7 100755
--- a/website/content/ChapterFour/0054.Spiral-Matrix.md
+++ b/website/content/ChapterFour/0054.Spiral-Matrix.md
@@ -162,4 +162,11 @@ func spiralOrder2(matrix [][]int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0055.Jump-Game.md b/website/content/ChapterFour/0055.Jump-Game.md
index 84b7ddaf..f7728173 100644
--- a/website/content/ChapterFour/0055.Jump-Game.md
+++ b/website/content/ChapterFour/0055.Jump-Game.md
@@ -55,4 +55,11 @@ func canJump(nums []int) bool {
}
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0056.Merge-Intervals.md b/website/content/ChapterFour/0056.Merge-Intervals.md
index cfe7aecd..bf424015 100644
--- a/website/content/ChapterFour/0056.Merge-Intervals.md
+++ b/website/content/ChapterFour/0056.Merge-Intervals.md
@@ -106,4 +106,11 @@ func quickSort(a []Interval, lo, hi int) {
quickSort(a, p+1, hi)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0057.Insert-Interval.md b/website/content/ChapterFour/0057.Insert-Interval.md
index 63b6df7c..77957dd9 100644
--- a/website/content/ChapterFour/0057.Insert-Interval.md
+++ b/website/content/ChapterFour/0057.Insert-Interval.md
@@ -72,4 +72,11 @@ func insert(intervals []Interval, newInterval Interval) []Interval {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0059.Spiral-Matrix-II.md b/website/content/ChapterFour/0059.Spiral-Matrix-II.md
index 201b80f3..763affe6 100755
--- a/website/content/ChapterFour/0059.Spiral-Matrix-II.md
+++ b/website/content/ChapterFour/0059.Spiral-Matrix-II.md
@@ -91,4 +91,11 @@ func generateMatrix(n int) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0060.Permutation-Sequence.md b/website/content/ChapterFour/0060.Permutation-Sequence.md
index e762d748..67889293 100755
--- a/website/content/ChapterFour/0060.Permutation-Sequence.md
+++ b/website/content/ChapterFour/0060.Permutation-Sequence.md
@@ -93,4 +93,11 @@ func findPermutation(n, index int, k *int, p []int, res *string, used *[]bool) {
return
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0061.Rotate-List.md b/website/content/ChapterFour/0061.Rotate-List.md
index 6bef2616..f4adedb5 100644
--- a/website/content/ChapterFour/0061.Rotate-List.md
+++ b/website/content/ChapterFour/0061.Rotate-List.md
@@ -78,4 +78,11 @@ func rotateRight(head *ListNode, k int) *ListNode {
return res.Next
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0062.Unique-Paths.md b/website/content/ChapterFour/0062.Unique-Paths.md
index 9a67bbb9..a0dce700 100755
--- a/website/content/ChapterFour/0062.Unique-Paths.md
+++ b/website/content/ChapterFour/0062.Unique-Paths.md
@@ -66,4 +66,11 @@ func uniquePaths(m int, n int) int {
return dp[n-1][m-1]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0063.Unique-Paths-II.md b/website/content/ChapterFour/0063.Unique-Paths-II.md
index 7ab37659..6038f50c 100755
--- a/website/content/ChapterFour/0063.Unique-Paths-II.md
+++ b/website/content/ChapterFour/0063.Unique-Paths-II.md
@@ -77,4 +77,11 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int {
return dp[m-1][n-1]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0064.Minimum-Path-Sum.md b/website/content/ChapterFour/0064.Minimum-Path-Sum.md
index 8ae24ab1..c39e60cf 100755
--- a/website/content/ChapterFour/0064.Minimum-Path-Sum.md
+++ b/website/content/ChapterFour/0064.Minimum-Path-Sum.md
@@ -90,4 +90,11 @@ func minPathSum1(grid [][]int) int {
return dp[m-1][n-1]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0066.Plus-One.md b/website/content/ChapterFour/0066.Plus-One.md
index 441789f9..6cc9b1e3 100755
--- a/website/content/ChapterFour/0066.Plus-One.md
+++ b/website/content/ChapterFour/0066.Plus-One.md
@@ -60,4 +60,11 @@ func plusOne(digits []int) []int {
return digits
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0067.Add-Binary.md b/website/content/ChapterFour/0067.Add-Binary.md
index 91d977e5..74af33b2 100644
--- a/website/content/ChapterFour/0067.Add-Binary.md
+++ b/website/content/ChapterFour/0067.Add-Binary.md
@@ -73,4 +73,11 @@ func addBinary(a string, b string) string {
return strings.Join(res, "")
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0069.Sqrtx.md b/website/content/ChapterFour/0069.Sqrtx.md
index 3b4397de..ff8d8742 100755
--- a/website/content/ChapterFour/0069.Sqrtx.md
+++ b/website/content/ChapterFour/0069.Sqrtx.md
@@ -88,4 +88,11 @@ func mySqrt1(x int) int {
// return y;
// }
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0070.Climbing-Stairs.md b/website/content/ChapterFour/0070.Climbing-Stairs.md
index 5eda8e5c..8f8ed262 100755
--- a/website/content/ChapterFour/0070.Climbing-Stairs.md
+++ b/website/content/ChapterFour/0070.Climbing-Stairs.md
@@ -52,4 +52,11 @@ func climbStairs(n int) int {
return dp[n]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0071.Simplify-Path.md b/website/content/ChapterFour/0071.Simplify-Path.md
index b4a7c4cf..e716cd11 100644
--- a/website/content/ChapterFour/0071.Simplify-Path.md
+++ b/website/content/ChapterFour/0071.Simplify-Path.md
@@ -114,4 +114,11 @@ func simplifyPath1(path string) string {
return filepath.Clean(path)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0074.Search-a-2D-Matrix.md b/website/content/ChapterFour/0074.Search-a-2D-Matrix.md
index 07290862..d84a1b1e 100755
--- a/website/content/ChapterFour/0074.Search-a-2D-Matrix.md
+++ b/website/content/ChapterFour/0074.Search-a-2D-Matrix.md
@@ -69,4 +69,11 @@ func searchMatrix(matrix [][]int, target int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0075.Sort-Colors.md b/website/content/ChapterFour/0075.Sort-Colors.md
index 127d74c0..d9653fc9 100644
--- a/website/content/ChapterFour/0075.Sort-Colors.md
+++ b/website/content/ChapterFour/0075.Sort-Colors.md
@@ -69,4 +69,11 @@ func sortColors(nums []int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0076.Minimum-Window-Substring.md b/website/content/ChapterFour/0076.Minimum-Window-Substring.md
index a13affa3..5ac08bf8 100644
--- a/website/content/ChapterFour/0076.Minimum-Window-Substring.md
+++ b/website/content/ChapterFour/0076.Minimum-Window-Substring.md
@@ -74,3 +74,10 @@ func minWindow(s string, t string) string {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0077.Combinations.md b/website/content/ChapterFour/0077.Combinations.md
index 74a6bf26..c9c88ed6 100755
--- a/website/content/ChapterFour/0077.Combinations.md
+++ b/website/content/ChapterFour/0077.Combinations.md
@@ -28,7 +28,7 @@ Given two integers *n* and *k*, return all possible combinations of *k* num
## 代码
-```
+```go
package leetcode
@@ -57,4 +57,11 @@ func generateCombinations(n, k, start int, c []int, res *[][]int) {
return
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0078.Subsets.md b/website/content/ChapterFour/0078.Subsets.md
index 3173014e..32aa9d48 100755
--- a/website/content/ChapterFour/0078.Subsets.md
+++ b/website/content/ChapterFour/0078.Subsets.md
@@ -102,4 +102,11 @@ func subsets2(nums []int) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0079.Word-Search.md b/website/content/ChapterFour/0079.Word-Search.md
index b38e63ba..62c03768 100755
--- a/website/content/ChapterFour/0079.Word-Search.md
+++ b/website/content/ChapterFour/0079.Word-Search.md
@@ -80,4 +80,11 @@ func searchWord(board [][]byte, visited [][]bool, word string, index, x, y int)
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md b/website/content/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md
index e0811e92..36438895 100644
--- a/website/content/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md
+++ b/website/content/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md
@@ -102,4 +102,11 @@ func removeDuplicates80(nums []int) int {
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0081.Search-in-Rotated-Sorted-Array-II.md b/website/content/ChapterFour/0081.Search-in-Rotated-Sorted-Array-II.md
index e9b9a880..e7dad91f 100755
--- a/website/content/ChapterFour/0081.Search-in-Rotated-Sorted-Array-II.md
+++ b/website/content/ChapterFour/0081.Search-in-Rotated-Sorted-Array-II.md
@@ -82,4 +82,11 @@ func search(nums []int, target int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md b/website/content/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md
index 26328f20..d0dc28f7 100644
--- a/website/content/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md
+++ b/website/content/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md
@@ -43,6 +43,8 @@ package leetcode
* Next *ListNode
* }
*/
+
+// 解法一
func deleteDuplicates1(head *ListNode) *ListNode {
if head == nil {
return nil
@@ -89,6 +91,7 @@ func deleteDuplicates1(head *ListNode) *ListNode {
return newHead.Next
}
+// 解法二
func deleteDuplicates2(head *ListNode) *ListNode {
if head == nil {
return nil
@@ -103,4 +106,93 @@ func deleteDuplicates2(head *ListNode) *ListNode {
return head
}
-```
\ No newline at end of file
+func deleteDuplicates(head *ListNode) *ListNode {
+ cur := head
+ if head == nil {
+ return nil
+ }
+ if head.Next == nil {
+ return head
+ }
+ for cur.Next != nil {
+ if cur.Next.Val == cur.Val {
+ cur.Next = cur.Next.Next
+ } else {
+ cur = cur.Next
+ }
+ }
+ return head
+}
+
+// 解法三 双循环简单解法 O(n*m)
+func deleteDuplicates3(head *ListNode) *ListNode {
+ if head == nil {
+ return head
+ }
+
+ nilNode := &ListNode{Val: 0, Next: head}
+ head = nilNode
+
+ lastVal := 0
+ for head.Next != nil && head.Next.Next != nil {
+ if head.Next.Val == head.Next.Next.Val {
+ lastVal = head.Next.Val
+ for head.Next != nil && lastVal == head.Next.Val {
+ head.Next = head.Next.Next
+ }
+ } else {
+ head = head.Next
+ }
+ }
+ return nilNode.Next
+}
+
+// 解法四 双指针+删除标志位,单循环解法 O(n)
+func deleteDuplicates4(head *ListNode) *ListNode {
+ if head == nil || head.Next == nil {
+ return head
+ }
+
+ nilNode := &ListNode{Val: 0, Next: head}
+ // 上次遍历有删除操作的标志位
+ lastIsDel := false
+ // 虚拟空结点
+ head = nilNode
+ // 前后指针用于判断
+ pre, back := head.Next, head.Next.Next
+ // 每次只删除前面的一个重复的元素,留一个用于下次遍历判重
+ // pre, back 指针的更新位置和值比较重要和巧妙
+ for head.Next != nil && head.Next.Next != nil {
+ if pre.Val != back.Val && lastIsDel {
+ head.Next = head.Next.Next
+ pre, back = head.Next, head.Next.Next
+ lastIsDel = false
+ continue
+ }
+
+ if pre.Val == back.Val {
+ head.Next = head.Next.Next
+ pre, back = head.Next, head.Next.Next
+ lastIsDel = true
+ } else {
+ head = head.Next
+ pre, back = head.Next, head.Next.Next
+ lastIsDel = false
+ }
+ }
+ // 处理 [1,1] 这种删除还剩一个的情况
+ if lastIsDel && head.Next != nil {
+ head.Next = nil
+ }
+ return nilNode.Next
+}
+
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md b/website/content/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md
index 07d1654e..fd662034 100644
--- a/website/content/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md
+++ b/website/content/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md
@@ -63,4 +63,11 @@ func deleteDuplicates(head *ListNode) *ListNode {
return head
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0084.Largest-Rectangle-in-Histogram.md b/website/content/ChapterFour/0084.Largest-Rectangle-in-Histogram.md
index 7b22b220..f50d91ad 100644
--- a/website/content/ChapterFour/0084.Largest-Rectangle-in-Histogram.md
+++ b/website/content/ChapterFour/0084.Largest-Rectangle-in-Histogram.md
@@ -72,4 +72,11 @@ func largestRectangleArea(heights []int) int {
return maxArea
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0086.Partition-List.md b/website/content/ChapterFour/0086.Partition-List.md
index d261700d..540430a3 100644
--- a/website/content/ChapterFour/0086.Partition-List.md
+++ b/website/content/ChapterFour/0086.Partition-List.md
@@ -145,4 +145,11 @@ func genListNode(head *DoublyListNode) *ListNode {
return LNHead
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0088.Merge-Sorted-Array.md b/website/content/ChapterFour/0088.Merge-Sorted-Array.md
index 42d50a53..500295f6 100644
--- a/website/content/ChapterFour/0088.Merge-Sorted-Array.md
+++ b/website/content/ChapterFour/0088.Merge-Sorted-Array.md
@@ -66,4 +66,11 @@ func merge(nums1 []int, m int, nums2 []int, n int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0089.Gray-Code.md b/website/content/ChapterFour/0089.Gray-Code.md
index cb3d5df9..df616ebc 100755
--- a/website/content/ChapterFour/0089.Gray-Code.md
+++ b/website/content/ChapterFour/0089.Gray-Code.md
@@ -114,4 +114,11 @@ func grayCode1(n int) []int {
return out
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0090.Subsets-II.md b/website/content/ChapterFour/0090.Subsets-II.md
index 53e15611..77b974db 100755
--- a/website/content/ChapterFour/0090.Subsets-II.md
+++ b/website/content/ChapterFour/0090.Subsets-II.md
@@ -73,4 +73,11 @@ func generateSubsetsWithDup(nums []int, k, start int, c []int, res *[][]int) {
return
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0091.Decode-Ways.md b/website/content/ChapterFour/0091.Decode-Ways.md
index 11dc5416..ccf85684 100755
--- a/website/content/ChapterFour/0091.Decode-Ways.md
+++ b/website/content/ChapterFour/0091.Decode-Ways.md
@@ -79,4 +79,11 @@ func numDecodings(s string) int {
return dp[len(s)]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0092.Reverse-Linked-List-II.md b/website/content/ChapterFour/0092.Reverse-Linked-List-II.md
index 59cd5d57..ea62d1f1 100644
--- a/website/content/ChapterFour/0092.Reverse-Linked-List-II.md
+++ b/website/content/ChapterFour/0092.Reverse-Linked-List-II.md
@@ -62,4 +62,11 @@ func reverseBetween(head *ListNode, m int, n int) *ListNode {
return newHead.Next
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0093.Restore-IP-Addresses.md b/website/content/ChapterFour/0093.Restore-IP-Addresses.md
index 1ef2120d..f4c862d9 100755
--- a/website/content/ChapterFour/0093.Restore-IP-Addresses.md
+++ b/website/content/ChapterFour/0093.Restore-IP-Addresses.md
@@ -75,4 +75,11 @@ func getString(ip []int) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md b/website/content/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md
index 1161f158..68f2997d 100644
--- a/website/content/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md
+++ b/website/content/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md
@@ -70,4 +70,11 @@ func inorder(root *TreeNode, output *[]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0095.Unique-Binary-Search-Trees-II.md b/website/content/ChapterFour/0095.Unique-Binary-Search-Trees-II.md
index 790470c1..8bb74436 100755
--- a/website/content/ChapterFour/0095.Unique-Binary-Search-Trees-II.md
+++ b/website/content/ChapterFour/0095.Unique-Binary-Search-Trees-II.md
@@ -75,4 +75,11 @@ func generateBSTree(start, end int) []*TreeNode {
return tree
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0096.Unique-Binary-Search-Trees.md b/website/content/ChapterFour/0096.Unique-Binary-Search-Trees.md
index a3fca5ef..216f7084 100755
--- a/website/content/ChapterFour/0096.Unique-Binary-Search-Trees.md
+++ b/website/content/ChapterFour/0096.Unique-Binary-Search-Trees.md
@@ -50,4 +50,11 @@ func numTrees(n int) int {
return dp[n]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0098.Validate-Binary-Search-Tree.md b/website/content/ChapterFour/0098.Validate-Binary-Search-Tree.md
index 870f3598..d95b7e82 100755
--- a/website/content/ChapterFour/0098.Validate-Binary-Search-Tree.md
+++ b/website/content/ChapterFour/0098.Validate-Binary-Search-Tree.md
@@ -11,7 +11,7 @@ Assume a BST is defined as follows:
- The right subtree of a node contains only nodes with keys **greater than** the node's key.
- Both the left and right subtrees must also be binary search trees.
-**xample 1:**
+**Example 1**:
2
/ \
@@ -96,4 +96,11 @@ func inOrder(root *TreeNode, arr *[]int) {
inOrder(root.Right, arr)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0099.Recover-Binary-Search-Tree.md b/website/content/ChapterFour/0099.Recover-Binary-Search-Tree.md
index 0a0e86e9..4ec788c7 100755
--- a/website/content/ChapterFour/0099.Recover-Binary-Search-Tree.md
+++ b/website/content/ChapterFour/0099.Recover-Binary-Search-Tree.md
@@ -98,4 +98,11 @@ func inOrderTraverse(root, prev, target1, target2 *TreeNode) (*TreeNode, *TreeNo
return prev, target1, target2
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0100.Same-Tree.md b/website/content/ChapterFour/0100.Same-Tree.md
index 6c12131b..e714cda2 100644
--- a/website/content/ChapterFour/0100.Same-Tree.md
+++ b/website/content/ChapterFour/0100.Same-Tree.md
@@ -89,4 +89,11 @@ func isSameTree(p *TreeNode, q *TreeNode) bool {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0101.Symmetric-Tree.md b/website/content/ChapterFour/0101.Symmetric-Tree.md
index b3f2ea18..21b4dc1a 100644
--- a/website/content/ChapterFour/0101.Symmetric-Tree.md
+++ b/website/content/ChapterFour/0101.Symmetric-Tree.md
@@ -68,4 +68,11 @@ func isSymmetric(root *TreeNode) bool {
return isSameTree(invertTree(root.Left), root.Right)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md b/website/content/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md
index 6848f2ca..e00a4646 100644
--- a/website/content/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md
+++ b/website/content/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md
@@ -112,4 +112,11 @@ func dfsLevel(node *TreeNode, level int, res *[][]int) {
dfsLevel(node.Right, currLevel, res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md b/website/content/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md
index 6cac4bca..110306c8 100644
--- a/website/content/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md
+++ b/website/content/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md
@@ -56,6 +56,8 @@ package leetcode
* Right *TreeNode
* }
*/
+
+// 解法一
func zigzagLevelOrder(root *TreeNode) [][]int {
if root == nil {
return [][]int{}
@@ -98,4 +100,34 @@ func zigzagLevelOrder(root *TreeNode) [][]int {
return res
}
-```
\ No newline at end of file
+// 解法二 递归
+func zigzagLevelOrder0(root *TreeNode) [][]int {
+ var res [][]int
+ search(root, 0, &res)
+ return res
+}
+
+func search(root *TreeNode, depth int, res *[][]int) {
+ if root == nil {
+ return
+ }
+ for len(*res) < depth+1 {
+ *res = append(*res, []int{})
+ }
+ if depth%2 == 0 {
+ (*res)[depth] = append((*res)[depth], root.Val)
+ } else {
+ (*res)[depth] = append([]int{root.Val}, (*res)[depth]...)
+ }
+ search(root.Left, depth+1, res)
+ search(root.Right, depth+1, res)
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md b/website/content/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md
index 3502cb85..8529be03 100644
--- a/website/content/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md
+++ b/website/content/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md
@@ -57,4 +57,11 @@ func maxDepth(root *TreeNode) int {
return max(maxDepth(root.Left), maxDepth(root.Right)) + 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md b/website/content/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md
index 0d6259c0..4a77e74b 100755
--- a/website/content/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md
+++ b/website/content/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md
@@ -70,4 +70,11 @@ func buildPreIn2TreeDFS(pre []int, preStart int, preEnd int, inStart int, inPos
return root
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md b/website/content/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md
index 62ea1c8a..fefec6b0 100755
--- a/website/content/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md
+++ b/website/content/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md
@@ -68,4 +68,11 @@ func buildInPos2TreeDFS(post []int, postStart int, postEnd int, inStart int, inP
return root
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md b/website/content/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md
index 5054e26f..1003bee3 100644
--- a/website/content/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md
+++ b/website/content/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md
@@ -67,4 +67,11 @@ func levelOrderBottom(root *TreeNode) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md b/website/content/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md
index b888c624..6b440de7 100755
--- a/website/content/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md
+++ b/website/content/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md
@@ -49,4 +49,11 @@ func sortedArrayToBST(nums []int) *TreeNode {
return &TreeNode{Val: nums[len(nums)/2], Left: sortedArrayToBST(nums[:len(nums)/2]), Right: sortedArrayToBST(nums[len(nums)/2+1:])}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md b/website/content/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md
index 5ddfce29..9ae35afd 100644
--- a/website/content/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md
+++ b/website/content/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md
@@ -94,4 +94,11 @@ func middleNodeAndPreNode(head *ListNode) (middle *ListNode, pre *ListNode) {
return p1, pre
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0110.Balanced-Binary-Tree.md b/website/content/ChapterFour/0110.Balanced-Binary-Tree.md
index 9417fd71..779fae8f 100644
--- a/website/content/ChapterFour/0110.Balanced-Binary-Tree.md
+++ b/website/content/ChapterFour/0110.Balanced-Binary-Tree.md
@@ -87,4 +87,11 @@ func depth(root *TreeNode) int {
return max(depth(root.Left), depth(root.Right)) + 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md b/website/content/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md
index 12019aed..d3bd4f1b 100755
--- a/website/content/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md
+++ b/website/content/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md
@@ -59,4 +59,11 @@ func minDepth(root *TreeNode) int {
return min(minDepth(root.Left), minDepth(root.Right)) + 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0112.Path-Sum.md b/website/content/ChapterFour/0112.Path-Sum.md
index 19a22631..f3fcce0f 100755
--- a/website/content/ChapterFour/0112.Path-Sum.md
+++ b/website/content/ChapterFour/0112.Path-Sum.md
@@ -56,4 +56,11 @@ func hasPathSum(root *TreeNode, sum int) bool {
return hasPathSum(root.Left, sum-root.Val) || hasPathSum(root.Right, sum-root.Val)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0113.Path-Sum-II.md b/website/content/ChapterFour/0113.Path-Sum-II.md
index ac592ca8..e975e8a1 100755
--- a/website/content/ChapterFour/0113.Path-Sum-II.md
+++ b/website/content/ChapterFour/0113.Path-Sum-II.md
@@ -105,4 +105,11 @@ func pathSum1(root *TreeNode, sum int) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md b/website/content/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md
index 4cfc5452..e80d351b 100755
--- a/website/content/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md
+++ b/website/content/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md
@@ -188,4 +188,11 @@ func flatten2(root *TreeNode) {
root.Left = nil
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0118.Pascals-Triangle.md b/website/content/ChapterFour/0118.Pascals-Triangle.md
index b74f58fa..36a16f50 100644
--- a/website/content/ChapterFour/0118.Pascals-Triangle.md
+++ b/website/content/ChapterFour/0118.Pascals-Triangle.md
@@ -58,3 +58,10 @@ func generate(numRows int) [][]int {
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0120.Triangle.md b/website/content/ChapterFour/0120.Triangle.md
index d3ec1112..473cfa62 100755
--- a/website/content/ChapterFour/0120.Triangle.md
+++ b/website/content/ChapterFour/0120.Triangle.md
@@ -86,4 +86,11 @@ func minimumTotal1(triangle [][]int) int {
return minNum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md b/website/content/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md
index 5a39f8cc..0ec5db6b 100755
--- a/website/content/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md
+++ b/website/content/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md
@@ -79,4 +79,11 @@ func maxProfit1(prices []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md b/website/content/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md
index 5029cbf8..241e31bc 100755
--- a/website/content/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md
+++ b/website/content/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md
@@ -57,4 +57,11 @@ func maxProfit122(prices []int) int {
return profit
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md b/website/content/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md
index b8fdab71..665d167c 100755
--- a/website/content/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md
+++ b/website/content/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md
@@ -77,4 +77,11 @@ func getPathSum(root *TreeNode, maxSum *int) int {
return currMax
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0125.Valid-Palindrome.md b/website/content/ChapterFour/0125.Valid-Palindrome.md
index 552c02c9..bc19bb4d 100644
--- a/website/content/ChapterFour/0125.Valid-Palindrome.md
+++ b/website/content/ChapterFour/0125.Valid-Palindrome.md
@@ -34,13 +34,11 @@ For the purpose of this problem, we define empty string as valid palindrome.
package leetcode
import (
- "strings"
+ "strings"
)
func isPalindrome(s string) bool {
-
- s = strings.ToLower(s)
-
+ s = strings.ToLower(s)
i, j := 0, len(s)-1
for i < j {
for i < j && !isChar(s[i]) {
@@ -55,7 +53,6 @@ func isPalindrome(s string) bool {
i++
j--
}
-
return true
}
@@ -67,4 +64,11 @@ func isChar(c byte) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0126.Word-Ladder-II.md b/website/content/ChapterFour/0126.Word-Ladder-II.md
index 687124c7..a296cf23 100755
--- a/website/content/ChapterFour/0126.Word-Ladder-II.md
+++ b/website/content/ChapterFour/0126.Word-Ladder-II.md
@@ -127,4 +127,11 @@ func findLadders(beginWord string, endWord string, wordList []string) [][]string
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0127.Word-Ladder.md b/website/content/ChapterFour/0127.Word-Ladder.md
index 475aed66..dbeebb29 100755
--- a/website/content/ChapterFour/0127.Word-Ladder.md
+++ b/website/content/ChapterFour/0127.Word-Ladder.md
@@ -60,7 +60,7 @@ Given two words (*beginWord* and *endWord*), and a dictionary's word list, fin
- 这一题要求输出从 `beginWord` 变换到 `endWord` 最短变换次数。可以用 BFS,从 `beginWord` 开始变换,把该单词的每个字母都用 `'a'~'z'` 变换一次,生成的数组到 `wordList` 中查找,这里用 Map 来记录查找。找得到就入队列,找不到就输出 0 。入队以后按照 BFS 的算法依次遍历完,当所有单词都 `len(queue)<=0` 出队以后,整个程序结束。
- 这一题题目中虽然说了要求找到一条最短的路径,但是实际上最短的路径的寻找方法已经告诉你了:
- 1. 每次只变换一个字母
+ 1. 每次只变换一个字母
2. 每次变换都必须在 `wordList` 中
所以不需要单独考虑何种方式是最短的。
@@ -118,4 +118,11 @@ func getCandidates(word string) []string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0128.Longest-Consecutive-Sequence.md b/website/content/ChapterFour/0128.Longest-Consecutive-Sequence.md
index 80d7a5f4..e8d9307c 100755
--- a/website/content/ChapterFour/0128.Longest-Consecutive-Sequence.md
+++ b/website/content/ChapterFour/0128.Longest-Consecutive-Sequence.md
@@ -136,4 +136,11 @@ func longestConsecutive2(nums []int) int {
return max(lcs, length)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md b/website/content/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md
index 261b8ebd..2e52457e 100755
--- a/website/content/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md
+++ b/website/content/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md
@@ -94,4 +94,11 @@ func binaryTreeNums(root *TreeNode) []string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0130.Surrounded-Regions.md b/website/content/ChapterFour/0130.Surrounded-Regions.md
index 4ba38197..228ce63e 100755
--- a/website/content/ChapterFour/0130.Surrounded-Regions.md
+++ b/website/content/ChapterFour/0130.Surrounded-Regions.md
@@ -22,7 +22,7 @@ After running your function, the board should be:
X X X X
X O X X
-**Explanation:**
+**Explanation**:
Surrounded regions shouldn’t be on the border, which means that any `'O'` on the border of the board are not flipped to `'X'`. Any `'O'` that is not on the border and it is not connected to an `'O'` on the border will be flipped to `'X'`. Two cells are connected if they are adjacent cells connected horizontally or vertically.
@@ -123,4 +123,11 @@ func dfs130(i, j int, board [][]byte) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0131.Palindrome-Partitioning.md b/website/content/ChapterFour/0131.Palindrome-Partitioning.md
index 29b17bff..41c4f013 100755
--- a/website/content/ChapterFour/0131.Palindrome-Partitioning.md
+++ b/website/content/ChapterFour/0131.Palindrome-Partitioning.md
@@ -118,4 +118,11 @@ func isPal(str string, s, e int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0136.Single-Number.md b/website/content/ChapterFour/0136.Single-Number.md
index e3d24d83..73561826 100755
--- a/website/content/ChapterFour/0136.Single-Number.md
+++ b/website/content/ChapterFour/0136.Single-Number.md
@@ -43,4 +43,11 @@ func singleNumber(nums []int) int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0137.Single-Number-II.md b/website/content/ChapterFour/0137.Single-Number-II.md
index 5e82a6b7..44ac1c0a 100755
--- a/website/content/ChapterFour/0137.Single-Number-II.md
+++ b/website/content/ChapterFour/0137.Single-Number-II.md
@@ -106,4 +106,11 @@ func singleNumberIIIII1(nums []int) int {
return ones
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0141.Linked-List-Cycle.md b/website/content/ChapterFour/0141.Linked-List-Cycle.md
index ac0553c6..cdb276f6 100644
--- a/website/content/ChapterFour/0141.Linked-List-Cycle.md
+++ b/website/content/ChapterFour/0141.Linked-List-Cycle.md
@@ -45,4 +45,11 @@ func hasCycle(head *ListNode) bool {
return false
}
-```w
\ No newline at end of file
+```w
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0142.Linked-List-Cycle-II.md b/website/content/ChapterFour/0142.Linked-List-Cycle-II.md
index f598045a..07f10488 100644
--- a/website/content/ChapterFour/0142.Linked-List-Cycle-II.md
+++ b/website/content/ChapterFour/0142.Linked-List-Cycle-II.md
@@ -106,4 +106,11 @@ func hasCycle142(head *ListNode) (bool, *ListNode) {
return false, nil
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0143.Reorder-List.md b/website/content/ChapterFour/0143.Reorder-List.md
index 9383f56e..87060cc9 100644
--- a/website/content/ChapterFour/0143.Reorder-List.md
+++ b/website/content/ChapterFour/0143.Reorder-List.md
@@ -124,4 +124,11 @@ func listToArray(head *ListNode) []int {
return array
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md b/website/content/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md
index 408ccb75..d4b09831 100644
--- a/website/content/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md
+++ b/website/content/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md
@@ -109,4 +109,11 @@ func preorderTraversal2(root *TreeNode) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md b/website/content/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md
index a78a7465..e73320d0 100644
--- a/website/content/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md
+++ b/website/content/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md
@@ -68,4 +68,11 @@ func postorder(root *TreeNode, output *[]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0146.LRU-Cache.md b/website/content/ChapterFour/0146.LRU-Cache.md
new file mode 100644
index 00000000..abf03290
--- /dev/null
+++ b/website/content/ChapterFour/0146.LRU-Cache.md
@@ -0,0 +1,141 @@
+# [146. LRU Cache](https://leetcode.com/problems/lru-cache/)
+
+## 题目
+
+Design a data structure that follows the constraints of a **[Least Recently Used (LRU) cache](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU)**.
+
+Implement the `LRUCache` class:
+
+- `LRUCache(int capacity)` Initialize the LRU cache with **positive** size `capacity`.
+- `int get(int key)` Return the value of the `key` if the key exists, otherwise return `1`.
+- `void put(int key, int value)` Update the value of the `key` if the `key` exists. Otherwise, add the `key-value` pair to the cache. If the number of keys exceeds the `capacity` from this operation, **evict** the least recently used key.
+
+**Follow up**:Could you do `get` and `put` in `O(1)` time complexity?
+
+**Example 1**:
+
+```
+Input
+["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, null, -1, 3, 4]
+
+Explanation
+LRUCache lRUCache = new LRUCache(2);
+lRUCache.put(1, 1); // cache is {1=1}
+lRUCache.put(2, 2); // cache is {1=1, 2=2}
+lRUCache.get(1); // return 1
+lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}
+lRUCache.get(2); // returns -1 (not found)
+lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}
+lRUCache.get(1); // return -1 (not found)
+lRUCache.get(3); // return 3
+lRUCache.get(4); // return 4
+
+```
+
+**Constraints**:
+
+- `1 <= capacity <= 3000`
+- `0 <= key <= 3000`
+- `0 <= value <= 104`
+- At most `3 * 104` calls will be made to `get` and `put`.
+
+## 题目大意
+
+运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制 。
+实现 LRUCache 类:
+
+- LRUCache(int capacity) 以正整数作为容量 capacity 初始化 LRU 缓存
+- int get(int key) 如果关键字 key 存在于缓存中,则返回关键字的值,否则返回 -1 。
+- void put(int key, int value) 如果关键字已经存在,则变更其数据值;如果关键字不存在,则插入该组「关键字-值」。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的数据值,从而为新的数据值留出空间。
+
+进阶:你是否可以在 O(1) 时间复杂度内完成这两种操作?
+
+## 解题思路
+
+- 这一题是 LRU 经典面试题,详细解释见第三章模板。
+
+## 代码
+
+```go
+package leetcode
+
+type LRUCache struct {
+ head, tail *Node
+ Keys map[int]*Node
+ Cap int
+}
+
+type Node struct {
+ Key, Val int
+ Prev, Next *Node
+}
+
+func Constructor(capacity int) LRUCache {
+ return LRUCache{Keys: make(map[int]*Node), Cap: capacity}
+}
+
+func (this *LRUCache) Get(key int) int {
+ if node, ok := this.Keys[key]; ok {
+ this.Remove(node)
+ this.Add(node)
+ return node.Val
+ }
+ return -1
+}
+
+func (this *LRUCache) Put(key int, value int) {
+ if node, ok := this.Keys[key]; ok {
+ node.Val = value
+ this.Remove(node)
+ this.Add(node)
+ return
+ } else {
+ node = &Node{Key: key, Val: value}
+ this.Keys[key] = node
+ this.Add(node)
+ }
+ if len(this.Keys) > this.Cap {
+ delete(this.Keys, this.tail.Key)
+ this.Remove(this.tail)
+ }
+}
+
+func (this *LRUCache) Add(node *Node) {
+ node.Prev = nil
+ node.Next = this.head
+ if this.head != nil {
+ this.head.Prev = node
+ }
+ this.head = node
+ if this.tail == nil {
+ this.tail = node
+ this.tail.Next = nil
+ }
+}
+
+func (this *LRUCache) Remove(node *Node) {
+ if node == this.head {
+ this.head = node.Next
+ node.Next = nil
+ return
+ }
+ if node == this.tail {
+ this.tail = node.Prev
+ node.Prev.Next = nil
+ node.Prev = nil
+ return
+ }
+ node.Prev.Next = node.Next
+ node.Next.Prev = node.Prev
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0147.Insertion-Sort-List.md b/website/content/ChapterFour/0147.Insertion-Sort-List.md
index 80bedc45..bbdca940 100644
--- a/website/content/ChapterFour/0147.Insertion-Sort-List.md
+++ b/website/content/ChapterFour/0147.Insertion-Sort-List.md
@@ -74,4 +74,11 @@ func insertionSortList(head *ListNode) *ListNode {
return newHead.Next
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0148.Sort-List.md b/website/content/ChapterFour/0148.Sort-List.md
index 0cf29b92..6d435555 100644
--- a/website/content/ChapterFour/0148.Sort-List.md
+++ b/website/content/ChapterFour/0148.Sort-List.md
@@ -54,17 +54,17 @@ func sortList(head *ListNode) *ListNode {
return head
}
- middleNode := middleNode1(head)
+ middleNode := middleNode(head)
cur = middleNode.Next
middleNode.Next = nil
middleNode = cur
left := sortList(head)
right := sortList(middleNode)
- return mergeTwoLists148(left, right)
+ return mergeTwoLists(left, right)
}
-func middleNode1(head *ListNode) *ListNode {
+func middleNode(head *ListNode) *ListNode {
if head == nil || head.Next == nil {
return head
}
@@ -77,7 +77,7 @@ func middleNode1(head *ListNode) *ListNode {
return p1
}
-func mergeTwoLists148(l1 *ListNode, l2 *ListNode) *ListNode {
+func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
if l1 == nil {
return l2
}
@@ -92,4 +92,12 @@ func mergeTwoLists148(l1 *ListNode, l2 *ListNode) *ListNode {
return l2
}
-```
\ No newline at end of file
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md b/website/content/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md
index 0cb6b472..b8cfa59b 100644
--- a/website/content/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md
+++ b/website/content/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md
@@ -112,4 +112,11 @@ func evalRPN(tokens []string) int {
return stack[0]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0151.Reverse-Words-in-a-String.md b/website/content/ChapterFour/0151.Reverse-Words-in-a-String.md
index e7d47d72..9d3a8fa4 100755
--- a/website/content/ChapterFour/0151.Reverse-Words-in-a-String.md
+++ b/website/content/ChapterFour/0151.Reverse-Words-in-a-String.md
@@ -79,4 +79,11 @@ func reverse151(m *[]string, i int, j int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0152.Maximum-Product-Subarray.md b/website/content/ChapterFour/0152.Maximum-Product-Subarray.md
index a09a1296..937780c5 100755
--- a/website/content/ChapterFour/0152.Maximum-Product-Subarray.md
+++ b/website/content/ChapterFour/0152.Maximum-Product-Subarray.md
@@ -49,4 +49,11 @@ func maxProduct(nums []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0153.Find-Minimum-in-Rotated-Sorted-Array.md b/website/content/ChapterFour/0153.Find-Minimum-in-Rotated-Sorted-Array.md
index b2a6d6e6..2462d5f4 100755
--- a/website/content/ChapterFour/0153.Find-Minimum-in-Rotated-Sorted-Array.md
+++ b/website/content/ChapterFour/0153.Find-Minimum-in-Rotated-Sorted-Array.md
@@ -105,4 +105,11 @@ func findMin2(nums []int) int {
return min
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md b/website/content/ChapterFour/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md
index 4ddfaa71..ed0c89af 100755
--- a/website/content/ChapterFour/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md
+++ b/website/content/ChapterFour/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md
@@ -64,4 +64,11 @@ func findMin154(nums []int) int {
return nums[low]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0155.Min-Stack.md b/website/content/ChapterFour/0155.Min-Stack.md
index 5d811c4e..4259b85a 100644
--- a/website/content/ChapterFour/0155.Min-Stack.md
+++ b/website/content/ChapterFour/0155.Min-Stack.md
@@ -84,4 +84,11 @@ func (this *MinStack) GetMin() int {
return this.min[this.l-1]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md b/website/content/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md
index 6a450eba..0fe6c24d 100644
--- a/website/content/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md
+++ b/website/content/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md
@@ -113,4 +113,11 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
return a
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0162.Find-Peak-Element.md b/website/content/ChapterFour/0162.Find-Peak-Element.md
index 2b69dbdb..74e7b14e 100755
--- a/website/content/ChapterFour/0162.Find-Peak-Element.md
+++ b/website/content/ChapterFour/0162.Find-Peak-Element.md
@@ -91,4 +91,11 @@ func findPeakElement1(nums []int) int {
return low
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0164.Maximum-Gap.md b/website/content/ChapterFour/0164.Maximum-Gap.md
index e1579e67..ea05421f 100644
--- a/website/content/ChapterFour/0164.Maximum-Gap.md
+++ b/website/content/ChapterFour/0164.Maximum-Gap.md
@@ -51,13 +51,12 @@ Explanation: The array contains less than 2 elements, therefore return 0.
package leetcode
-// 解法一
+// 解法一 快排
func maximumGap(nums []int) int {
if len(nums) < 2 {
return 0
}
quickSort164(nums, 0, len(nums)-1)
-
res := 0
for i := 0; i < len(nums)-1; i++ {
if (nums[i+1] - nums[i]) > res {
@@ -88,53 +87,58 @@ func quickSort164(a []int, lo, hi int) {
quickSort164(a, p+1, hi)
}
-// 解法二
+// 解法二 基数排序
func maximumGap1(nums []int) int {
-
if nums == nil || len(nums) < 2 {
return 0
}
-
// m is the maximal number in nums
m := nums[0]
for i := 1; i < len(nums); i++ {
m = max(m, nums[i])
}
-
exp := 1 // 1, 10, 100, 1000 ...
R := 10 // 10 digits
-
aux := make([]int, len(nums))
-
for (m / exp) > 0 { // Go through all digits from LSB to MSB
count := make([]int, R)
-
for i := 0; i < len(nums); i++ {
count[(nums[i]/exp)%10]++
}
-
for i := 1; i < len(count); i++ {
count[i] += count[i-1]
}
-
for i := len(nums) - 1; i >= 0; i-- {
tmp := count[(nums[i]/exp)%10]
tmp--
aux[tmp] = nums[i]
+ count[(nums[i]/exp)%10] = tmp
}
-
for i := 0; i < len(nums); i++ {
nums[i] = aux[i]
}
exp *= 10
}
-
maxValue := 0
for i := 1; i < len(aux); i++ {
maxValue = max(maxValue, aux[i]-aux[i-1])
}
-
return maxValue
}
-```
\ No newline at end of file
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md b/website/content/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md
index b4a1dd22..1e55e786 100644
--- a/website/content/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md
+++ b/website/content/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md
@@ -65,4 +65,11 @@ func twoSum167_1(numbers []int, target int) []int {
return nil
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0168.Excel-Sheet-Column-Title.md b/website/content/ChapterFour/0168.Excel-Sheet-Column-Title.md
index c1ecdd58..3a78b80d 100644
--- a/website/content/ChapterFour/0168.Excel-Sheet-Column-Title.md
+++ b/website/content/ChapterFour/0168.Excel-Sheet-Column-Title.md
@@ -77,4 +77,11 @@ func convertToTitle(n int) string {
return string(result)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0169.Majority-Element.md b/website/content/ChapterFour/0169.Majority-Element.md
index 548fb3ed..f05a4392 100755
--- a/website/content/ChapterFour/0169.Majority-Element.md
+++ b/website/content/ChapterFour/0169.Majority-Element.md
@@ -63,4 +63,11 @@ func majorityElement1(nums []int) int {
return 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0171.Excel-Sheet-Column-Number.md b/website/content/ChapterFour/0171.Excel-Sheet-Column-Number.md
index 8c9f6651..6294074d 100644
--- a/website/content/ChapterFour/0171.Excel-Sheet-Column-Number.md
+++ b/website/content/ChapterFour/0171.Excel-Sheet-Column-Number.md
@@ -64,4 +64,11 @@ func titleToNumber(s string) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0172.Factorial-Trailing-Zeroes.md b/website/content/ChapterFour/0172.Factorial-Trailing-Zeroes.md
index 4c6db632..c6a99740 100755
--- a/website/content/ChapterFour/0172.Factorial-Trailing-Zeroes.md
+++ b/website/content/ChapterFour/0172.Factorial-Trailing-Zeroes.md
@@ -48,4 +48,11 @@ func trailingZeroes(n int) int {
return n/5 + trailingZeroes(n/5)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0173.Binary-Search-Tree-Iterator.md b/website/content/ChapterFour/0173.Binary-Search-Tree-Iterator.md
index 8521ef5b..b81575ce 100755
--- a/website/content/ChapterFour/0173.Binary-Search-Tree-Iterator.md
+++ b/website/content/ChapterFour/0173.Binary-Search-Tree-Iterator.md
@@ -115,4 +115,11 @@ func (pq *PriorityQueueOfInt) Pop() interface{} {
return item
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0174.Dungeon-Game.md b/website/content/ChapterFour/0174.Dungeon-Game.md
index d95cc1ac..1c0edf33 100755
--- a/website/content/ChapterFour/0174.Dungeon-Game.md
+++ b/website/content/ChapterFour/0174.Dungeon-Game.md
@@ -41,9 +41,20 @@ For example, given the dungeon below, the initial health of the knight must be a
## 解题思路
- 在二维地图上给出每个格子扣血数,负数代表扣血,正数代表补血。左上角第一个格子是起点,右下角最后一个格子是终点。问骑士初始最少多少血才能走完迷宫,顺利营救位于终点的公主。需要注意的是,起点和终点都会对血量进行影响。每到一个格子,骑士的血都不能少于 1,一旦少于 1 点血,骑士就会死去。
-- 这一题首先想到的解题思路是动态规划。从终点逆推回起点。`dp[i][j]` 代表骑士进入坐标为 `(i,j)` 的格子之前最少的血量值。 那么 `dp[m-1][n-1]` 应该同时满足两个条件,`dp[m-1][n-1] + dungeon[m-1][n-1] ≥ 1` 并且 `dp[m-1][n-1] ≥ 1`,由于这两个不等式的方向是相同的,取交集以后,起决定作用的是数轴最右边的数,即 `max(1-dungeon[m-1][n-1] , 1)`。算出 `dp[m-1][n-1]` 以后,接着可以推出 `dp[m-1][i]` 这一行和 `dp[i][n-1]` 这一列的值。因为骑士只能往右走和往下走。往回推,即只能往上走和往左走。到这里,DP 的初始条件都准备好了。那么状态转移方程是什么呢?分析一般的情况,`dp[i][j]` 这个值应该是和 `dp[i+1][j]` 和 `dp[i][j+1]` 这两者有关系。即 `dp[i][j]` 经过自己本格子的扣血以后,要能至少满足下一行和右一列格子血量的最少要求。并且自己的血量也应该 `≥1`。即需要满足下面这两组不等式。
- 
- 
+- 这一题首先想到的解题思路是动态规划。从终点逆推回起点。`dp[i][j]` 代表骑士进入坐标为 `(i,j)` 的格子之前最少的血量值。 那么 `dp[m-1][n-1]` 应该同时满足两个条件,`dp[m-1][n-1] + dungeon[m-1][n-1] ≥ 1` 并且 `dp[m-1][n-1] ≥ 1`,由于这两个不等式的方向是相同的,取交集以后,起决定作用的是数轴最右边的数,即 `max(1-dungeon[m-1][n-1] , 1)`。算出 `dp[m-1][n-1]` 以后,接着可以推出 `dp[m-1][i]` 这一行和 `dp[i][n-1]` 这一列的值。因为骑士只能往右走和往下走。往回推,即只能往上走和往左走。到这里,DP 的初始条件都准备好了。那么状态转移方程是什么呢?分析一般的情况,`dp[i][j]` 这个值应该是和 `dp[i+1][j]` 和 `dp[i][j+1]` 这两者有关系。即 `dp[i][j]` 经过自己本格子的扣血以后,要能至少满足下一行和右一列格子血量的最少要求。并且自己的血量也应该 `≥1`。即需要满足下面这两组不等式。
+
+ {{< katex display >}}
+ \begin{matrix} \left\{
+ \begin{array}{lr}
+ dp[i][j] + dungeon[i][j] \geqslant dp[i+1][j] \\
+ dp[i][j] \geqslant 1
+ \end{array} \right.
+ \end{matrix}
+ {{< /katex >}}
+
+ {{< katex display >}}
+ \begin{matrix} \left\{ \begin{array}{lr} dp[i][j] + dungeon[i][j] \geqslant dp[i][j+1] \\ dp[i][j] \geqslant 1 \end{array} \right. \end{matrix}
+ {{< /katex >}}
上面不等式中第一组不等式是满足下一行格子的最低血量要求,第二组不等式是满足右一列格子的最低血量要求。第一个式子化简即 `dp[i][j] = max(1, dp[i+1][j]-dungeon[i][j])`,第二个式子化简即 `dp[i][j] = max(1, dp[i][j+1]-dungeon[i][j])`。求得了这两种走法的最低血量值,从这两个值里面取最小,即是当前格子所需的最低血量,所以状态转移方程为 `dp[i][j] = min(max(1, dp[i][j+1]-dungeon[i][j]), max(1, dp[i+1][j]-dungeon[i][j]))`。DP 完成以后,`dp[0][0]` 中记录的就是骑士初始最低血量值。时间复杂度 O(m\*n),空间复杂度 O(m\*n)。
- 这一题还可以用二分搜索来求解。骑士的血量取值范围一定是在 `[1,+∞)` 这个区间内。那么二分这个区间,每次二分的中间值,再用 dp 在地图中去判断是否能到达终点,如果能,就缩小搜索空间至 `[1,mid]`,否则搜索空间为 `[mid + 1,+∞)` 。时间复杂度 O(m\*n\* log math.MaxInt64),空间复杂度 O(m\*n)。
@@ -121,4 +132,11 @@ func canCross(dungeon [][]int, start int) bool {
return dp[m-1][n-1] > 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0179.Largest-Number.md b/website/content/ChapterFour/0179.Largest-Number.md
index de167785..aeb366ce 100644
--- a/website/content/ChapterFour/0179.Largest-Number.md
+++ b/website/content/ChapterFour/0179.Largest-Number.md
@@ -119,4 +119,11 @@ func quickSortString(a []string, lo, hi int) {
quickSortString(a, p+1, hi)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0187.Repeated-DNA-Sequences.md b/website/content/ChapterFour/0187.Repeated-DNA-Sequences.md
index 5f917e03..fe746802 100755
--- a/website/content/ChapterFour/0187.Repeated-DNA-Sequences.md
+++ b/website/content/ChapterFour/0187.Repeated-DNA-Sequences.md
@@ -68,4 +68,11 @@ func findRepeatedDnaSequences1(s string) []string {
return ans
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0189.Rotate-Array.md b/website/content/ChapterFour/0189.Rotate-Array.md
new file mode 100644
index 00000000..3be1e0de
--- /dev/null
+++ b/website/content/ChapterFour/0189.Rotate-Array.md
@@ -0,0 +1,82 @@
+# [189. Rotate Array](https://leetcode.com/problems/rotate-array/)
+
+## 题目
+
+Given an array, rotate the array to the right by *k* steps, where *k* is non-negative.
+
+**Follow up**:
+
+- Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
+- Could you do it in-place with O(1) extra space?
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,4,5,6,7], k = 3
+Output: [5,6,7,1,2,3,4]
+Explanation:
+rotate 1 steps to the right: [7,1,2,3,4,5,6]
+rotate 2 steps to the right: [6,7,1,2,3,4,5]
+rotate 3 steps to the right: [5,6,7,1,2,3,4]
+```
+
+**Example 2**:
+
+```
+Input: nums = [-1,-100,3,99], k = 2
+Output: [3,99,-1,-100]
+Explanation:
+rotate 1 steps to the right: [99,-1,-100,3]
+rotate 2 steps to the right: [3,99,-1,-100]
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 2 * 10^4`
+- `-2^31 <= nums[i] <= 2^31 - 1`
+- `0 <= k <= 10^5`
+
+## 题目大意
+
+给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
+
+## 解题思路
+
+- 解法二,使用一个额外的数组,先将原数组下标为 i 的元素移动到 `(i+k) mod n` 的位置,再将剩下的元素拷贝回来即可。
+- 解法一,由于题目要求不能使用额外的空间,所以本题最佳解法不是解法二。翻转最终态是,末尾 `k mod n` 个元素移动至了数组头部,剩下的元素右移 `k mod n` 个位置至最尾部。确定了最终态以后再变换就很容易。先将数组中所有元素从头到尾翻转一次,尾部的所有元素都到了头部,然后再将 `[0,(k mod n) − 1]` 区间内的元素翻转一次,最后再将 `[k mod n, n − 1]` 区间内的元素翻转一次,即可满足题目要求。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 时间复杂度 O(n),空间复杂度 O(1)
+func rotate(nums []int, k int) {
+ k %= len(nums)
+ reverse(nums)
+ reverse(nums[:k])
+ reverse(nums[k:])
+}
+
+func reverse(a []int) {
+ for i, n := 0, len(a); i < n/2; i++ {
+ a[i], a[n-1-i] = a[n-1-i], a[i]
+ }
+}
+
+// 解法二 时间复杂度 O(n),空间复杂度 O(n)
+func rotate1(nums []int, k int) {
+ newNums := make([]int, len(nums))
+ for i, v := range nums {
+ newNums[(i+k)%len(nums)] = v
+ }
+ copy(nums, newNums)
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0190.Reverse-Bits.md b/website/content/ChapterFour/0190.Reverse-Bits.md
index 47b9b939..dfbb2863 100755
--- a/website/content/ChapterFour/0190.Reverse-Bits.md
+++ b/website/content/ChapterFour/0190.Reverse-Bits.md
@@ -50,4 +50,11 @@ func reverseBits(num uint32) uint32 {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0191.Number-of-1-Bits.md b/website/content/ChapterFour/0191.Number-of-1-Bits.md
index 2723d2a0..379892d3 100755
--- a/website/content/ChapterFour/0191.Number-of-1-Bits.md
+++ b/website/content/ChapterFour/0191.Number-of-1-Bits.md
@@ -62,4 +62,11 @@ func hammingWeight1(num uint32) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0198.House-Robber.md b/website/content/ChapterFour/0198.House-Robber.md
index 4ad33a62..cbe1d110 100755
--- a/website/content/ChapterFour/0198.House-Robber.md
+++ b/website/content/ChapterFour/0198.House-Robber.md
@@ -91,4 +91,11 @@ func rob(nums []int) int {
return max(a, b)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0199.Binary-Tree-Right-Side-View.md b/website/content/ChapterFour/0199.Binary-Tree-Right-Side-View.md
index 621d2333..5c15e36b 100644
--- a/website/content/ChapterFour/0199.Binary-Tree-Right-Side-View.md
+++ b/website/content/ChapterFour/0199.Binary-Tree-Right-Side-View.md
@@ -81,4 +81,11 @@ func rightSideView(root *TreeNode) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0200.Number-of-Islands.md b/website/content/ChapterFour/0200.Number-of-Islands.md
index 3fe5a2f2..703125e3 100755
--- a/website/content/ChapterFour/0200.Number-of-Islands.md
+++ b/website/content/ChapterFour/0200.Number-of-Islands.md
@@ -78,4 +78,11 @@ func searchIslands(grid [][]byte, visited *[][]bool, x, y int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md b/website/content/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md
index cccdb75b..c0c11f3d 100755
--- a/website/content/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md
+++ b/website/content/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md
@@ -63,4 +63,11 @@ func rangeBitwiseAnd(m int, n int) int {
return n
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0202.Happy-Number.md b/website/content/ChapterFour/0202.Happy-Number.md
index 673c90cb..453b3275 100644
--- a/website/content/ChapterFour/0202.Happy-Number.md
+++ b/website/content/ChapterFour/0202.Happy-Number.md
@@ -62,4 +62,11 @@ func isHappy(n int) bool {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0203.Remove-Linked-List-Elements.md b/website/content/ChapterFour/0203.Remove-Linked-List-Elements.md
index 049e2561..0ab51f2a 100644
--- a/website/content/ChapterFour/0203.Remove-Linked-List-Elements.md
+++ b/website/content/ChapterFour/0203.Remove-Linked-List-Elements.md
@@ -53,4 +53,11 @@ func removeElements(head *ListNode, val int) *ListNode {
return newHead.Next
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0204.Count-Primes.md b/website/content/ChapterFour/0204.Count-Primes.md
index 81f49cdc..f835f5a8 100755
--- a/website/content/ChapterFour/0204.Count-Primes.md
+++ b/website/content/ChapterFour/0204.Count-Primes.md
@@ -47,4 +47,11 @@ func countPrimes(n int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0205.Isomorphic-Strings.md b/website/content/ChapterFour/0205.Isomorphic-Strings.md
index 31a2b620..43074115 100644
--- a/website/content/ChapterFour/0205.Isomorphic-Strings.md
+++ b/website/content/ChapterFour/0205.Isomorphic-Strings.md
@@ -87,4 +87,11 @@ func isIsomorphic(s string, t string) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0206.Reverse-Linked-List.md b/website/content/ChapterFour/0206.Reverse-Linked-List.md
index 28f4d7e6..af6949ca 100644
--- a/website/content/ChapterFour/0206.Reverse-Linked-List.md
+++ b/website/content/ChapterFour/0206.Reverse-Linked-List.md
@@ -44,4 +44,11 @@ func reverseList(head *ListNode) *ListNode {
return behind
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0207.Course-Schedule.md b/website/content/ChapterFour/0207.Course-Schedule.md
index 7d2e8401..c3f60925 100755
--- a/website/content/ChapterFour/0207.Course-Schedule.md
+++ b/website/content/ChapterFour/0207.Course-Schedule.md
@@ -79,4 +79,11 @@ func canFinish(n int, pre [][]int) bool {
return len(next) == n
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0208.Implement-Trie-Prefix-Tree.md b/website/content/ChapterFour/0208.Implement-Trie-Prefix-Tree.md
index 42d6500b..fec04d06 100755
--- a/website/content/ChapterFour/0208.Implement-Trie-Prefix-Tree.md
+++ b/website/content/ChapterFour/0208.Implement-Trie-Prefix-Tree.md
@@ -96,4 +96,11 @@ func (this *Trie) StartsWith(prefix string) bool {
* param_3 := obj.StartsWith(prefix);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0209.Minimum-Size-Subarray-Sum.md b/website/content/ChapterFour/0209.Minimum-Size-Subarray-Sum.md
index c2fd8a75..0d6d6f1e 100644
--- a/website/content/ChapterFour/0209.Minimum-Size-Subarray-Sum.md
+++ b/website/content/ChapterFour/0209.Minimum-Size-Subarray-Sum.md
@@ -58,4 +58,11 @@ func minSubArrayLen(s int, nums []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0210.Course-Schedule-II.md b/website/content/ChapterFour/0210.Course-Schedule-II.md
index 735d260e..d2662b22 100755
--- a/website/content/ChapterFour/0210.Course-Schedule-II.md
+++ b/website/content/ChapterFour/0210.Course-Schedule-II.md
@@ -77,4 +77,11 @@ func findOrder(numCourses int, prerequisites [][]int) []int {
return []int{}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md b/website/content/ChapterFour/0211.Design-Add-and-Search-Words-Data-Structure.md
similarity index 83%
rename from website/content/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md
rename to website/content/ChapterFour/0211.Design-Add-and-Search-Words-Data-Structure.md
index ba8502f7..171e82cc 100755
--- a/website/content/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md
+++ b/website/content/ChapterFour/0211.Design-Add-and-Search-Words-Data-Structure.md
@@ -1,4 +1,4 @@
-# [211. Add and Search Word - Data structure design](https://leetcode.com/problems/add-and-search-word-data-structure-design/)
+# [211. Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
## 题目
@@ -92,4 +92,11 @@ func (this *WordDictionary) Search(word string) bool {
* param_2 := obj.Search(word);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0212.Word-Search-II.md b/website/content/ChapterFour/0212.Word-Search-II.md
index b277984b..f83123dc 100755
--- a/website/content/ChapterFour/0212.Word-Search-II.md
+++ b/website/content/ChapterFour/0212.Word-Search-II.md
@@ -54,4 +54,11 @@ func findWords(board [][]byte, words []string) []string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0213.House-Robber-II.md b/website/content/ChapterFour/0213.House-Robber-II.md
index b53c02f6..4860b757 100755
--- a/website/content/ChapterFour/0213.House-Robber-II.md
+++ b/website/content/ChapterFour/0213.House-Robber-II.md
@@ -67,4 +67,11 @@ func rob213_1(nums []int, start, end int) int {
return curMax
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0215.Kth-Largest-Element-in-an-Array.md b/website/content/ChapterFour/0215.Kth-Largest-Element-in-an-Array.md
index babad9e9..ed9137fd 100644
--- a/website/content/ChapterFour/0215.Kth-Largest-Element-in-an-Array.md
+++ b/website/content/ChapterFour/0215.Kth-Largest-Element-in-an-Array.md
@@ -73,4 +73,11 @@ func selection(arr []int, l, r, k int) int {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0216.Combination-Sum-III.md b/website/content/ChapterFour/0216.Combination-Sum-III.md
index 8aadea35..97e953dc 100755
--- a/website/content/ChapterFour/0216.Combination-Sum-III.md
+++ b/website/content/ChapterFour/0216.Combination-Sum-III.md
@@ -70,4 +70,11 @@ func findcombinationSum3(k, target, index int, c []int, res *[][]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0217.Contains-Duplicate.md b/website/content/ChapterFour/0217.Contains-Duplicate.md
index c9ce8b43..2a078acd 100644
--- a/website/content/ChapterFour/0217.Contains-Duplicate.md
+++ b/website/content/ChapterFour/0217.Contains-Duplicate.md
@@ -59,4 +59,11 @@ func containsDuplicate(nums []int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0218.The-Skyline-Problem.md b/website/content/ChapterFour/0218.The-Skyline-Problem.md
index 0a4f2bc6..71fa6d02 100755
--- a/website/content/ChapterFour/0218.The-Skyline-Problem.md
+++ b/website/content/ChapterFour/0218.The-Skyline-Problem.md
@@ -284,4 +284,11 @@ func (q *IndexMaxPQ) less(i, j int) bool {
return q.items[q.pq[i]] < q.items[q.pq[j]]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0219.Contains-Duplicate-II.md b/website/content/ChapterFour/0219.Contains-Duplicate-II.md
index 8cf856a3..37772d36 100644
--- a/website/content/ChapterFour/0219.Contains-Duplicate-II.md
+++ b/website/content/ChapterFour/0219.Contains-Duplicate-II.md
@@ -66,4 +66,11 @@ func containsNearbyDuplicate(nums []int, k int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0220.Contains-Duplicate-III.md b/website/content/ChapterFour/0220.Contains-Duplicate-III.md
index 9dcd3f1b..a9df8c3f 100644
--- a/website/content/ChapterFour/0220.Contains-Duplicate-III.md
+++ b/website/content/ChapterFour/0220.Contains-Duplicate-III.md
@@ -100,4 +100,11 @@ func containsNearbyAlmostDuplicate1(nums []int, k int, t int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0222.Count-Complete-Tree-Nodes.md b/website/content/ChapterFour/0222.Count-Complete-Tree-Nodes.md
index b2a21ebe..88f00d48 100644
--- a/website/content/ChapterFour/0222.Count-Complete-Tree-Nodes.md
+++ b/website/content/ChapterFour/0222.Count-Complete-Tree-Nodes.md
@@ -79,4 +79,11 @@ func countNodes(root *TreeNode) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0223.Rectangle-Area.md b/website/content/ChapterFour/0223.Rectangle-Area.md
index 08d9c64d..c129f609 100755
--- a/website/content/ChapterFour/0223.Rectangle-Area.md
+++ b/website/content/ChapterFour/0223.Rectangle-Area.md
@@ -50,4 +50,11 @@ func area(x0, y0, x1, y1 int) int {
return l * h
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0224.Basic-Calculator.md b/website/content/ChapterFour/0224.Basic-Calculator.md
index 5861726a..dae86172 100755
--- a/website/content/ChapterFour/0224.Basic-Calculator.md
+++ b/website/content/ChapterFour/0224.Basic-Calculator.md
@@ -162,4 +162,11 @@ func isDigital(v byte) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0225.Implement-Stack-using-Queues.md b/website/content/ChapterFour/0225.Implement-Stack-using-Queues.md
index 11ef4866..9a1be896 100644
--- a/website/content/ChapterFour/0225.Implement-Stack-using-Queues.md
+++ b/website/content/ChapterFour/0225.Implement-Stack-using-Queues.md
@@ -92,4 +92,11 @@ func (this *MyStack) Empty() bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0226.Invert-Binary-Tree.md b/website/content/ChapterFour/0226.Invert-Binary-Tree.md
index 8fae9dff..844f3e90 100644
--- a/website/content/ChapterFour/0226.Invert-Binary-Tree.md
+++ b/website/content/ChapterFour/0226.Invert-Binary-Tree.md
@@ -73,4 +73,11 @@ func invertTree(root *TreeNode) *TreeNode {
return root
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0228.Summary-Ranges.md b/website/content/ChapterFour/0228.Summary-Ranges.md
new file mode 100644
index 00000000..3a2a53ec
--- /dev/null
+++ b/website/content/ChapterFour/0228.Summary-Ranges.md
@@ -0,0 +1,115 @@
+# [228. Summary Ranges](https://leetcode.com/problems/summary-ranges/)
+
+
+## 题目
+
+You are given a **sorted unique** integer array `nums`.
+
+Return *the **smallest sorted** list of ranges that **cover all the numbers in the array exactly***. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`.
+
+Each range `[a,b]` in the list should be output as:
+
+- `"a->b"` if `a != b`
+- `"a"` if `a == b`
+
+**Example 1**:
+
+```
+Input: nums = [0,1,2,4,5,7]
+Output: ["0->2","4->5","7"]
+Explanation: The ranges are:
+[0,2] --> "0->2"
+[4,5] --> "4->5"
+[7,7] --> "7"
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [0,2,3,4,6,8,9]
+Output: ["0","2->4","6","8->9"]
+Explanation: The ranges are:
+[0,0] --> "0"
+[2,4] --> "2->4"
+[6,6] --> "6"
+[8,9] --> "8->9"
+
+```
+
+**Example 3**:
+
+```
+Input: nums = []
+Output: []
+
+```
+
+**Example 4**:
+
+```
+Input: nums = [-1]
+Output: ["-1"]
+
+```
+
+**Example 5**:
+
+```
+Input: nums = [0]
+Output: ["0"]
+
+```
+
+**Constraints**:
+
+- `0 <= nums.length <= 20`
+- `231 <= nums[i] <= 231 - 1`
+- All the values of `nums` are **unique**.
+- `nums` is sorted in ascending order.
+
+## 题目大意
+
+给定一个无重复元素的有序整数数组 nums 。
+
+返回 恰好覆盖数组中所有数字 的 最小有序 区间范围列表。也就是说,nums 的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个范围但不属于 nums 的数字 x 。
+
+列表中的每个区间范围 [a,b] 应该按如下格式输出:
+
+- "a->b" ,如果 a != b
+- "a" ,如果 a == b
+
+## 解题思路
+
+- 简单题。按照题意,用一个游标变量累加寻找连续的区间。一旦出现了中断,就按照题意格式输出。输出的规则有多种,带箭头的区间,单个元素区间,空区间。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "strconv"
+)
+
+func summaryRanges(nums []int) (ans []string) {
+ for i, n := 0, len(nums); i < n; {
+ left := i
+ for i++; i < n && nums[i-1]+1 == nums[i]; i++ {
+ }
+ s := strconv.Itoa(nums[left])
+ if left != i-1 {
+ s += "->" + strconv.Itoa(nums[i-1])
+ }
+ ans = append(ans, s)
+ }
+ return
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0229.Majority-Element-II.md b/website/content/ChapterFour/0229.Majority-Element-II.md
index ce926058..45cbf0db 100755
--- a/website/content/ChapterFour/0229.Majority-Element-II.md
+++ b/website/content/ChapterFour/0229.Majority-Element-II.md
@@ -97,4 +97,11 @@ func majorityElement229_1(nums []int) []int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md b/website/content/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md
index b874e616..45fcea55 100755
--- a/website/content/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md
+++ b/website/content/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md
@@ -75,4 +75,11 @@ func inorder230(node *TreeNode, k int, count *int, ans *int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0231.Power-of-Two.md b/website/content/ChapterFour/0231.Power-of-Two.md
index d2b3d492..157f91e5 100755
--- a/website/content/ChapterFour/0231.Power-of-Two.md
+++ b/website/content/ChapterFour/0231.Power-of-Two.md
@@ -67,4 +67,11 @@ func isPowerOfTwo3(num int) bool {
return num == 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0232.Implement-Queue-using-Stacks.md b/website/content/ChapterFour/0232.Implement-Queue-using-Stacks.md
index fded5d37..6ceaa1b0 100644
--- a/website/content/ChapterFour/0232.Implement-Queue-using-Stacks.md
+++ b/website/content/ChapterFour/0232.Implement-Queue-using-Stacks.md
@@ -96,4 +96,11 @@ func (this *MyQueue) fromStackToQueue(s, q *[]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0234.Palindrome-Linked-List.md b/website/content/ChapterFour/0234.Palindrome-Linked-List.md
index f883bea3..56eca338 100644
--- a/website/content/ChapterFour/0234.Palindrome-Linked-List.md
+++ b/website/content/ChapterFour/0234.Palindrome-Linked-List.md
@@ -108,4 +108,11 @@ func L2ss(head *ListNode) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md b/website/content/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md
index 6cadb8e9..73a9a443 100755
--- a/website/content/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md
+++ b/website/content/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md
@@ -69,4 +69,11 @@ func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode {
return root
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md b/website/content/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md
index ccd47234..96342c14 100755
--- a/website/content/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md
+++ b/website/content/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md
@@ -69,4 +69,11 @@ func lowestCommonAncestor236(root, p, q *TreeNode) *TreeNode {
return right
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0237.Delete-Node-in-a-Linked-List.md b/website/content/ChapterFour/0237.Delete-Node-in-a-Linked-List.md
index c431655d..981fe415 100644
--- a/website/content/ChapterFour/0237.Delete-Node-in-a-Linked-List.md
+++ b/website/content/ChapterFour/0237.Delete-Node-in-a-Linked-List.md
@@ -69,4 +69,11 @@ func deleteNode(node *ListNode) {
cur.Next = nil
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0239.Sliding-Window-Maximum.md b/website/content/ChapterFour/0239.Sliding-Window-Maximum.md
index dd1cd697..ea5a4493 100755
--- a/website/content/ChapterFour/0239.Sliding-Window-Maximum.md
+++ b/website/content/ChapterFour/0239.Sliding-Window-Maximum.md
@@ -92,4 +92,11 @@ func maxSlidingWindow(nums []int, k int) []int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0240.Search-a-2D-Matrix-II.md b/website/content/ChapterFour/0240.Search-a-2D-Matrix-II.md
index d8d92a10..736d4ba4 100755
--- a/website/content/ChapterFour/0240.Search-a-2D-Matrix-II.md
+++ b/website/content/ChapterFour/0240.Search-a-2D-Matrix-II.md
@@ -86,4 +86,11 @@ func searchMatrix2401(matrix [][]int, target int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0242.Valid-Anagram.md b/website/content/ChapterFour/0242.Valid-Anagram.md
index cc243f3e..7f643f68 100644
--- a/website/content/ChapterFour/0242.Valid-Anagram.md
+++ b/website/content/ChapterFour/0242.Valid-Anagram.md
@@ -114,4 +114,11 @@ func quickSortByte(a []byte, lo, hi int) {
quickSortByte(a, p+1, hi)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0257.Binary-Tree-Paths.md b/website/content/ChapterFour/0257.Binary-Tree-Paths.md
index 5ee5f35f..eaef55f8 100755
--- a/website/content/ChapterFour/0257.Binary-Tree-Paths.md
+++ b/website/content/ChapterFour/0257.Binary-Tree-Paths.md
@@ -68,4 +68,11 @@ func binaryTreePaths(root *TreeNode) []string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0258.Add-Digits.md b/website/content/ChapterFour/0258.Add-Digits.md
index 8c811904..57abdabc 100644
--- a/website/content/ChapterFour/0258.Add-Digits.md
+++ b/website/content/ChapterFour/0258.Add-Digits.md
@@ -44,4 +44,11 @@ func addDigits(num int) int {
return num
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0260.Single-Number-III.md b/website/content/ChapterFour/0260.Single-Number-III.md
index fa8e45b5..a5c74bf0 100755
--- a/website/content/ChapterFour/0260.Single-Number-III.md
+++ b/website/content/ChapterFour/0260.Single-Number-III.md
@@ -58,4 +58,11 @@ func singleNumberIII(nums []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0263.Ugly-Number.md b/website/content/ChapterFour/0263.Ugly-Number.md
index e677f673..4e04b40e 100644
--- a/website/content/ChapterFour/0263.Ugly-Number.md
+++ b/website/content/ChapterFour/0263.Ugly-Number.md
@@ -66,4 +66,11 @@ func isUgly(num int) bool {
return num == 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0268.Missing-Number.md b/website/content/ChapterFour/0268.Missing-Number.md
index cf72f8c0..f5bafc72 100755
--- a/website/content/ChapterFour/0268.Missing-Number.md
+++ b/website/content/ChapterFour/0268.Missing-Number.md
@@ -44,4 +44,11 @@ func missingNumber(nums []int) int {
return xor ^ i
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0274.H-Index.md b/website/content/ChapterFour/0274.H-Index.md
index 4306deed..fd961ebc 100644
--- a/website/content/ChapterFour/0274.H-Index.md
+++ b/website/content/ChapterFour/0274.H-Index.md
@@ -75,4 +75,11 @@ func hIndex1(citations []int) int {
return hIndex
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0275.H-Index-II.md b/website/content/ChapterFour/0275.H-Index-II.md
index 21310f01..880d39d3 100755
--- a/website/content/ChapterFour/0275.H-Index-II.md
+++ b/website/content/ChapterFour/0275.H-Index-II.md
@@ -68,4 +68,11 @@ func hIndex275(citations []int) int {
return len(citations) - low
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0283.Move-Zeroes.md b/website/content/ChapterFour/0283.Move-Zeroes.md
index f7c334ea..48c52dd7 100644
--- a/website/content/ChapterFour/0283.Move-Zeroes.md
+++ b/website/content/ChapterFour/0283.Move-Zeroes.md
@@ -52,4 +52,11 @@ func moveZeroes(nums []int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0287.Find-the-Duplicate-Number.md b/website/content/ChapterFour/0287.Find-the-Duplicate-Number.md
index a8146fe3..11dc7ccf 100644
--- a/website/content/ChapterFour/0287.Find-the-Duplicate-Number.md
+++ b/website/content/ChapterFour/0287.Find-the-Duplicate-Number.md
@@ -104,4 +104,11 @@ func findDuplicate2(nums []int) int {
return 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0290.Word-Pattern.md b/website/content/ChapterFour/0290.Word-Pattern.md
index d7764d4e..d22b9623 100644
--- a/website/content/ChapterFour/0290.Word-Pattern.md
+++ b/website/content/ChapterFour/0290.Word-Pattern.md
@@ -95,4 +95,11 @@ func wordPattern(pattern string, str string) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0300.Longest-Increasing-Subsequence.md b/website/content/ChapterFour/0300.Longest-Increasing-Subsequence.md
index eb6436a6..3d678515 100755
--- a/website/content/ChapterFour/0300.Longest-Increasing-Subsequence.md
+++ b/website/content/ChapterFour/0300.Longest-Increasing-Subsequence.md
@@ -76,4 +76,11 @@ func lengthOfLIS1(nums []int) int {
return len(dp)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0303.Range-Sum-Query---Immutable.md b/website/content/ChapterFour/0303.Range-Sum-Query---Immutable.md
index 12ebbe67..9f24536e 100755
--- a/website/content/ChapterFour/0303.Range-Sum-Query---Immutable.md
+++ b/website/content/ChapterFour/0303.Range-Sum-Query---Immutable.md
@@ -107,4 +107,11 @@ func (ma *NumArray) SumRange(i int, j int) int {
* param_1 := obj.SumRange(i,j);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0306.Additive-Number.md b/website/content/ChapterFour/0306.Additive-Number.md
index 4d188472..b3ed5be6 100755
--- a/website/content/ChapterFour/0306.Additive-Number.md
+++ b/website/content/ChapterFour/0306.Additive-Number.md
@@ -86,4 +86,11 @@ func recursiveCheck(num string, x1 int, x2 int, left int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0307.Range-Sum-Query---Mutable.md b/website/content/ChapterFour/0307.Range-Sum-Query---Mutable.md
index 1d17bbec..c8618b62 100755
--- a/website/content/ChapterFour/0307.Range-Sum-Query---Mutable.md
+++ b/website/content/ChapterFour/0307.Range-Sum-Query---Mutable.md
@@ -118,4 +118,11 @@ func (this *NumArray) Update(i int, val int) {
* param_2 := obj.SumRange(i,j);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md b/website/content/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md
index f9d6d14a..efd0363d 100755
--- a/website/content/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md
+++ b/website/content/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md
@@ -81,4 +81,11 @@ func maxProfit309_1(prices []int) int {
return sell[(len(prices)-1)%3]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md b/website/content/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md
index e82ba661..77b9e627 100755
--- a/website/content/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md
+++ b/website/content/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md
@@ -85,4 +85,11 @@ func countSmaller(nums []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md b/website/content/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md
index 7020a8bd..de8f712c 100755
--- a/website/content/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md
+++ b/website/content/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md
@@ -74,4 +74,11 @@ func maxProduct318(words []string) int {
return maxProduct
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0322.Coin-Change.md b/website/content/ChapterFour/0322.Coin-Change.md
index ee3adf0b..4e15b87c 100755
--- a/website/content/ChapterFour/0322.Coin-Change.md
+++ b/website/content/ChapterFour/0322.Coin-Change.md
@@ -58,4 +58,11 @@ func coinChange(coins []int, amount int) int {
return dp[amount]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0324.Wiggle-Sort-II.md b/website/content/ChapterFour/0324.Wiggle-Sort-II.md
index d8baed57..5047b8f0 100644
--- a/website/content/ChapterFour/0324.Wiggle-Sort-II.md
+++ b/website/content/ChapterFour/0324.Wiggle-Sort-II.md
@@ -260,4 +260,11 @@ func wiggleSort1(nums []int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0326.Power-of-Three.md b/website/content/ChapterFour/0326.Power-of-Three.md
index 7455f864..38328b88 100755
--- a/website/content/ChapterFour/0326.Power-of-Three.md
+++ b/website/content/ChapterFour/0326.Power-of-Three.md
@@ -74,4 +74,11 @@ func isPowerOfThree2(num int) bool {
return num == 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0327.Count-of-Range-Sum.md b/website/content/ChapterFour/0327.Count-of-Range-Sum.md
index 87a5d324..30779996 100755
--- a/website/content/ChapterFour/0327.Count-of-Range-Sum.md
+++ b/website/content/ChapterFour/0327.Count-of-Range-Sum.md
@@ -142,4 +142,11 @@ func countRangeSum1(nums []int, lower int, upper int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0328.Odd-Even-Linked-List.md b/website/content/ChapterFour/0328.Odd-Even-Linked-List.md
index b7201e5d..3e76e37c 100644
--- a/website/content/ChapterFour/0328.Odd-Even-Linked-List.md
+++ b/website/content/ChapterFour/0328.Odd-Even-Linked-List.md
@@ -74,4 +74,11 @@ func oddEvenList(head *ListNode) *ListNode {
return oddHead.Next
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0329.Longest-Increasing-Path-in-a-Matrix.md b/website/content/ChapterFour/0329.Longest-Increasing-Path-in-a-Matrix.md
index 4ae43112..f26eb117 100755
--- a/website/content/ChapterFour/0329.Longest-Increasing-Path-in-a-Matrix.md
+++ b/website/content/ChapterFour/0329.Longest-Increasing-Path-in-a-Matrix.md
@@ -89,4 +89,11 @@ func searchPath(board, cache [][]int, lastNum, x, y int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md b/website/content/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md
index 8df741a1..83ba9b8d 100644
--- a/website/content/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md
+++ b/website/content/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md
@@ -82,4 +82,11 @@ func isValidSerialization(preorder string) bool {
return diff == 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0337.House-Robber-III.md b/website/content/ChapterFour/0337.House-Robber-III.md
index e8451881..d524b3d3 100644
--- a/website/content/ChapterFour/0337.House-Robber-III.md
+++ b/website/content/ChapterFour/0337.House-Robber-III.md
@@ -70,4 +70,11 @@ func dfsTreeRob(root *TreeNode) (a, b int) {
return tmp0, tmp1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0338.Counting-Bits.md b/website/content/ChapterFour/0338.Counting-Bits.md
index ea8e0de2..a543d869 100755
--- a/website/content/ChapterFour/0338.Counting-Bits.md
+++ b/website/content/ChapterFour/0338.Counting-Bits.md
@@ -51,4 +51,11 @@ func countBits(num int) []int {
return bits
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0342.Power-of-Four.md b/website/content/ChapterFour/0342.Power-of-Four.md
index 64782049..221989d8 100755
--- a/website/content/ChapterFour/0342.Power-of-Four.md
+++ b/website/content/ChapterFour/0342.Power-of-Four.md
@@ -52,4 +52,11 @@ func isPowerOfFour1(num int) bool {
return num == 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0343.Integer-Break.md b/website/content/ChapterFour/0343.Integer-Break.md
index cfa558d7..3ca9c6af 100755
--- a/website/content/ChapterFour/0343.Integer-Break.md
+++ b/website/content/ChapterFour/0343.Integer-Break.md
@@ -50,4 +50,11 @@ func integerBreak(n int) int {
return dp[n]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0344.Reverse-String.md b/website/content/ChapterFour/0344.Reverse-String.md
index f3568648..493fbe3b 100644
--- a/website/content/ChapterFour/0344.Reverse-String.md
+++ b/website/content/ChapterFour/0344.Reverse-String.md
@@ -50,4 +50,11 @@ func reverseString(s []byte) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0345.Reverse-Vowels-of-a-String.md b/website/content/ChapterFour/0345.Reverse-Vowels-of-a-String.md
index 2cbb07fb..bd7679af 100644
--- a/website/content/ChapterFour/0345.Reverse-Vowels-of-a-String.md
+++ b/website/content/ChapterFour/0345.Reverse-Vowels-of-a-String.md
@@ -66,4 +66,11 @@ func isVowels(s byte) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0347.Top-K-Frequent-Elements.md b/website/content/ChapterFour/0347.Top-K-Frequent-Elements.md
index c2a98fcd..ea1d85b1 100644
--- a/website/content/ChapterFour/0347.Top-K-Frequent-Elements.md
+++ b/website/content/ChapterFour/0347.Top-K-Frequent-Elements.md
@@ -100,4 +100,11 @@ func (pq *PriorityQueue) Pop() interface{} {
return item
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0349.Intersection-of-Two-Arrays.md b/website/content/ChapterFour/0349.Intersection-of-Two-Arrays.md
index 8f8ad399..ade24e62 100644
--- a/website/content/ChapterFour/0349.Intersection-of-Two-Arrays.md
+++ b/website/content/ChapterFour/0349.Intersection-of-Two-Arrays.md
@@ -57,4 +57,11 @@ func intersection(nums1 []int, nums2 []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0350.Intersection-of-Two-Arrays-II.md b/website/content/ChapterFour/0350.Intersection-of-Two-Arrays-II.md
index dc92b38c..eb94c11d 100644
--- a/website/content/ChapterFour/0350.Intersection-of-Two-Arrays-II.md
+++ b/website/content/ChapterFour/0350.Intersection-of-Two-Arrays-II.md
@@ -69,4 +69,11 @@ func intersect(nums1 []int, nums2 []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0354.Russian-Doll-Envelopes.md b/website/content/ChapterFour/0354.Russian-Doll-Envelopes.md
index 810345d3..8100d0f6 100755
--- a/website/content/ChapterFour/0354.Russian-Doll-Envelopes.md
+++ b/website/content/ChapterFour/0354.Russian-Doll-Envelopes.md
@@ -78,4 +78,11 @@ func maxEnvelopes(envelopes [][]int) int {
return len(dp)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md b/website/content/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md
index 021b4187..6c7583a6 100755
--- a/website/content/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md
+++ b/website/content/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md
@@ -58,4 +58,11 @@ func countNumbersWithUniqueDigits(n int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0367.Valid-Perfect-Square.md b/website/content/ChapterFour/0367.Valid-Perfect-Square.md
index 50584b0d..0edd6fc0 100755
--- a/website/content/ChapterFour/0367.Valid-Perfect-Square.md
+++ b/website/content/ChapterFour/0367.Valid-Perfect-Square.md
@@ -54,4 +54,11 @@ func isPerfectSquare(num int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0371.Sum-of-Two-Integers.md b/website/content/ChapterFour/0371.Sum-of-Two-Integers.md
index 31318dd7..423f35b1 100755
--- a/website/content/ChapterFour/0371.Sum-of-Two-Integers.md
+++ b/website/content/ChapterFour/0371.Sum-of-Two-Integers.md
@@ -44,4 +44,11 @@ func getSum(a int, b int) int {
return getSum((a&b)<<1, a^b)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0372.Super-Pow.md b/website/content/ChapterFour/0372.Super-Pow.md
index 79b2830c..1bb73d92 100755
--- a/website/content/ChapterFour/0372.Super-Pow.md
+++ b/website/content/ChapterFour/0372.Super-Pow.md
@@ -105,4 +105,11 @@ func superPow1(a int, b []int) int {
return f * l % 1337
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0373.Find-K-Pairs-with-Smallest-Sums.md b/website/content/ChapterFour/0373.Find-K-Pairs-with-Smallest-Sums.md
index 237c063d..85bb5352 100755
--- a/website/content/ChapterFour/0373.Find-K-Pairs-with-Smallest-Sums.md
+++ b/website/content/ChapterFour/0373.Find-K-Pairs-with-Smallest-Sums.md
@@ -123,4 +123,11 @@ func kSmallestPairs1(nums1 []int, nums2 []int, k int) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0378.Kth-Smallest-Element-in-a-Sorted-Matrix.md b/website/content/ChapterFour/0378.Kth-Smallest-Element-in-a-Sorted-Matrix.md
index 922adeeb..9f675463 100755
--- a/website/content/ChapterFour/0378.Kth-Smallest-Element-in-a-Sorted-Matrix.md
+++ b/website/content/ChapterFour/0378.Kth-Smallest-Element-in-a-Sorted-Matrix.md
@@ -132,4 +132,11 @@ func (p *pq) Pop() interface{} {
return p.data[p.len]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0385.Mini-Parser.md b/website/content/ChapterFour/0385.Mini-Parser.md
index 57a00d32..93706631 100755
--- a/website/content/ChapterFour/0385.Mini-Parser.md
+++ b/website/content/ChapterFour/0385.Mini-Parser.md
@@ -172,4 +172,11 @@ func deserialize(s string) *NestedInteger {
return cur
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0386.Lexicographical-Numbers.md b/website/content/ChapterFour/0386.Lexicographical-Numbers.md
index 7bb82d4b..2b448727 100755
--- a/website/content/ChapterFour/0386.Lexicographical-Numbers.md
+++ b/website/content/ChapterFour/0386.Lexicographical-Numbers.md
@@ -48,4 +48,11 @@ func dfs386(x, n int, res *[]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0387.First-Unique-Character-in-a-String.md b/website/content/ChapterFour/0387.First-Unique-Character-in-a-String.md
index b3ccff4c..211fab68 100755
--- a/website/content/ChapterFour/0387.First-Unique-Character-in-a-String.md
+++ b/website/content/ChapterFour/0387.First-Unique-Character-in-a-String.md
@@ -24,6 +24,7 @@ Given a string, find the first non-repeating character in it and return it's ind
## 解题思路
- 简单题,要求输出第一个没有重复的字符。
+- 解法二这个思路只超过 81% 的用户,但是如果测试样例中 s 的字符串很长,但是满足条件的字符都在靠后的位置的话,这个思路应该会更有优势。通过记录每个字符的第一次出现的位置和最后一次出现的位置。第一次对 s 进行一次遍历。第二次仅仅对数组进行遍历就可以了。
## 代码
@@ -32,6 +33,7 @@ Given a string, find the first non-repeating character in it and return it's ind
package leetcode
+// 解法 一
func firstUniqChar(s string) int {
result := make([]int, 26)
for i := 0; i < len(s); i++ {
@@ -45,4 +47,42 @@ func firstUniqChar(s string) int {
return -1
}
-```
\ No newline at end of file
+// 解法 二
+// 执行用时: 8 ms
+// 内存消耗: 5.2 MB
+func firstUniqChar1(s string) int {
+ charMap := make([][2]int, 26)
+ for i := 0; i < 26; i++ {
+ charMap[i][0] = -1
+ charMap[i][1] = -1
+ }
+ for i := 0; i < len(s); i++ {
+ if charMap[s[i]-'a'][0] == -1 {
+ charMap[s[i]-'a'][0] = i
+ } else { //已经出现过
+ charMap[s[i]-'a'][1] = i
+ }
+ }
+ res := len(s)
+ for i := 0; i < 26; i++ {
+ //只出现了一次
+ if charMap[i][0] >= 0 && charMap[i][1] == -1 {
+ if charMap[i][0] < res {
+ res = charMap[i][0]
+ }
+ }
+ }
+ if res == len(s) {
+ return -1
+ }
+ return res
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0389.Find-the-Difference.md b/website/content/ChapterFour/0389.Find-the-Difference.md
index 57b53354..026b6f99 100755
--- a/website/content/ChapterFour/0389.Find-the-Difference.md
+++ b/website/content/ChapterFour/0389.Find-the-Difference.md
@@ -45,4 +45,11 @@ func findTheDifference(s string, t string) byte {
return ch
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0392.Is-Subsequence.md b/website/content/ChapterFour/0392.Is-Subsequence.md
index 09ff2c75..7b11b78e 100755
--- a/website/content/ChapterFour/0392.Is-Subsequence.md
+++ b/website/content/ChapterFour/0392.Is-Subsequence.md
@@ -77,4 +77,11 @@ func isSubsequence1(s string, t string) bool {
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0393.UTF-8-Validation.md b/website/content/ChapterFour/0393.UTF-8-Validation.md
index 1d8b50fb..b1efbce0 100755
--- a/website/content/ChapterFour/0393.UTF-8-Validation.md
+++ b/website/content/ChapterFour/0393.UTF-8-Validation.md
@@ -102,4 +102,11 @@ func validUtf8(data []int) bool {
return count == 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0394.Decode-String.md b/website/content/ChapterFour/0394.Decode-String.md
index 93a71bce..902049c3 100644
--- a/website/content/ChapterFour/0394.Decode-String.md
+++ b/website/content/ChapterFour/0394.Decode-String.md
@@ -78,4 +78,11 @@ func decodeString(s string) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0397.Integer-Replacement.md b/website/content/ChapterFour/0397.Integer-Replacement.md
index 1dea6f59..67691292 100755
--- a/website/content/ChapterFour/0397.Integer-Replacement.md
+++ b/website/content/ChapterFour/0397.Integer-Replacement.md
@@ -83,4 +83,11 @@ func integerReplacement(n int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0399.Evaluate-Division.md b/website/content/ChapterFour/0399.Evaluate-Division.md
index d4cf4524..cdefaf23 100755
--- a/website/content/ChapterFour/0399.Evaluate-Division.md
+++ b/website/content/ChapterFour/0399.Evaluate-Division.md
@@ -114,4 +114,11 @@ func calcEquation(equations [][]string, values []float64, queries [][]string) []
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0401.Binary-Watch.md b/website/content/ChapterFour/0401.Binary-Watch.md
index 0d40d6f2..ae9162a2 100755
--- a/website/content/ChapterFour/0401.Binary-Watch.md
+++ b/website/content/ChapterFour/0401.Binary-Watch.md
@@ -135,4 +135,11 @@ func findReadBinaryWatchHour(target, index int, c []int, res *[]string) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0402.Remove-K-Digits.md b/website/content/ChapterFour/0402.Remove-K-Digits.md
index 52c3ce27..e8f6c0e4 100644
--- a/website/content/ChapterFour/0402.Remove-K-Digits.md
+++ b/website/content/ChapterFour/0402.Remove-K-Digits.md
@@ -85,4 +85,11 @@ func removeKdigits(num string, k int) string {
return string(res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0404.Sum-of-Left-Leaves.md b/website/content/ChapterFour/0404.Sum-of-Left-Leaves.md
index c2103dbe..18c83472 100755
--- a/website/content/ChapterFour/0404.Sum-of-Left-Leaves.md
+++ b/website/content/ChapterFour/0404.Sum-of-Left-Leaves.md
@@ -52,4 +52,11 @@ func sumOfLeftLeaves(root *TreeNode) int {
return sumOfLeftLeaves(root.Left) + sumOfLeftLeaves(root.Right)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md b/website/content/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md
index c77a0258..52d661c8 100755
--- a/website/content/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md
+++ b/website/content/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md
@@ -77,4 +77,11 @@ func toHex(num int) string {
return str
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0409.Longest-Palindrome.md b/website/content/ChapterFour/0409.Longest-Palindrome.md
index a0e18ad1..f0d3f136 100755
--- a/website/content/ChapterFour/0409.Longest-Palindrome.md
+++ b/website/content/ChapterFour/0409.Longest-Palindrome.md
@@ -54,4 +54,11 @@ func longestPalindrome(s string) int {
return answer
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0410.Split-Array-Largest-Sum.md b/website/content/ChapterFour/0410.Split-Array-Largest-Sum.md
index f4ce4e9b..5620d814 100755
--- a/website/content/ChapterFour/0410.Split-Array-Largest-Sum.md
+++ b/website/content/ChapterFour/0410.Split-Array-Largest-Sum.md
@@ -89,4 +89,11 @@ func calSum(mid, m int, nums []int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0412.Fizz-Buzz.md b/website/content/ChapterFour/0412.Fizz-Buzz.md
index cf9fdd90..2dd24805 100644
--- a/website/content/ChapterFour/0412.Fizz-Buzz.md
+++ b/website/content/ChapterFour/0412.Fizz-Buzz.md
@@ -68,4 +68,11 @@ func fizzBuzz(n int) []string {
return solution
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0414.Third-Maximum-Number.md b/website/content/ChapterFour/0414.Third-Maximum-Number.md
index 7c8ef633..cd2224b0 100644
--- a/website/content/ChapterFour/0414.Third-Maximum-Number.md
+++ b/website/content/ChapterFour/0414.Third-Maximum-Number.md
@@ -69,4 +69,11 @@ func thirdMax(nums []int) int {
return c
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0416.Partition-Equal-Subset-Sum.md b/website/content/ChapterFour/0416.Partition-Equal-Subset-Sum.md
index ce3a79cc..94fe2e3c 100755
--- a/website/content/ChapterFour/0416.Partition-Equal-Subset-Sum.md
+++ b/website/content/ChapterFour/0416.Partition-Equal-Subset-Sum.md
@@ -73,4 +73,11 @@ func canPartition(nums []int) bool {
return dp[C]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md b/website/content/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md
index e4c527b3..688e41e3 100755
--- a/website/content/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md
+++ b/website/content/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md
@@ -96,4 +96,11 @@ func findMaximumXOR1(nums []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0424.Longest-Repeating-Character-Replacement.md b/website/content/ChapterFour/0424.Longest-Repeating-Character-Replacement.md
index 8e54fbcc..1762c02c 100644
--- a/website/content/ChapterFour/0424.Longest-Repeating-Character-Replacement.md
+++ b/website/content/ChapterFour/0424.Longest-Repeating-Character-Replacement.md
@@ -82,4 +82,11 @@ func max(a int, b int) int {
return b
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0433.Minimum-Genetic-Mutation.md b/website/content/ChapterFour/0433.Minimum-Genetic-Mutation.md
index 8fea5ecf..309dece2 100755
--- a/website/content/ChapterFour/0433.Minimum-Genetic-Mutation.md
+++ b/website/content/ChapterFour/0433.Minimum-Genetic-Mutation.md
@@ -180,4 +180,11 @@ func convert(gene string) uint32 {
return v
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0435.Non-overlapping-Intervals.md b/website/content/ChapterFour/0435.Non-overlapping-Intervals.md
index ff8c9074..de0366f7 100755
--- a/website/content/ChapterFour/0435.Non-overlapping-Intervals.md
+++ b/website/content/ChapterFour/0435.Non-overlapping-Intervals.md
@@ -132,4 +132,11 @@ func eraseOverlapIntervals1(intervals [][]int) int {
return len(intervals) - res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0436.Find-Right-Interval.md b/website/content/ChapterFour/0436.Find-Right-Interval.md
index 2bb73c8d..5aef3a4a 100755
--- a/website/content/ChapterFour/0436.Find-Right-Interval.md
+++ b/website/content/ChapterFour/0436.Find-Right-Interval.md
@@ -139,4 +139,11 @@ func searchFirstGreaterInterval(nums []Interval, target int) int {
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0437.Path-Sum-III.md b/website/content/ChapterFour/0437.Path-Sum-III.md
index 8b9811d5..51b357f6 100755
--- a/website/content/ChapterFour/0437.Path-Sum-III.md
+++ b/website/content/ChapterFour/0437.Path-Sum-III.md
@@ -82,4 +82,11 @@ func findPath437(root *TreeNode, sum int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0438.Find-All-Anagrams-in-a-String.md b/website/content/ChapterFour/0438.Find-All-Anagrams-in-a-String.md
index c422dbb1..207f321b 100644
--- a/website/content/ChapterFour/0438.Find-All-Anagrams-in-a-String.md
+++ b/website/content/ChapterFour/0438.Find-All-Anagrams-in-a-String.md
@@ -103,4 +103,11 @@ func findAnagrams(s string, p string) []int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0441.Arranging-Coins.md b/website/content/ChapterFour/0441.Arranging-Coins.md
index d76eb626..fb7ba3f7 100755
--- a/website/content/ChapterFour/0441.Arranging-Coins.md
+++ b/website/content/ChapterFour/0441.Arranging-Coins.md
@@ -72,4 +72,11 @@ func arrangeCoins1(n int) int {
return k - 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0445.Add-Two-Numbers-II.md b/website/content/ChapterFour/0445.Add-Two-Numbers-II.md
index 19c3a576..f0b62889 100644
--- a/website/content/ChapterFour/0445.Add-Two-Numbers-II.md
+++ b/website/content/ChapterFour/0445.Add-Two-Numbers-II.md
@@ -93,4 +93,11 @@ func getLength(l *ListNode) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0447.Number-of-Boomerangs.md b/website/content/ChapterFour/0447.Number-of-Boomerangs.md
index 332a6a3e..44289f4d 100644
--- a/website/content/ChapterFour/0447.Number-of-Boomerangs.md
+++ b/website/content/ChapterFour/0447.Number-of-Boomerangs.md
@@ -63,4 +63,11 @@ func dis(pa, pb []int) int {
return (pa[0]-pb[0])*(pa[0]-pb[0]) + (pa[1]-pb[1])*(pa[1]-pb[1])
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0448.Find-All-Numbers-Disappeared-in-an-Array.md b/website/content/ChapterFour/0448.Find-All-Numbers-Disappeared-in-an-Array.md
index ec98b0b4..02019d10 100644
--- a/website/content/ChapterFour/0448.Find-All-Numbers-Disappeared-in-an-Array.md
+++ b/website/content/ChapterFour/0448.Find-All-Numbers-Disappeared-in-an-Array.md
@@ -54,4 +54,11 @@ func findDisappearedNumbers(nums []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0451.Sort-Characters-By-Frequency.md b/website/content/ChapterFour/0451.Sort-Characters-By-Frequency.md
index 58558d7f..84d262a5 100644
--- a/website/content/ChapterFour/0451.Sort-Characters-By-Frequency.md
+++ b/website/content/ChapterFour/0451.Sort-Characters-By-Frequency.md
@@ -110,4 +110,11 @@ func frequencySort(s string) string {
return string(res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0453.Minimum-Moves-to-Equal-Array-Elements.md b/website/content/ChapterFour/0453.Minimum-Moves-to-Equal-Array-Elements.md
index 280f22a2..7417b7ad 100644
--- a/website/content/ChapterFour/0453.Minimum-Moves-to-Equal-Array-Elements.md
+++ b/website/content/ChapterFour/0453.Minimum-Moves-to-Equal-Array-Elements.md
@@ -48,4 +48,11 @@ func minMoves(nums []int) int {
return sum - min*l
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0454.4Sum-II.md b/website/content/ChapterFour/0454.4Sum-II.md
index 6a60ecf1..048a3452 100644
--- a/website/content/ChapterFour/0454.4Sum-II.md
+++ b/website/content/ChapterFour/0454.4Sum-II.md
@@ -62,4 +62,11 @@ func fourSumCount(A []int, B []int, C []int, D []int) int {
return ret
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0455.Assign-Cookies.md b/website/content/ChapterFour/0455.Assign-Cookies.md
index 4efda7a8..bfdff43a 100755
--- a/website/content/ChapterFour/0455.Assign-Cookies.md
+++ b/website/content/ChapterFour/0455.Assign-Cookies.md
@@ -66,4 +66,11 @@ func findContentChildren(g []int, s []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0456.132-Pattern.md b/website/content/ChapterFour/0456.132-Pattern.md
index 382c2720..425aef1a 100755
--- a/website/content/ChapterFour/0456.132-Pattern.md
+++ b/website/content/ChapterFour/0456.132-Pattern.md
@@ -100,4 +100,11 @@ func find132pattern1(nums []int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0457.Circular-Array-Loop.md b/website/content/ChapterFour/0457.Circular-Array-Loop.md
index 89756b22..3038fe2b 100755
--- a/website/content/ChapterFour/0457.Circular-Array-Loop.md
+++ b/website/content/ChapterFour/0457.Circular-Array-Loop.md
@@ -101,4 +101,11 @@ func getNextIndex(nums []int, index int) int {
return ((nums[index]+index)%len(nums) + len(nums)) % len(nums)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0460.LFU-Cache.md b/website/content/ChapterFour/0460.LFU-Cache.md
new file mode 100644
index 00000000..cc384229
--- /dev/null
+++ b/website/content/ChapterFour/0460.LFU-Cache.md
@@ -0,0 +1,149 @@
+# [460. LFU Cache](https://leetcode.com/problems/lfu-cache/)
+
+
+## 题目
+
+Design and implement a data structure for [Least Frequently Used (LFU)](https://en.wikipedia.org/wiki/Least_frequently_used) cache.
+
+Implement the `LFUCache` class:
+
+- `LFUCache(int capacity)` Initializes the object with the `capacity` of the data structure.
+- `int get(int key)` Gets the value of the `key` if the `key` exists in the cache. Otherwise, returns `1`.
+- `void put(int key, int value)` Sets or inserts the value if the `key` is not already present. When the cache reaches its `capacity`, it should invalidate the least frequently used item before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), **the least recently** used `key` would be evicted.
+
+**Notice that** the number of times an item is used is the number of calls to the `get` and `put` functions for that item since it was inserted. This number is set to zero when the item is removed.
+
+**Example 1**:
+
+```
+Input
+["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, 3, null, -1, 3, 4]
+
+Explanation
+LFUCache lfu = new LFUCache(2);
+lfu.put(1, 1);
+lfu.put(2, 2);
+lfu.get(1); // return 1
+lfu.put(3, 3); // evicts key 2
+lfu.get(2); // return -1 (not found)
+lfu.get(3); // return 3
+lfu.put(4, 4); // evicts key 1.
+lfu.get(1); // return -1 (not found)
+lfu.get(3); // return 3
+lfu.get(4); // return 4
+
+```
+
+**Constraints**:
+
+- `0 <= capacity, key, value <= 104`
+- At most `10^5` calls will be made to `get` and `put`.
+
+**Follow up**: Could you do both operations in `O(1)` time complexity?
+
+## 题目大意
+
+请你为 最不经常使用(LFU)缓存算法设计并实现数据结构。
+
+实现 LFUCache 类:
+
+- LFUCache(int capacity) - 用数据结构的容量 capacity 初始化对象
+- int get(int key) - 如果键存在于缓存中,则获取键的值,否则返回 -1。
+- void put(int key, int value) - 如果键已存在,则变更其值;如果键不存在,请插入键值对。当缓存达到其容量时,则应该在插入新项之前,使最不经常使用的项无效。在此问题中,当存在平局(即两个或更多个键具有相同使用频率)时,应该去除 最久未使用 的键。
+
+注意「项的使用次数」就是自插入该项以来对其调用 get 和 put 函数的次数之和。使用次数会在对应项被移除后置为 0 。
+
+进阶:你是否可以在 O(1) 时间复杂度内执行两项操作?
+
+## 解题思路
+
+- 这一题是 LFU 经典面试题,详细解释见第三章模板。
+
+## 代码
+
+```go
+package leetcode
+
+import "container/list"
+
+type LFUCache struct {
+ nodes map[int]*list.Element
+ lists map[int]*list.List
+ capacity int
+ min int
+}
+
+type node struct {
+ key int
+ value int
+ frequency int
+}
+
+func Constructor(capacity int) LFUCache {
+ return LFUCache{nodes: make(map[int]*list.Element),
+ lists: make(map[int]*list.List),
+ capacity: capacity,
+ min: 0,
+ }
+}
+
+func (this *LFUCache) Get(key int) int {
+ value, ok := this.nodes[key]
+ if !ok {
+ return -1
+ }
+ currentNode := value.Value.(*node)
+ this.lists[currentNode.frequency].Remove(value)
+ currentNode.frequency++
+ if _, ok := this.lists[currentNode.frequency]; !ok {
+ this.lists[currentNode.frequency] = list.New()
+ }
+ newList := this.lists[currentNode.frequency]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+ if currentNode.frequency-1 == this.min && this.lists[currentNode.frequency-1].Len() == 0 {
+ this.min++
+ }
+ return currentNode.value
+}
+
+func (this *LFUCache) Put(key int, value int) {
+ if this.capacity == 0 {
+ return
+ }
+ if currentValue, ok := this.nodes[key]; ok {
+ currentNode := currentValue.Value.(*node)
+ currentNode.value = value
+ this.Get(key)
+ return
+ }
+ if this.capacity == len(this.nodes) {
+ currentList := this.lists[this.min]
+ frontNode := currentList.Front()
+ delete(this.nodes, frontNode.Value.(*node).key)
+ currentList.Remove(frontNode)
+ }
+ this.min = 1
+ currentNode := &node{
+ key: key,
+ value: value,
+ frequency: 1,
+ }
+ if _, ok := this.lists[1]; !ok {
+ this.lists[1] = list.New()
+ }
+ newList := this.lists[1]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0461.Hamming-Distance.md b/website/content/ChapterFour/0461.Hamming-Distance.md
index 9d0d75c0..0d85bdcb 100755
--- a/website/content/ChapterFour/0461.Hamming-Distance.md
+++ b/website/content/ChapterFour/0461.Hamming-Distance.md
@@ -50,4 +50,11 @@ func hammingDistance(x int, y int) int {
return distance
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0463.Island-Perimeter.md b/website/content/ChapterFour/0463.Island-Perimeter.md
index 7a319887..b847d231 100755
--- a/website/content/ChapterFour/0463.Island-Perimeter.md
+++ b/website/content/ChapterFour/0463.Island-Perimeter.md
@@ -68,4 +68,11 @@ func islandPerimeter(grid [][]int) int {
return counter
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0470.Implement-Rand10-Using-Rand7.md b/website/content/ChapterFour/0470.Implement-Rand10-Using-Rand7.md
index 1c650ca3..06fca2cd 100755
--- a/website/content/ChapterFour/0470.Implement-Rand10-Using-Rand7.md
+++ b/website/content/ChapterFour/0470.Implement-Rand10-Using-Rand7.md
@@ -97,4 +97,11 @@ func rand101() int {
return rand40%10 + 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0474.Ones-and-Zeroes.md b/website/content/ChapterFour/0474.Ones-and-Zeroes.md
index 65e29392..dddce982 100755
--- a/website/content/ChapterFour/0474.Ones-and-Zeroes.md
+++ b/website/content/ChapterFour/0474.Ones-and-Zeroes.md
@@ -75,4 +75,11 @@ func findMaxForm(strs []string, m int, n int) int {
return dp[m][n]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0475.Heaters.md b/website/content/ChapterFour/0475.Heaters.md
index bbe46ca7..8beba569 100755
--- a/website/content/ChapterFour/0475.Heaters.md
+++ b/website/content/ChapterFour/0475.Heaters.md
@@ -119,4 +119,11 @@ func findRadius1(houses []int, heaters []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0476.Number-Complement.md b/website/content/ChapterFour/0476.Number-Complement.md
index 1bc61a9e..cd3ca3b0 100755
--- a/website/content/ChapterFour/0476.Number-Complement.md
+++ b/website/content/ChapterFour/0476.Number-Complement.md
@@ -65,4 +65,11 @@ func findComplement1(num int) int {
return (temp - 1) ^ num // temp - 1 即是前面都是 0,num 长度的末尾都是 1 的数,再异或 num 即是最终结果
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0477.Total-Hamming-Distance.md b/website/content/ChapterFour/0477.Total-Hamming-Distance.md
index f3e64a05..12970083 100755
--- a/website/content/ChapterFour/0477.Total-Hamming-Distance.md
+++ b/website/content/ChapterFour/0477.Total-Hamming-Distance.md
@@ -63,4 +63,11 @@ func totalHammingDistance1(nums []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0480.Sliding-Window-Median.md b/website/content/ChapterFour/0480.Sliding-Window-Median.md
index 23499f93..105da2eb 100755
--- a/website/content/ChapterFour/0480.Sliding-Window-Median.md
+++ b/website/content/ChapterFour/0480.Sliding-Window-Median.md
@@ -273,4 +273,11 @@ func (h *MaxHeapR) Push(x int) { heap.Push(&h.hp, x) }
// Remove define
func (h *MaxHeapR) Remove(x int) { heap.Push(&h.hpDel, x) }
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0483.Smallest-Good-Base.md b/website/content/ChapterFour/0483.Smallest-Good-Base.md
index 117d95c4..6ab60aef 100755
--- a/website/content/ChapterFour/0483.Smallest-Good-Base.md
+++ b/website/content/ChapterFour/0483.Smallest-Good-Base.md
@@ -51,46 +51,47 @@ Now given a string representing n, you should return the smallest good base of n
- 给出一个数 n,要求找一个进制 k,使得数字 n 在 k 进制下每一位都是 1 。求最小的进制 k。
- 这一题等价于求最小的正整数 k,满足存在一个正整数 m 使得
-
-
-
+{{< katex display >}}
+ \sum_{i=0}^{m} k^{i} = \frac{1-k^{m+1}}{1-k} = n
+{{< /katex >}}
- 这一题需要确定 k 和 m 两个数的值。m 和 k 是有关系的,确定了一个值,另外一个值也确定了。由
-
-
-
+{{< katex display >}}
+ \frac{1-k^{m+1}}{1-k} = n \\
+{{< /katex >}}
可得:
-
-
-
+{{< katex display >}}
+ m = log_{k}(kn-n+1) - 1 < log_{k}(kn) = 1 + log_{k}n
+{{< /katex >}}
根据题意,可以知道 k ≥2,m ≥1 ,所以有:
-
-
-
+{{< katex display >}}
+ 1 \leqslant m \leqslant log_{2}n
+{{< /katex >}}
所以 m 的取值范围确定了。那么外层循环从 1 到 log n 遍历。找到一个最小的 k ,能满足:
可以用二分搜索来逼近找到最小的 k。先找到 k 的取值范围。由
-
-
-
+{{< katex display >}}
+ \frac{1-k^{m+1}}{1-k} = n \\
+{{< /katex >}}
可得,
-
-
-
+{{< katex display >}}
+ k^{m+1} = nk-n+1 < nk\\ \Rightarrow k < \sqrt[m]{n}
+{{< /katex >}}
+
所以 k 的取值范围是 [2, n*(1/m) ]。再利用二分搜索逼近找到最小的 k 即为答案。
@@ -135,4 +136,11 @@ func findBase(mid, bit uint64) uint64 {
return sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0485.Max-Consecutive-Ones.md b/website/content/ChapterFour/0485.Max-Consecutive-Ones.md
index 6bd2c40e..02f757ef 100644
--- a/website/content/ChapterFour/0485.Max-Consecutive-Ones.md
+++ b/website/content/ChapterFour/0485.Max-Consecutive-Ones.md
@@ -56,4 +56,11 @@ func findMaxConsecutiveOnes(nums []int) int {
return maxCount
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0491.Increasing-Subsequences.md b/website/content/ChapterFour/0491.Increasing-Subsequences.md
index 9a262bb7..b7a1b4a7 100755
--- a/website/content/ChapterFour/0491.Increasing-Subsequences.md
+++ b/website/content/ChapterFour/0491.Increasing-Subsequences.md
@@ -81,4 +81,11 @@ func generateIncSubsets(nums []int, current int, c []int, res *[][]int) {
return
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0493.Reverse-Pairs.md b/website/content/ChapterFour/0493.Reverse-Pairs.md
index 6335db07..82bcc36b 100755
--- a/website/content/ChapterFour/0493.Reverse-Pairs.md
+++ b/website/content/ChapterFour/0493.Reverse-Pairs.md
@@ -7,12 +7,12 @@ Given an array `nums`, we call `(i, j)` an **important reverse pair** if `
You need to return the number of important reverse pairs in the given array.
-**Example1:**
+**Example1**:
Input: [1,3,2,3,1]
Output: 2
-**Example2:**
+**Example2**:
Input: [2,4,3,5,1]
Output: 3
@@ -123,4 +123,11 @@ func mergesortCount(nums, buf []int) int {
return cnt
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0494.Target-Sum.md b/website/content/ChapterFour/0494.Target-Sum.md
index dd3c2b10..16b49336 100644
--- a/website/content/ChapterFour/0494.Target-Sum.md
+++ b/website/content/ChapterFour/0494.Target-Sum.md
@@ -105,4 +105,11 @@ func dfsFindTargetSumWays(nums []int, index int, curSum int, S int, res *int, su
dfsFindTargetSumWays(nums, index+1, curSum-nums[index], S, res, sums)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0496.Next-Greater-Element-I.md b/website/content/ChapterFour/0496.Next-Greater-Element-I.md
index 2a62ef32..8d60eb23 100644
--- a/website/content/ChapterFour/0496.Next-Greater-Element-I.md
+++ b/website/content/ChapterFour/0496.Next-Greater-Element-I.md
@@ -77,4 +77,11 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md b/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md
index 3c68e053..6819448c 100755
--- a/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md
+++ b/website/content/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md
@@ -31,7 +31,7 @@ Given a list of **non-overlapping** axis-aligned rectangles `rects`, write a
Output:
[null,[-1,-2],[2,0],[-2,-1],[3,0],[-2,-2]]
-**Explanation of Input Syntax:**
+**Explanation of Input Syntax**:
The input is two lists: the subroutines called and their arguments. `Solution`'s constructor has one argument, the array of rectangles `rects`. `pick` has no arguments. Arguments are always wrapped with a list, even if there aren't any.
@@ -131,4 +131,11 @@ func (so *Solution497) Pick() []int {
* param_1 := obj.Pick();
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0498.Diagonal-Traverse.md b/website/content/ChapterFour/0498.Diagonal-Traverse.md
index f28348a6..b6d0739c 100755
--- a/website/content/ChapterFour/0498.Diagonal-Traverse.md
+++ b/website/content/ChapterFour/0498.Diagonal-Traverse.md
@@ -181,4 +181,11 @@ func addTraverse(matrix [][]int, i, j int, res *[]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0500.Keyboard-Row.md b/website/content/ChapterFour/0500.Keyboard-Row.md
index 6d6eda08..168b9370 100755
--- a/website/content/ChapterFour/0500.Keyboard-Row.md
+++ b/website/content/ChapterFour/0500.Keyboard-Row.md
@@ -59,4 +59,11 @@ func findWords500(words []string) []string {
return output
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0503.Next-Greater-Element-II.md b/website/content/ChapterFour/0503.Next-Greater-Element-II.md
index a8d5f46c..e9ff3ace 100644
--- a/website/content/ChapterFour/0503.Next-Greater-Element-II.md
+++ b/website/content/ChapterFour/0503.Next-Greater-Element-II.md
@@ -75,4 +75,11 @@ func nextGreaterElements1(nums []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0507.Perfect-Number.md b/website/content/ChapterFour/0507.Perfect-Number.md
index 12d0c764..3092928a 100644
--- a/website/content/ChapterFour/0507.Perfect-Number.md
+++ b/website/content/ChapterFour/0507.Perfect-Number.md
@@ -61,4 +61,11 @@ func checkPerfectNumber_(num int) bool {
return num == 6 || num == 28 || num == 496 || num == 8128 || num == 33550336
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md b/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md
index 91c2a9a6..0b78939a 100755
--- a/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md
+++ b/website/content/ChapterFour/0508.Most-Frequent-Subtree-Sum.md
@@ -120,4 +120,11 @@ func findTreeSum(root *TreeNode, fre map[int]int) int {
return val
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0509.Fibonacci-Number.md b/website/content/ChapterFour/0509.Fibonacci-Number.md
index ee304607..baf08390 100755
--- a/website/content/ChapterFour/0509.Fibonacci-Number.md
+++ b/website/content/ChapterFour/0509.Fibonacci-Number.md
@@ -168,4 +168,11 @@ func fib5(N int) int {
return int(math.Round(math.Pow(goldenRatio, float64(N)) / math.Sqrt(5)))
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md b/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md
index c4f7f083..4c6683c4 100755
--- a/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md
+++ b/website/content/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md
@@ -109,4 +109,11 @@ func findBottomLeftValue1(root *TreeNode) int {
return 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md b/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md
index 7cf9f303..cb60a179 100755
--- a/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md
+++ b/website/content/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md
@@ -90,4 +90,11 @@ func largestValues1(root *TreeNode) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md b/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md
index d139890a..f9e5044a 100644
--- a/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md
+++ b/website/content/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md
@@ -73,4 +73,11 @@ func findLongestWord(s string, d []string) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0526.Beautiful-Arrangement.md b/website/content/ChapterFour/0526.Beautiful-Arrangement.md
index f9f005cd..5dee55d6 100755
--- a/website/content/ChapterFour/0526.Beautiful-Arrangement.md
+++ b/website/content/ChapterFour/0526.Beautiful-Arrangement.md
@@ -107,4 +107,11 @@ func checkDivisible(num, d int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0528.Random-Pick-with-Weight.md b/website/content/ChapterFour/0528.Random-Pick-with-Weight.md
index 9e5d6397..ce18b24e 100755
--- a/website/content/ChapterFour/0528.Random-Pick-with-Weight.md
+++ b/website/content/ChapterFour/0528.Random-Pick-with-Weight.md
@@ -25,7 +25,7 @@ Given an array `w` of positive integers, where `w[i]` describes the weight o
[[[1,3]],[],[],[],[],[]]
Output: [null,0,1,1,1,0]
-**Explanation of Input Syntax:**
+**Explanation of Input Syntax**:
The input is two lists: the subroutines called and their arguments. `Solution`'s constructor has one argument, the array `w`. `pickIndex` has no arguments. Arguments are always wrapped with a list, even if there aren't any.
@@ -105,4 +105,11 @@ func (so *Solution528) PickIndex() int {
* param_1 := obj.PickIndex();
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0529.Minesweeper.md b/website/content/ChapterFour/0529.Minesweeper.md
index f2166a69..d1b7ed79 100644
--- a/website/content/ChapterFour/0529.Minesweeper.md
+++ b/website/content/ChapterFour/0529.Minesweeper.md
@@ -142,4 +142,11 @@ func mineSweeper(x, y int, board [][]byte, mineMap [][]int, dir8 [][]int) {
}
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md b/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md
index 20aa2889..ff546c26 100644
--- a/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md
+++ b/website/content/ChapterFour/0532.K-diff-Pairs-in-an-Array.md
@@ -92,4 +92,11 @@ func findPairs(nums []int, k int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0537.Complex-Number-Multiplication.md b/website/content/ChapterFour/0537.Complex-Number-Multiplication.md
index 568404ba..6f0c11bb 100644
--- a/website/content/ChapterFour/0537.Complex-Number-Multiplication.md
+++ b/website/content/ChapterFour/0537.Complex-Number-Multiplication.md
@@ -70,4 +70,11 @@ func parse(s string) (int, int) {
return r, i
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0541.Reverse-String-II.md b/website/content/ChapterFour/0541.Reverse-String-II.md
index 8d9ebdaf..6c2c50c9 100755
--- a/website/content/ChapterFour/0541.Reverse-String-II.md
+++ b/website/content/ChapterFour/0541.Reverse-String-II.md
@@ -10,7 +10,7 @@ Given a string and an integer k, you need to reverse the first k characters for
Input: s = "abcdefg", k = 2
Output: "bacdfeg"
-**Restrictions:**
+**Restrictions**:
1. The string consists of lower English letters only.
2. Length of the given string and k will in the range [1, 10000]
@@ -53,4 +53,11 @@ func reverseStr(s string, k int) string {
return s
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0542.01-Matrix.md b/website/content/ChapterFour/0542.01-Matrix.md
index deb16e4c..5dc0b0b3 100755
--- a/website/content/ChapterFour/0542.01-Matrix.md
+++ b/website/content/ChapterFour/0542.01-Matrix.md
@@ -199,4 +199,11 @@ func updateMatrixDP(matrix [][]int) [][]int {
return matrix
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0547.Friend-Circles.md b/website/content/ChapterFour/0547.Number-of-Provinces.md
similarity index 88%
rename from website/content/ChapterFour/0547.Friend-Circles.md
rename to website/content/ChapterFour/0547.Number-of-Provinces.md
index a5597297..727eaa16 100755
--- a/website/content/ChapterFour/0547.Friend-Circles.md
+++ b/website/content/ChapterFour/0547.Number-of-Provinces.md
@@ -1,4 +1,4 @@
-# [547. Friend Circles](https://leetcode.com/problems/friend-circles/)
+# [547. Number of Provinces](https://leetcode.com/problems/number-of-provinces/)
## 题目
@@ -108,4 +108,11 @@ func dfs547(M [][]int, cur int, visited []bool) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md b/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md
index 68363ed8..91251032 100755
--- a/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md
+++ b/website/content/ChapterFour/0557.Reverse-Words-in-a-String-III.md
@@ -54,4 +54,11 @@ func revers(s string) string {
return string(bytes)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0561.Array-Partition-I.md b/website/content/ChapterFour/0561.Array-Partition-I.md
index d72ea633..0b146a5a 100644
--- a/website/content/ChapterFour/0561.Array-Partition-I.md
+++ b/website/content/ChapterFour/0561.Array-Partition-I.md
@@ -55,4 +55,11 @@ func arrayPairSum(nums []int) int {
return sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0563.Binary-Tree-Tilt.md b/website/content/ChapterFour/0563.Binary-Tree-Tilt.md
index b5a8ce5c..23bdf2ab 100755
--- a/website/content/ChapterFour/0563.Binary-Tree-Tilt.md
+++ b/website/content/ChapterFour/0563.Binary-Tree-Tilt.md
@@ -80,4 +80,11 @@ func findTiltDFS(root *TreeNode, sum *int) int {
return root.Val + left + right
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0566.Reshape-the-Matrix.md b/website/content/ChapterFour/0566.Reshape-the-Matrix.md
index a55a7028..694ab4b7 100755
--- a/website/content/ChapterFour/0566.Reshape-the-Matrix.md
+++ b/website/content/ChapterFour/0566.Reshape-the-Matrix.md
@@ -99,4 +99,11 @@ func reshape(nums [][]int, r, c int) [][]int {
return newShape
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0567.Permutation-in-String.md b/website/content/ChapterFour/0567.Permutation-in-String.md
index e2e9d17a..a17623c4 100644
--- a/website/content/ChapterFour/0567.Permutation-in-String.md
+++ b/website/content/ChapterFour/0567.Permutation-in-String.md
@@ -84,4 +84,11 @@ func checkInclusion(s1 string, s2 string) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md b/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md
index 21611c12..38df9747 100755
--- a/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md
+++ b/website/content/ChapterFour/0572.Subtree-of-Another-Tree.md
@@ -84,4 +84,11 @@ func isSubtree(s *TreeNode, t *TreeNode) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0575.Distribute-Candies.md b/website/content/ChapterFour/0575.Distribute-Candies.md
index 4e329936..98421846 100755
--- a/website/content/ChapterFour/0575.Distribute-Candies.md
+++ b/website/content/ChapterFour/0575.Distribute-Candies.md
@@ -56,4 +56,11 @@ func distributeCandies(candies []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md b/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md
index 380ad65a..e580f1b8 100755
--- a/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md
+++ b/website/content/ChapterFour/0594.Longest-Harmonious-Subsequence.md
@@ -54,4 +54,11 @@ func findLHS(nums []int) int {
return longest
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0598.Range-Addition-II.md b/website/content/ChapterFour/0598.Range-Addition-II.md
index a4606f95..2629104d 100644
--- a/website/content/ChapterFour/0598.Range-Addition-II.md
+++ b/website/content/ChapterFour/0598.Range-Addition-II.md
@@ -79,4 +79,11 @@ func min(a, b int) int {
return b
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md b/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md
index 01cc155e..98bedc57 100755
--- a/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md
+++ b/website/content/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md
@@ -74,4 +74,11 @@ func findRestaurant(list1 []string, list2 []string) []string {
return ans
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0605.Can-Place-Flowers.md b/website/content/ChapterFour/0605.Can-Place-Flowers.md
new file mode 100644
index 00000000..c873052e
--- /dev/null
+++ b/website/content/ChapterFour/0605.Can-Place-Flowers.md
@@ -0,0 +1,67 @@
+# [605. Can Place Flowers](https://leetcode.com/problems/can-place-flowers/)
+
+## 题目
+
+You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in **adjacent** plots.
+
+Given an integer array `flowerbed` containing `0`'s and `1`'s, where `0` means empty and `1` means not empty, and an integer `n`, return *if* `n` new flowers can be planted in the `flowerbed` without violating the no-adjacent-flowers rule.
+
+**Example 1**:
+
+```
+Input: flowerbed = [1,0,0,0,1], n = 1
+Output: true
+```
+
+**Example 2**:
+
+```
+Input: flowerbed = [1,0,0,0,1], n = 2
+Output: false
+```
+
+**Constraints**:
+
+- `1 <= flowerbed.length <= 2 * 104`
+- `flowerbed[i]` is `0` or `1`.
+- There are no two adjacent flowers in `flowerbed`.
+- `0 <= n <= flowerbed.length`
+
+## 题目大意
+
+假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有。可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去。给定一个花坛(表示为一个数组包含0和1,其中0表示没种植花,1表示种植了花),和一个数 n 。能否在不打破种植规则的情况下种入 n 朵花?能则返回True,不能则返回False。
+
+## 解题思路
+
+- 这一题最容易想到的解法是步长为 2 遍历数组,依次计数 0 的个数。有 2 种特殊情况需要单独判断,第一种情况是首尾连续多个 0,例如,00001 和 10000,第二种情况是 2 个 1 中间存在的 0 不足以种花,例如,1001 和 100001,1001 不能种任何花,100001 只能种一种花。单独判断出这 2 种情况,这一题就可以 AC 了。
+- 换个思路,找到可以种花的基本单元是 00,那么上面那 2 种特殊情况都可以统一成一种情况。判断是否当前存在 00 的组合,如果存在 00 的组合,都可以种花。末尾的情况需要单独判断,如果末尾为 0,也可以种花。这个时候不需要再找 00 组合,因为会越界。代码实现如下,思路很简洁明了。
+
+## 代码
+
+```go
+package leetcode
+
+func canPlaceFlowers(flowerbed []int, n int) bool {
+ lenth := len(flowerbed)
+ for i := 0; i < lenth && n > 0; i += 2 {
+ if flowerbed[i] == 0 {
+ if i+1 == lenth || flowerbed[i+1] == 0 {
+ n--
+ } else {
+ i++
+ }
+ }
+ }
+ if n == 0 {
+ return true
+ }
+ return false
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md b/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md
index c51411ad..890a736d 100755
--- a/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md
+++ b/website/content/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md
@@ -93,4 +93,11 @@ func maximumProduct1(nums []int) int {
return n1 * n4 * n5
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md b/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md
index b1187be9..9b77ea7e 100755
--- a/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md
+++ b/website/content/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md
@@ -110,4 +110,11 @@ func (p SortByVal) Less(i, j int) bool {
return p.elements[i].val < p.elements[j].val
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md b/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md
index 4af1d2a4..5db9b22e 100755
--- a/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md
+++ b/website/content/ChapterFour/0633.Sum-of-Square-Numbers.md
@@ -25,7 +25,7 @@ Given a non-negative integer `c`, your task is to decide whether there're two i
## 解题思路
- 给出一个数,要求判断这个数能否由由 2 个完全平方数组成。能则输出 true,不能则输出 false。
-- 可以用二分搜索来解答这道题。判断题意,依次计算 `low * low + high * high` 和 c 是否相等。从 [1, sqrt(n)] 区间内进行二分,若能找到则返回 true,找不到就返回 false 。
+- 可以用二分搜索来解答这道题。判断题意,依次计算 `low * low + high * high` 和 c 是否相等。从 [0, sqrt(n)] 区间内进行二分,若能找到则返回 true,找不到就返回 false 。
## 代码
@@ -50,4 +50,11 @@ func judgeSquareSum(c int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md b/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md
index 71458a89..49ebc64a 100755
--- a/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md
+++ b/website/content/ChapterFour/0636.Exclusive-Time-of-Functions.md
@@ -97,4 +97,11 @@ func exclusiveTime(n int, logs []string) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md b/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md
index 34b0c41a..494e17b3 100644
--- a/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md
+++ b/website/content/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md
@@ -82,4 +82,11 @@ func averageOfLevels(root *TreeNode) []float64 {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0638.Shopping-Offers.md b/website/content/ChapterFour/0638.Shopping-Offers.md
index cf389acb..e139c7b8 100644
--- a/website/content/ChapterFour/0638.Shopping-Offers.md
+++ b/website/content/ChapterFour/0638.Shopping-Offers.md
@@ -126,4 +126,11 @@ func dfsShoppingOffers(price []int, special [][]int, needs []int, pay int, res *
dfsShoppingOffers(price, special[1:], newNeeds, pay+special[0][len(price)], res)
dfsShoppingOffers(price, special[1:], needs, pay, res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0645.Set-Mismatch.md b/website/content/ChapterFour/0645.Set-Mismatch.md
index 9236fd4c..389004d7 100755
--- a/website/content/ChapterFour/0645.Set-Mismatch.md
+++ b/website/content/ChapterFour/0645.Set-Mismatch.md
@@ -59,4 +59,11 @@ func findErrorNums(nums []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0648.Replace-Words.md b/website/content/ChapterFour/0648.Replace-Words.md
index 17614c9c..d47adb84 100755
--- a/website/content/ChapterFour/0648.Replace-Words.md
+++ b/website/content/ChapterFour/0648.Replace-Words.md
@@ -108,4 +108,11 @@ func replaceWords1(dict []string, sentence string) string {
return strings.Join(result, " ")
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md b/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md
index e203db03..bf1681f0 100755
--- a/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md
+++ b/website/content/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md
@@ -72,4 +72,11 @@ func findTargetDFS(root *TreeNode, k int, m map[int]int) bool {
return findTargetDFS(root.Left, k, m) || findTargetDFS(root.Right, k, m)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0658.Find-K-Closest-Elements.md b/website/content/ChapterFour/0658.Find-K-Closest-Elements.md
index b55ced18..cc6ea000 100755
--- a/website/content/ChapterFour/0658.Find-K-Closest-Elements.md
+++ b/website/content/ChapterFour/0658.Find-K-Closest-Elements.md
@@ -79,4 +79,11 @@ func findClosestElements1(arr []int, k int, x int) []int {
return arr[low : low+k]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0661.Image-Smoother.md b/website/content/ChapterFour/0661.Image-Smoother.md
index 03fde6bf..898ac924 100644
--- a/website/content/ChapterFour/0661.Image-Smoother.md
+++ b/website/content/ChapterFour/0661.Image-Smoother.md
@@ -108,4 +108,11 @@ func smooth(x, y int, M [][]int) int {
return sum / count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md b/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md
index d60af025..00a6fb10 100755
--- a/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md
+++ b/website/content/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md
@@ -149,4 +149,11 @@ func widthOfBinaryTree(root *TreeNode) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md b/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md
index 491973cb..6c2d2620 100755
--- a/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md
+++ b/website/content/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md
@@ -81,4 +81,11 @@ func counterKthNum(m, n, mid int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md b/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md
index 4ce7d05c..8633d427 100755
--- a/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md
+++ b/website/content/ChapterFour/0676.Implement-Magic-Dictionary.md
@@ -84,4 +84,11 @@ func (this *MagicDictionary) Search(word string) bool {
* param_2 := obj.Search(word);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0682.Baseball-Game.md b/website/content/ChapterFour/0682.Baseball-Game.md
index 6f76fd35..447934fb 100644
--- a/website/content/ChapterFour/0682.Baseball-Game.md
+++ b/website/content/ChapterFour/0682.Baseball-Game.md
@@ -103,4 +103,11 @@ func calPoints(ops []string) int {
return points
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0684.Redundant-Connection.md b/website/content/ChapterFour/0684.Redundant-Connection.md
index 527d61be..5348b2b9 100755
--- a/website/content/ChapterFour/0684.Redundant-Connection.md
+++ b/website/content/ChapterFour/0684.Redundant-Connection.md
@@ -82,4 +82,11 @@ func findRedundantConnection(edges [][]int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0685.Redundant-Connection-II.md b/website/content/ChapterFour/0685.Redundant-Connection-II.md
index d6436f4b..f96a97c7 100755
--- a/website/content/ChapterFour/0685.Redundant-Connection-II.md
+++ b/website/content/ChapterFour/0685.Redundant-Connection-II.md
@@ -107,4 +107,11 @@ func findRoot(parent *[]int, k int) int {
return (*parent)[k]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md b/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md
index 290e2cda..0a75d45c 100755
--- a/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md
+++ b/website/content/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md
@@ -77,4 +77,11 @@ func hasAlternatingBits1(n int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0695.Max-Area-of-Island.md b/website/content/ChapterFour/0695.Max-Area-of-Island.md
index 2419d561..6d5ee78a 100644
--- a/website/content/ChapterFour/0695.Max-Area-of-Island.md
+++ b/website/content/ChapterFour/0695.Max-Area-of-Island.md
@@ -74,4 +74,11 @@ func areaOfIsland(grid [][]int, x, y int) int {
}
return total
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0697.Degree-of-an-Array.md b/website/content/ChapterFour/0697.Degree-of-an-Array.md
index ab032f5c..25cf311a 100644
--- a/website/content/ChapterFour/0697.Degree-of-an-Array.md
+++ b/website/content/ChapterFour/0697.Degree-of-an-Array.md
@@ -77,4 +77,11 @@ func findShortestSubArray(nums []int) int {
return smallest
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0699.Falling-Squares.md b/website/content/ChapterFour/0699.Falling-Squares.md
index a3228a87..7986f80e 100755
--- a/website/content/ChapterFour/0699.Falling-Squares.md
+++ b/website/content/ChapterFour/0699.Falling-Squares.md
@@ -142,4 +142,11 @@ func discretization(positions [][]int) map[int]int {
return posMap
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0704.Binary-Search.md b/website/content/ChapterFour/0704.Binary-Search.md
index b10293d9..ea9b82b3 100755
--- a/website/content/ChapterFour/0704.Binary-Search.md
+++ b/website/content/ChapterFour/0704.Binary-Search.md
@@ -64,4 +64,11 @@ func search704(nums []int, target int) int {
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0705.Design-HashSet.md b/website/content/ChapterFour/0705.Design-HashSet.md
index d4d241f7..da4d3578 100755
--- a/website/content/ChapterFour/0705.Design-HashSet.md
+++ b/website/content/ChapterFour/0705.Design-HashSet.md
@@ -91,4 +91,11 @@ func (this *MyHashSet) Contains(key int) bool {
* param_3 := obj.Contains(key);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0706.Design-HashMap.md b/website/content/ChapterFour/0706.Design-HashMap.md
index 80146098..786c2cab 100755
--- a/website/content/ChapterFour/0706.Design-HashMap.md
+++ b/website/content/ChapterFour/0706.Design-HashMap.md
@@ -148,4 +148,11 @@ func (this *MyHashMap) Hash(value int) int {
* obj.Remove(key);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0707.Design-Linked-List.md b/website/content/ChapterFour/0707.Design-Linked-List.md
index c014e9e6..6930dd2f 100644
--- a/website/content/ChapterFour/0707.Design-Linked-List.md
+++ b/website/content/ChapterFour/0707.Design-Linked-List.md
@@ -137,4 +137,11 @@ func (this *MyLinkedList) DeleteAtIndex(index int) {
* obj.DeleteAtIndex(index);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md b/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md
index d796e1e7..8622e8ed 100644
--- a/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md
+++ b/website/content/ChapterFour/0710.Random-Pick-with-Blacklist.md
@@ -142,4 +142,11 @@ func (this *Solution) Pick() int {
* param_1 := obj.Pick();
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md b/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md
index f5afc7d1..47182853 100644
--- a/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md
+++ b/website/content/ChapterFour/0713.Subarray-Product-Less-Than-K.md
@@ -62,4 +62,11 @@ func numSubarrayProductLessThanK(nums []int, k int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md b/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md
index 7bf23833..9a4f62fb 100755
--- a/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md
+++ b/website/content/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md
@@ -77,4 +77,11 @@ func maxProfit714_1(prices []int, fee int) int {
return sell
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0715.Range-Module.md b/website/content/ChapterFour/0715.Range-Module.md
index acd40364..80b3a39b 100755
--- a/website/content/ChapterFour/0715.Range-Module.md
+++ b/website/content/ChapterFour/0715.Range-Module.md
@@ -267,4 +267,11 @@ func query(node *SegmentTreeNode, start, end int) bool {
* obj.RemoveRange(left,right);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md b/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md
index 49988924..82de8dfc 100755
--- a/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md
+++ b/website/content/ChapterFour/0717.1-bit-and-2-bit-Characters.md
@@ -62,4 +62,11 @@ func isOneBitCharacter(bits []int) bool {
return i == len(bits)-1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md b/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md
index eec248fe..211ef777 100755
--- a/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md
+++ b/website/content/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md
@@ -120,4 +120,11 @@ func findLength1(A []int, B []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md b/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md
index 836b8922..d529b244 100755
--- a/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md
+++ b/website/content/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md
@@ -94,4 +94,11 @@ func findDistanceCount1(nums []int, num int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md b/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md
index 8a70177f..27b9c7a1 100755
--- a/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md
+++ b/website/content/ChapterFour/0720.Longest-Word-in-Dictionary.md
@@ -69,4 +69,11 @@ func longestWord(words []string) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0721.Accounts-Merge.md b/website/content/ChapterFour/0721.Accounts-Merge.md
index 352343d9..42c63ba1 100755
--- a/website/content/ChapterFour/0721.Accounts-Merge.md
+++ b/website/content/ChapterFour/0721.Accounts-Merge.md
@@ -146,4 +146,11 @@ func accountsMerge1(accounts [][]string) [][]string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0724.Find-Pivot-Index.md b/website/content/ChapterFour/0724.Find-Pivot-Index.md
index 1e93cf47..5360bf54 100644
--- a/website/content/ChapterFour/0724.Find-Pivot-Index.md
+++ b/website/content/ChapterFour/0724.Find-Pivot-Index.md
@@ -72,3 +72,10 @@ func pivotIndex(nums []int) int {
}
```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0725.Split-Linked-List-in-Parts.md b/website/content/ChapterFour/0725.Split-Linked-List-in-Parts.md
index 6c7fdf87..7bc0e10e 100644
--- a/website/content/ChapterFour/0725.Split-Linked-List-in-Parts.md
+++ b/website/content/ChapterFour/0725.Split-Linked-List-in-Parts.md
@@ -139,4 +139,11 @@ func getLength(l *ListNode) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0726.Number-of-Atoms.md b/website/content/ChapterFour/0726.Number-of-Atoms.md
index a9d3cf4a..a885505c 100755
--- a/website/content/ChapterFour/0726.Number-of-Atoms.md
+++ b/website/content/ChapterFour/0726.Number-of-Atoms.md
@@ -183,4 +183,11 @@ func isLowerLetter(v byte) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0729.My-Calendar-I.md b/website/content/ChapterFour/0729.My-Calendar-I.md
index bc957aba..15bb691d 100755
--- a/website/content/ChapterFour/0729.My-Calendar-I.md
+++ b/website/content/ChapterFour/0729.My-Calendar-I.md
@@ -177,4 +177,11 @@ func (this *MyCalendar) Book(start int, end int) bool {
* param_1 := obj.Book(start,end);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0732.My-Calendar-III.md b/website/content/ChapterFour/0732.My-Calendar-III.md
index 5b953911..16114138 100755
--- a/website/content/ChapterFour/0732.My-Calendar-III.md
+++ b/website/content/ChapterFour/0732.My-Calendar-III.md
@@ -139,4 +139,11 @@ func (st *SegmentTree732) book(start, end int, maxHeight *int) {
* param_1 := obj.Book(start,end);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0733.Flood-Fill.md b/website/content/ChapterFour/0733.Flood-Fill.md
index 8fd2bba3..b66a77a7 100755
--- a/website/content/ChapterFour/0733.Flood-Fill.md
+++ b/website/content/ChapterFour/0733.Flood-Fill.md
@@ -78,4 +78,11 @@ func dfs733(image [][]int, x, y int, newColor int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0735.Asteroid-Collision.md b/website/content/ChapterFour/0735.Asteroid-Collision.md
index 2db71447..a9933fdb 100644
--- a/website/content/ChapterFour/0735.Asteroid-Collision.md
+++ b/website/content/ChapterFour/0735.Asteroid-Collision.md
@@ -102,4 +102,11 @@ func asteroidCollision(asteroids []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0739.Daily-Temperatures.md b/website/content/ChapterFour/0739.Daily-Temperatures.md
index 9fef4be8..514474e8 100644
--- a/website/content/ChapterFour/0739.Daily-Temperatures.md
+++ b/website/content/ChapterFour/0739.Daily-Temperatures.md
@@ -56,4 +56,11 @@ func dailyTemperatures1(T []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md b/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md
index fc6e6208..da03eb56 100755
--- a/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md
+++ b/website/content/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md
@@ -89,4 +89,11 @@ func nextGreatestLetter(letters []byte, target byte) byte {
return find
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md b/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md
index 705aa217..fef5fe50 100755
--- a/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md
+++ b/website/content/ChapterFour/0745.Prefix-and-Suffix-Search.md
@@ -95,4 +95,11 @@ func (this *WordFilter_) F_(prefix string, suffix string) int {
* param_1 := obj.F(prefix,suffix);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md b/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md
index 2abd334b..b7616f0b 100755
--- a/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md
+++ b/website/content/ChapterFour/0746.Min-Cost-Climbing-Stairs.md
@@ -68,4 +68,11 @@ func minCostClimbingStairs1(cost []int) int {
return last
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0748.Shortest-Completing-Word.md b/website/content/ChapterFour/0748.Shortest-Completing-Word.md
index ec0267e3..8f2cb3a5 100755
--- a/website/content/ChapterFour/0748.Shortest-Completing-Word.md
+++ b/website/content/ChapterFour/0748.Shortest-Completing-Word.md
@@ -99,4 +99,11 @@ func match(lp [26]int, w string) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0753.Cracking-the-Safe.md b/website/content/ChapterFour/0753.Cracking-the-Safe.md
index 39c79a48..63567a9f 100644
--- a/website/content/ChapterFour/0753.Cracking-the-Safe.md
+++ b/website/content/ChapterFour/0753.Cracking-the-Safe.md
@@ -89,4 +89,11 @@ func dfsCrackSafe(depth, n, k int, str *[]byte, visit *map[string]bool) bool {
}
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md b/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md
index 1b158131..b3042ed5 100755
--- a/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md
+++ b/website/content/ChapterFour/0756.Pyramid-Transition-Matrix.md
@@ -89,4 +89,11 @@ func dfsT(bottom, above string, pyramid map[string][]string) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md b/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md
index 8c01e90f..fcfb1d5c 100755
--- a/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md
+++ b/website/content/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md
@@ -75,4 +75,11 @@ func isPrime(x int) bool {
return x == 2 || x == 3 || x == 5 || x == 7 || x == 11 || x == 13 || x == 17 || x == 19
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0763.Partition-Labels.md b/website/content/ChapterFour/0763.Partition-Labels.md
index 76bf1b3f..e5273f5e 100644
--- a/website/content/ChapterFour/0763.Partition-Labels.md
+++ b/website/content/ChapterFour/0763.Partition-Labels.md
@@ -89,4 +89,11 @@ func partitionLabels1(S string) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0765.Couples-Holding-Hands.md b/website/content/ChapterFour/0765.Couples-Holding-Hands.md
index 035512fe..65a08a69 100755
--- a/website/content/ChapterFour/0765.Couples-Holding-Hands.md
+++ b/website/content/ChapterFour/0765.Couples-Holding-Hands.md
@@ -90,4 +90,11 @@ func minSwapsCouples(row []int) int {
return len(row)/2 - uf.TotalCount()
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0766.Toeplitz-Matrix.md b/website/content/ChapterFour/0766.Toeplitz-Matrix.md
index a595e632..e4f7e305 100755
--- a/website/content/ChapterFour/0766.Toeplitz-Matrix.md
+++ b/website/content/ChapterFour/0766.Toeplitz-Matrix.md
@@ -76,4 +76,11 @@ func isToeplitzMatrix(matrix [][]int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0767.Reorganize-String.md b/website/content/ChapterFour/0767.Reorganize-String.md
index 45388be3..60eb52c3 100644
--- a/website/content/ChapterFour/0767.Reorganize-String.md
+++ b/website/content/ChapterFour/0767.Reorganize-String.md
@@ -146,4 +146,11 @@ func frequencySort767(s string) string {
return string(res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0771.Jewels-and-Stones.md b/website/content/ChapterFour/0771.Jewels-and-Stones.md
index e5490bed..e5322860 100755
--- a/website/content/ChapterFour/0771.Jewels-and-Stones.md
+++ b/website/content/ChapterFour/0771.Jewels-and-Stones.md
@@ -71,4 +71,11 @@ func numJewelsInStones1(J string, S string) int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0778.Swim-in-Rising-Water.md b/website/content/ChapterFour/0778.Swim-in-Rising-Water.md
index 7153069f..dbb2414b 100755
--- a/website/content/ChapterFour/0778.Swim-in-Rising-Water.md
+++ b/website/content/ChapterFour/0778.Swim-in-Rising-Water.md
@@ -129,4 +129,11 @@ func swimInWater1(grid [][]int) int {
return res - 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0781.Rabbits-in-Forest.md b/website/content/ChapterFour/0781.Rabbits-in-Forest.md
index 61aa4555..5ec3870d 100755
--- a/website/content/ChapterFour/0781.Rabbits-in-Forest.md
+++ b/website/content/ChapterFour/0781.Rabbits-in-Forest.md
@@ -66,4 +66,11 @@ func numRabbits(ans []int) int {
return total
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0784.Letter-Case-Permutation.md b/website/content/ChapterFour/0784.Letter-Case-Permutation.md
index 323b4e63..18f870a0 100755
--- a/website/content/ChapterFour/0784.Letter-Case-Permutation.md
+++ b/website/content/ChapterFour/0784.Letter-Case-Permutation.md
@@ -117,4 +117,11 @@ func toUpper(s string, i int) string {
return string(b)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0785.Is-Graph-Bipartite.md b/website/content/ChapterFour/0785.Is-Graph-Bipartite.md
new file mode 100644
index 00000000..f595b55e
--- /dev/null
+++ b/website/content/ChapterFour/0785.Is-Graph-Bipartite.md
@@ -0,0 +1,105 @@
+# [785. Is Graph Bipartite?](https://leetcode.com/problems/is-graph-bipartite/)
+
+
+## 题目
+
+Given an undirected `graph`, return `true` if and only if it is bipartite.
+
+Recall that a graph is *bipartite* if we can split it's set of nodes into two independent subsets A and B such that every edge in the graph has one node in A and another node in B.
+
+The graph is given in the following form: `graph[i]` is a list of indexes `j` for which the edge between nodes `i` and `j` exists. Each node is an integer between `0` and `graph.length - 1`. There are no self edges or parallel edges: `graph[i]` does not contain `i`, and it doesn't contain any element twice.
+
+
+ Example 1:Input: [[1,3], [0,2], [1,3], [0,2]]
+ Output: true
+ Explanation:
+ The graph looks like this:
+ 0----1
+ | |
+ | |
+ 3----2
+ We can divide the vertices into two groups: {0, 2} and {1, 3}.
+
+
+ Example 2:Input: [[1,2,3], [0,2], [0,1,3], [0,2]]
+ Output: false
+ Explanation:
+ The graph looks like this:
+ 0----1
+ | \ |
+ | \ |
+ 3----2
+ We cannot find a way to divide the set of nodes into two independent subsets.
+
+
+**Note**:
+
+- `graph` will have length in range `[1, 100]`.
+- `graph[i]` will contain integers in range `[0, graph.length - 1]`.
+- `graph[i]` will not contain `i` or duplicate values.
+- The graph is undirected: if any element `j` is in `graph[i]`, then `i` will be in `graph[j]`.
+
+## 题目大意
+
+给定一个无向图 graph,当这个图为二分图时返回 true。
+
+graph 将会以邻接表方式给出,graph[i] 表示图中与节点i相连的所有节点。每个节点都是一个在 0 到 graph.length-1 之间的整数。这图中没有自环和平行边: graph[i] 中不存在 i,并且 graph[i] 中没有重复的值。
+
+注意:
+
+- graph 的长度范围为 [1, 100]。
+- graph[i] 中的元素的范围为 [0, graph.length - 1]。
+- graph[i] 不会包含 i 或者有重复的值。
+- 图是无向的: 如果 j 在 graph[i] 里边, 那么 i 也会在 graph[j] 里边。
+
+## 解题思路
+
+- 判断一个无向图是否是二分图。二分图的定义:如果我们能将一个图的节点集合分割成两个独立的子集 A 和 B,并使图中的每一条边的两个节点一个来自 A 集合,一个来自 B 集合,我们就将这个图称为二分图。
+- 这一题可以用 BFS、DFS、并查集来解答。这里是 DFS 实现。任选一个节点开始,把它染成红色,然后对整个图 DFS 遍历,把与它相连的节点并且未被染色的,都染成绿色。颜色不同的节点代表不同的集合。这时候还可能遇到第 2 种情况,与它相连的节点已经有颜色了,并且这个颜色和前一个节点的颜色相同,这就说明了该无向图不是二分图。可以直接 return false。如此遍历到所有节点都染色了,如果能染色成功,说明该无向图是二分图,返回 true。
+
+## 代码
+
+```go
+package leetcode
+
+// DFS 染色,1 是红色,0 是绿色,-1 是未染色
+func isBipartite(graph [][]int) bool {
+ colors := make([]int, len(graph))
+ for i := range colors {
+ colors[i] = -1
+ }
+ for i := range graph {
+ if !dfs(i, graph, colors, -1) {
+ return false
+ }
+ }
+ return true
+}
+
+func dfs(n int, graph [][]int, colors []int, parentCol int) bool {
+ if colors[n] == -1 {
+ if parentCol == 1 {
+ colors[n] = 0
+ } else {
+ colors[n] = 1
+ }
+ } else if colors[n] == parentCol {
+ return false
+ } else if colors[n] != parentCol {
+ return true
+ }
+ for _, c := range graph[n] {
+ if !dfs(c, graph, colors, colors[n]) {
+ return false
+ }
+ }
+ return true
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md b/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md
index 9646d5af..17203613 100755
--- a/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md
+++ b/website/content/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md
@@ -116,4 +116,11 @@ func (a SortByFraction) Less(i, j int) bool {
return a[i].molecule*a[j].denominator < a[j].molecule*a[i].denominator
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md b/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md
index b784e046..e931f679 100755
--- a/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md
+++ b/website/content/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md
@@ -41,27 +41,22 @@ f(x) 是 x! 末尾是0的数量。(回想一下 x! = 1 * 2 * 3 * ... * x
- 给出一个数 K,要求有多少个 n 能使得 n!末尾 0 的个数等于 K。
- 这一题是基于第 172 题的逆过程加强版。第 172 题是给出 `n`,求得末尾 0 的个数。由第 172 题可以知道,`n!`末尾 0 的个数取决于因子 5 的个数。末尾可能有 `K` 个 0,那么 `n` 最多可以等于 `5 * K`,在 `[0, 5* K]` 区间内二分搜索,判断 `mid` 末尾 0 的个数,如果能找到 `K`,那么就范围 5,如果找不到这个 `K`,返回 0 。为什么答案取值只有 0 和 5 呢?因为当 `n` 增加 5 以后,因子 5 的个数又加一了,末尾又可以多 1 个或者多个 0(如果加 5 以后,有多个 5 的因子,例如 25,125,就有可能末尾增加多个 0)。所以有效的 `K` 值对应的 `n` 的范围区间就是 5 。反过来,无效的 `K` 值对应的 `n` 是 0。`K` 在 `5^n` 的分界线处会发生跳变,所有有些值取不到。例如,`n` 在 `[0,5)` 内取值,`K = 0`;`n` 在 `[5,10)` 内取值,`K = 1`;`n` 在 `[10,15)` 内取值,`K = 2`;`n` 在 `[15,20)` 内取值,`K = 3`;`n` 在 `[20,25)` 内取值,`K = 4`;`n` 在 `[25,30)` 内取值,`K = 6`,因为 25 提供了 2 个 5,也就提供了 2 个 0,所以 `K` 永远无法取值等于 5,即当 `K = 5` 时,找不到任何的 `n` 与之对应。
- 这一题也可以用数学的方法解题。见解法二。这个解法的灵感来自于:n!末尾 0 的个数等于 [1,n] 所有数的因子 5 的个数总和。其次此题的结果一定只有 0 和 5 (分析见上一种解法)。有了这两个结论以后,就可以用数学的方法推导了。首先 n 可以表示为 5 进制的形式
-
-
-
- 上面式子中,所有有因子 5 的个数为:
-
-
-
-
- 这个总数就即是 K。针对不同的 n,an 的通项公式不同,所以表示的 K 的系数也不同。cn 的通项公式呢?
-
-
-
-
-
-
-
- 由上面这个递推还能推出通项公式(不过这题不适用通项公式,是用递推公式更方便):
-
-
-
- 判断 K 是否能表示成两个数列的表示形式,等价于判断 K 是否能转化为以 Cn 为基的变进制数。到此,转化成类似第 483 题了。代码实现不难,见解法二。
+{{< katex display >}}
+n = 5^{0} * a_{0} + 5^{1} * a_{1} + 5^{2} * a_{2} + ... + 5^{n} * a_{n}, (a_{n} < 5)
+{{< /katex >}}
+ 上面式子中,所有有因子 5 的个数为:
+{{< katex display >}}
+K = \sum_{n=0}^{n} a_{n} * c_{n}
+{{< /katex >}}
+ 这个总数就即是 K。针对不同的 n,an 的通项公式不同,所以表示的 K 的系数也不同。cn 的通项公式呢?
+{{< katex display >}}
+c_{n} = 5 * c_{n-1} + 1,c_{0} = 0
+{{< /katex >}}
+ 由上面这个递推还能推出通项公式(不过这题不适用通项公式,是用递推公式更方便):
+{{< katex display >}}
+c_{n} = \frac{5^{n} - 1 }{4}
+{{< /katex >}}
+ 判断 K 是否能表示成两个数列的表示形式,等价于判断 K 是否能转化为以 Cn 为基的变进制数。到此,转化成类似第 483 题了。代码实现不难,见解法二。
## 代码
@@ -103,4 +98,11 @@ func preimageSizeFZF1(K int) int {
return 5
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md b/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md
index f6879f30..af127111 100644
--- a/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md
+++ b/website/content/ChapterFour/0802.Find-Eventual-Safe-States.md
@@ -70,4 +70,11 @@ func dfsEventualSafeNodes(graph [][]int, idx int, color []int) bool {
color[idx] = 2
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md b/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md
index 6f5335ed..c08b8ab8 100755
--- a/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md
+++ b/website/content/ChapterFour/0803.Bricks-Falling-When-Hit.md
@@ -122,4 +122,11 @@ func getUnionFindFromGrid(grid [][]int, x, y int, uf template.UnionFindCount) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0811.Subdomain-Visit-Count.md b/website/content/ChapterFour/0811.Subdomain-Visit-Count.md
index 69840bd9..d2eda349 100755
--- a/website/content/ChapterFour/0811.Subdomain-Visit-Count.md
+++ b/website/content/ChapterFour/0811.Subdomain-Visit-Count.md
@@ -140,4 +140,11 @@ func splitDomain(domain string, domains map[string]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0812.Largest-Triangle-Area.md b/website/content/ChapterFour/0812.Largest-Triangle-Area.md
index 426826f1..81ea3077 100644
--- a/website/content/ChapterFour/0812.Largest-Triangle-Area.md
+++ b/website/content/ChapterFour/0812.Largest-Triangle-Area.md
@@ -67,4 +67,11 @@ func max(a, b float64) float64 {
return b
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0815.Bus-Routes.md b/website/content/ChapterFour/0815.Bus-Routes.md
index bddbd3b0..18b747b2 100755
--- a/website/content/ChapterFour/0815.Bus-Routes.md
+++ b/website/content/ChapterFour/0815.Bus-Routes.md
@@ -85,4 +85,11 @@ func numBusesToDestination(routes [][]int, S int, T int) int {
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0817.Linked-List-Components.md b/website/content/ChapterFour/0817.Linked-List-Components.md
index a0415371..4b49383b 100644
--- a/website/content/ChapterFour/0817.Linked-List-Components.md
+++ b/website/content/ChapterFour/0817.Linked-List-Components.md
@@ -106,4 +106,11 @@ func toMap(G []int) map[int]int {
return GMap
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0819.Most-Common-Word.md b/website/content/ChapterFour/0819.Most-Common-Word.md
index e37b45ee..307a2044 100755
--- a/website/content/ChapterFour/0819.Most-Common-Word.md
+++ b/website/content/ChapterFour/0819.Most-Common-Word.md
@@ -86,4 +86,11 @@ func mostCommonWord(paragraph string, banned []string) string {
return mostFreqWord
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md b/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md
index 33059b95..4e49558d 100644
--- a/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md
+++ b/website/content/ChapterFour/0826.Most-Profit-Assigning-Work.md
@@ -104,4 +104,11 @@ func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.md b/website/content/ChapterFour/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.md
new file mode 100644
index 00000000..c60e35a1
--- /dev/null
+++ b/website/content/ChapterFour/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.md
@@ -0,0 +1,108 @@
+# [828. Count Unique Characters of All Substrings of a Given String](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/)
+
+
+## 题目
+
+Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`, for example if `s = "LEETCODE"` then `"L"`, `"T"`,`"C"`,`"O"`,`"D"` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`.On this problem given a string `s` we need to return the sum of `countUniqueChars(t)` where `t` is a substring of `s`. Notice that some substrings can be repeated so on this case you have to count the repeated ones too.
+
+Since the answer can be very large, return the answer modulo `10 ^ 9 + 7`.
+
+**Example 1**:
+
+```
+Input: s = "ABC"
+Output: 10
+Explanation: All possible substrings are: "A","B","C","AB","BC" and "ABC".
+Evey substring is composed with only unique letters.
+Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10
+
+```
+
+**Example 2**:
+
+```
+Input: s = "ABA"
+Output: 8
+Explanation: The same as example 1, except countUniqueChars("ABA") = 1.
+
+```
+
+**Example 3**:
+
+```
+Input: s = "LEETCODE"
+Output: 92
+
+```
+
+**Constraints**:
+
+- `0 <= s.length <= 10^4`
+- `s` contain upper-case English letters only.
+
+## 题目大意
+
+如果一个字符在字符串 S 中有且仅有出现一次,那么我们称其为独特字符。例如,在字符串 S = "LETTER" 中,"L" 和 "R" 可以被称为独特字符。我们再定义 UNIQ(S) 作为字符串 S 中独特字符的个数。那么,在 S = "LETTER" 中, UNIQ("LETTER") = 2。
+
+对于给定字符串 S,计算其所有非空子串的独特字符的个数(即 UNIQ(substring))之和。如果在 S 的不同位置上出现两个甚至多个相同的子串,那么我们认为这些子串是不同的。考虑到答案可能会非常大,规定返回格式为:结果 mod 10 ^ 9 + 7。
+
+## 解题思路
+
+- 这一题可以先用暴力解法尝试解题,不过提交以后会发现判题结果是超时。出错的一组数据是一个有 10000 个字符的字符串。暴力解法中间由于遍历了太多的子区间,导致了超时。
+- 这道题换一个角度思考问题。当子字符串中字符 X 出现了 2 次以上,那么它就对最终结果没有任何影响,所以只有当某个字符只出现一次的时候才会影响最终结果。再者,一个子字符串中不重复的字符的总个数,也就是这个子字符串 UNIQ 值。例如,“ABC”,这个子字符串的 UNIQ 值是 3,可以这样计算,它属于 A 的独特的字符串,也属于 B 的独特的字符串,也属于 C 的独特的字符串,那么计算这个子字符串的问题可以分解成计算 A 有多少个独特的子字符串,B 有多少个独特的子字符串,C 有多少个独特的子字符串的问题。在计算 A 有多少个子字符串的问题的时候,里面肯定会包含 "ABC" 这个子字符串的。所以原问题就转换成了分别计算给出的字符串中每个字符出现在独特字符串中的总数之和。
+- 假设原字符串是 BAABBABBBAAABA,这个字符串中出现了很多 A 和很多 B,假设我们当前计算到了第 3 个 A 的位置了(index = 5),即标红色的那个 A。如何计算这个 A 在哪些子字符串中是独特的呢?由于子字符串题目中要求必须是连续的区间,所以这个问题很简单。找到这个 A 前一个 A 的下标位置(index = 2),再找到这个 A 后一个 A 的下标位置(index = 9),即 BAABBABBBAAABA,第一个 A 和当前计算的 A 中间区间有 2 个字符,第三个 A 和当前计算的 A 中间有 3 个字符。那么当前计算的 A 出现在 `(2 + 1) * (3 + 1) = 12` 个子字符串中是独特的,这 12 个字符串是:`A`,`BA`,`BBA`,`AB`,`ABB`,`ABBB`,`BAB`,`BABB`,`BABBB`,`BBAB`,`BBABB`,`BBABBB`。计算方法,假设当前待计算的字符的下标是 i ,找到当前字符前一次出现的下标位置 left,再找到当前字符后一次出现的下标位置 right,那么左边区间 (left,i) 的***开区间****内包含的字符数是 i - left - 1,右边区间 (i,right) 的***开区间****内包含的字符数是 right - i - 1。左右两边都还需要考虑空字符串的情况,即左右两边都可以不取任何字符,那么对应的就是只有中间这个待计算的字符 `A`。所以左右两边都还需要再加上空串的情况,左边 i - left - 1 + 1 = i - left,右边 right - i - 1 + 1 = right - i。左右两边的情况进行排列组合,即 (i - left) * (right - i)。针对字符串的每个字符都计算这样的值,最后累积的总和就是题目中要求的总 UNIQ 值。
+
+## 代码
+
+```go
+package leetcode
+
+func uniqueLetterString(S string) int {
+ res, left, right := 0, 0, 0
+ for i := 0; i < len(S); i++ {
+ left = i - 1
+ for left >= 0 && S[left] != S[i] {
+ left--
+ }
+ right = i + 1
+ for right < len(S) && S[right] != S[i] {
+ right++
+ }
+ res += (i - left) * (right - i)
+ }
+ return res % 1000000007
+}
+
+// 暴力解法,超时!时间复杂度 O(n^2)
+func uniqueLetterString1(S string) int {
+ if len(S) == 0 {
+ return 0
+ }
+ res, mod := 0, 1000000007
+ for i := 0; i < len(S); i++ {
+ letterMap := map[byte]int{}
+ for j := i; j < len(S); j++ {
+ letterMap[S[j]]++
+ tmp := 0
+ for _, v := range letterMap {
+ if v > 1 {
+ tmp++
+ }
+ }
+ if tmp == len(letterMap) {
+ continue
+ } else {
+ res += len(letterMap) - tmp
+ }
+ }
+ }
+ return res % mod
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0830.Positions-of-Large-Groups.md b/website/content/ChapterFour/0830.Positions-of-Large-Groups.md
new file mode 100644
index 00000000..3fdced6d
--- /dev/null
+++ b/website/content/ChapterFour/0830.Positions-of-Large-Groups.md
@@ -0,0 +1,87 @@
+# [830. Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups/)
+
+
+## 题目
+
+In a string `s` of lowercase letters, these letters form consecutive groups of the same character.
+
+For example, a string like `s = "abbxxxxzyy"` has the groups `"a"`, `"bb"`, `"xxxx"`, `"z"`, and `"yy"`.
+
+A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indices (inclusive) of the group. In the above example, `"xxxx"` has the interval `[3,6]`.
+
+A group is considered **large** if it has 3 or more characters.
+
+Return *the intervals of every **large** group sorted in **increasing order by start index***.
+
+**Example 1**:
+
+```
+Input: s = "abbxxxxzzy"
+Output: [[3,6]]
+Explanation: "xxxx" is the only large group with start index 3 and end index 6.
+```
+
+**Example 2**:
+
+```
+Input: s = "abc"
+Output: []
+Explanation: We have groups "a", "b", and "c", none of which are large groups.
+```
+
+**Example 3**:
+
+```
+Input: s = "abcdddeeeeaabbbcd"
+Output: [[3,5],[6,9],[12,14]]
+Explanation: The large groups are "ddd", "eeee", and "bbb".
+```
+
+**Example 4**:
+
+```
+Input: s = "aba"
+Output: []
+```
+
+**Constraints**:
+
+- `1 <= s.length <= 1000`
+- `s` contains lower-case English letters only.
+
+## 题目大意
+
+在一个由小写字母构成的字符串 s 中,包含由一些连续的相同字符所构成的分组。例如,在字符串 s = "abbxxxxzyy" 中,就含有 "a", "bb", "xxxx", "z" 和 "yy" 这样的一些分组。分组可以用区间 [start, end] 表示,其中 start 和 end 分别表示该分组的起始和终止位置的下标。上例中的 "xxxx" 分组用区间表示为 [3,6] 。我们称所有包含大于或等于三个连续字符的分组为 较大分组 。
+
+找到每一个 较大分组 的区间,按起始位置下标递增顺序排序后,返回结果。
+
+## 解题思路
+
+- 简单题。利用滑动窗口的思想,先扩大窗口的右边界,找到能相同字母且能到达的最右边。记录左右边界。再将窗口的左边界移动到上一次的右边界处。以此类推,重复扩大窗口的右边界,直至扫完整个字符串。最终所有满足题意的较大分组区间都在数组中了。
+
+## 代码
+
+```go
+package leetcode
+
+func largeGroupPositions(S string) [][]int {
+ res, end := [][]int{}, 0
+ for end < len(S) {
+ start, str := end, S[end]
+ for end < len(S) && S[end] == str {
+ end++
+ }
+ if end-start >= 3 {
+ res = append(res, []int{start, end - 1})
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0832.Flipping-an-Image.md b/website/content/ChapterFour/0832.Flipping-an-Image.md
index 81b8ccc9..50bf028f 100644
--- a/website/content/ChapterFour/0832.Flipping-an-Image.md
+++ b/website/content/ChapterFour/0832.Flipping-an-Image.md
@@ -60,4 +60,11 @@ func flipAndInvertImage(A [][]int) [][]int {
return A
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md b/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md
index b0390a4a..d6a010e8 100755
--- a/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md
+++ b/website/content/ChapterFour/0834.Sum-of-Distances-in-Tree.md
@@ -98,4 +98,11 @@ func deepSecondSearch(root int, visited []bool, count, res []int, tree [][]int)
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0836.Rectangle-Overlap.md b/website/content/ChapterFour/0836.Rectangle-Overlap.md
index 2cce0169..986dda6e 100755
--- a/website/content/ChapterFour/0836.Rectangle-Overlap.md
+++ b/website/content/ChapterFour/0836.Rectangle-Overlap.md
@@ -51,4 +51,11 @@ func isRectangleOverlap(rec1 []int, rec2 []int) bool {
return rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0838.Push-Dominoes.md b/website/content/ChapterFour/0838.Push-Dominoes.md
index 7acc9ce5..548a2bac 100644
--- a/website/content/ChapterFour/0838.Push-Dominoes.md
+++ b/website/content/ChapterFour/0838.Push-Dominoes.md
@@ -141,4 +141,11 @@ func pushDominoes1(dominoes string) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0839.Similar-String-Groups.md b/website/content/ChapterFour/0839.Similar-String-Groups.md
index 217ee2da..e1ad098b 100755
--- a/website/content/ChapterFour/0839.Similar-String-Groups.md
+++ b/website/content/ChapterFour/0839.Similar-String-Groups.md
@@ -95,4 +95,11 @@ func isSimilar(a, b string) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0841.Keys-and-Rooms.md b/website/content/ChapterFour/0841.Keys-and-Rooms.md
index 69d1da3a..b7f3e74a 100644
--- a/website/content/ChapterFour/0841.Keys-and-Rooms.md
+++ b/website/content/ChapterFour/0841.Keys-and-Rooms.md
@@ -77,4 +77,11 @@ func dfsVisitAllRooms(es [][]int, visited map[int]bool, from int) {
dfsVisitAllRooms(es, visited, to)
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md b/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md
index 9bb286ec..6326d234 100755
--- a/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md
+++ b/website/content/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md
@@ -132,4 +132,11 @@ func findRecursiveCheck(S string, x1 int, x2 int, left int, res *[]int, isComple
return
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0844.Backspace-String-Compare.md b/website/content/ChapterFour/0844.Backspace-String-Compare.md
index fb758f3b..2ecbe11f 100644
--- a/website/content/ChapterFour/0844.Backspace-String-Compare.md
+++ b/website/content/ChapterFour/0844.Backspace-String-Compare.md
@@ -108,4 +108,11 @@ func backspaceCompare(S string, T string) bool {
return string(s) == string(s2)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md b/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md
index 0f44f673..9379ea68 100644
--- a/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md
+++ b/website/content/ChapterFour/0845.Longest-Mountain-in-Array.md
@@ -88,4 +88,11 @@ func longestMountain(A []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0850.Rectangle-Area-II.md b/website/content/ChapterFour/0850.Rectangle-Area-II.md
index 29dbe94e..149bcf13 100755
--- a/website/content/ChapterFour/0850.Rectangle-Area-II.md
+++ b/website/content/ChapterFour/0850.Rectangle-Area-II.md
@@ -290,4 +290,11 @@ func (sat *SegmentAreaTree) updateInTree(treeIndex, left, right, updateLeft, upd
sat.pushUp(treeIndex, leftTreeIndex, rightTreeIndex)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0851.Loud-and-Rich.md b/website/content/ChapterFour/0851.Loud-and-Rich.md
index 26351328..fbe44627 100644
--- a/website/content/ChapterFour/0851.Loud-and-Rich.md
+++ b/website/content/ChapterFour/0851.Loud-and-Rich.md
@@ -105,4 +105,11 @@ func loudAndRich(richer [][]int, quiet []int) []int {
}
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md b/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md
index ea6ae942..0948ede4 100755
--- a/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md
+++ b/website/content/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md
@@ -88,4 +88,11 @@ func peakIndexInMountainArray1(A []int) int {
return low
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0853.Car-Fleet.md b/website/content/ChapterFour/0853.Car-Fleet.md
index b28efdbd..bb13b0d5 100755
--- a/website/content/ChapterFour/0853.Car-Fleet.md
+++ b/website/content/ChapterFour/0853.Car-Fleet.md
@@ -95,4 +95,11 @@ func carFleet(target int, position []int, speed []int) int {
return fleet
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0856.Score-of-Parentheses.md b/website/content/ChapterFour/0856.Score-of-Parentheses.md
index 9d5c8758..7c810458 100644
--- a/website/content/ChapterFour/0856.Score-of-Parentheses.md
+++ b/website/content/ChapterFour/0856.Score-of-Parentheses.md
@@ -99,4 +99,11 @@ func scoreOfParentheses(S string) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md b/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md
index 469ca3bd..0bd92651 100644
--- a/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md
+++ b/website/content/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md
@@ -87,4 +87,11 @@ func shortestSubarray(A []int, K int) int {
}
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md b/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md
index 4ea32b20..c212698a 100644
--- a/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md
+++ b/website/content/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md
@@ -93,4 +93,11 @@ func findChild(root *TreeNode, K int, visit *[]int) {
findChild(root.Right, K-1, visit)
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md b/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md
index d6d65b49..b9dcafd7 100755
--- a/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md
+++ b/website/content/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md
@@ -228,4 +228,11 @@ func isKey(board [][]byte, x, y int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0867.Transpose-Matrix.md b/website/content/ChapterFour/0867.Transpose-Matrix.md
index 379b9b25..b9a42775 100755
--- a/website/content/ChapterFour/0867.Transpose-Matrix.md
+++ b/website/content/ChapterFour/0867.Transpose-Matrix.md
@@ -54,4 +54,11 @@ func transpose(A [][]int) [][]int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0872.Leaf-Similar-Trees.md b/website/content/ChapterFour/0872.Leaf-Similar-Trees.md
index 900b7e74..bce16f6b 100644
--- a/website/content/ChapterFour/0872.Leaf-Similar-Trees.md
+++ b/website/content/ChapterFour/0872.Leaf-Similar-Trees.md
@@ -59,4 +59,11 @@ func dfsLeaf(root *TreeNode, leaf *[]int) {
dfsLeaf(root.Right, leaf)
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0875.Koko-Eating-Bananas.md b/website/content/ChapterFour/0875.Koko-Eating-Bananas.md
index f2c7c411..7da578f7 100755
--- a/website/content/ChapterFour/0875.Koko-Eating-Bananas.md
+++ b/website/content/ChapterFour/0875.Koko-Eating-Bananas.md
@@ -98,4 +98,11 @@ func maxInArr(xs []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md b/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md
index b9f801fd..e4532487 100644
--- a/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md
+++ b/website/content/ChapterFour/0876.Middle-of-the-Linked-List.md
@@ -79,4 +79,11 @@ func middleNode(head *ListNode) *ListNode {
return p1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0878.Nth-Magical-Number.md b/website/content/ChapterFour/0878.Nth-Magical-Number.md
index d78c5ed9..7dc186cc 100755
--- a/website/content/ChapterFour/0878.Nth-Magical-Number.md
+++ b/website/content/ChapterFour/0878.Nth-Magical-Number.md
@@ -78,4 +78,11 @@ func calNthMagicalCount(num, a, b int64) int64 {
return num/a + num/b - num/ab
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0880.Decoded-String-at-Index.md b/website/content/ChapterFour/0880.Decoded-String-at-Index.md
index 96056438..e1f0e0b1 100644
--- a/website/content/ChapterFour/0880.Decoded-String-at-Index.md
+++ b/website/content/ChapterFour/0880.Decoded-String-at-Index.md
@@ -101,4 +101,11 @@ func decodeAtIndex(S string, K int) string {
return ""
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0881.Boats-to-Save-People.md b/website/content/ChapterFour/0881.Boats-to-Save-People.md
index 2af2b88d..a42fd693 100644
--- a/website/content/ChapterFour/0881.Boats-to-Save-People.md
+++ b/website/content/ChapterFour/0881.Boats-to-Save-People.md
@@ -87,4 +87,11 @@ func numRescueBoats(people []int, limit int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md b/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md
index 66fc23b0..cf2505db 100755
--- a/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md
+++ b/website/content/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md
@@ -63,4 +63,11 @@ func uncommonFromSentences(A string, B string) []string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0885.Spiral-Matrix-III.md b/website/content/ChapterFour/0885.Spiral-Matrix-III.md
index 0a80d2e0..9e57b2b0 100755
--- a/website/content/ChapterFour/0885.Spiral-Matrix-III.md
+++ b/website/content/ChapterFour/0885.Spiral-Matrix-III.md
@@ -81,4 +81,11 @@ func spiralMatrixIII(R int, C int, r0 int, c0 int) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0887.Super-Egg-Drop.md b/website/content/ChapterFour/0887.Super-Egg-Drop.md
index a79b6085..d7508003 100755
--- a/website/content/ChapterFour/0887.Super-Egg-Drop.md
+++ b/website/content/ChapterFour/0887.Super-Egg-Drop.md
@@ -56,11 +56,10 @@ What is the minimum number of moves that you need to know with certainty what
- 给出 `K` 个鸡蛋,`N` 层楼,要求确定安全楼层 `F` 需要最小步数 `t`。
- 这一题是微软的经典面试题。拿到题最容易想到的是二分搜索。但是仔细分析以后会发现单纯的二分是不对的。不断的二分确实能找到最终安全的楼层,但是这里没有考虑到 `K` 个鸡蛋。鸡蛋数的限制会导致二分搜索无法找到最终楼层。题目要求要在保证能找到最终安全楼层的情况下,找到最小步数。所以单纯的二分搜索并不能解答这道题。
-- 这一题如果按照题意正向考虑,动态规划的状态转移方程是 `searchTime(K, N) = max( searchTime(K-1, X-1), searchTime(K, N-X) )`。其中 `X` 是丢鸡蛋的楼层。随着 `X` 从 `[1,N]`,都能计算出一个 `searchTime` 的值,在所有这 `N` 个值之中,取最小值就是本题的答案了。这个解法可以 AC 这道题。不过这个解法不细展开了。时间复杂度 `O(k*N^2)`。
-
-
-
-
+- 这一题如果按照题意正向考虑,动态规划的状态转移方程是 `searchTime(K, N) = max( searchTime(K-1, X-1), searchTime(K, N-X) )`。其中 `X` 是丢鸡蛋的楼层。随着 `X` 从 `[1,N]`,都能计算出一个 `searchTime` 的值,在所有这 `N` 个值之中,取最小值就是本题的答案了。这个解法可以 AC 这道题。不过这个解法不细展开了。时间复杂度 `O(k*N^2)`。
+{{< katex display >}}
+dp(K,N) = MIN \begin{bmatrix} \, \, MAX(dp(K-1,X-1),dp(K,N-X))\, \, \end{bmatrix} ,1\leqslant x \leqslant N \\
+{{< /katex >}}
- 换个角度来看这个问题,定义 `dp[k][m]` 代表 `K` 个鸡蛋,`M` 次移动能检查的最大楼层。考虑某一步 `t` 应该在哪一层丢鸡蛋呢?一个正确的选择是在 `dp[k-1][t-1] + 1` 层丢鸡蛋,结果分两种情况:
1. 如果鸡蛋碎了,我们首先排除了该层以上的所有楼层(不管这个楼有多高),而对于剩下的 `dp[k-1][t-1]` 层楼,我们一定能用 `k-1` 个鸡蛋在 `t-1` 步内求解。因此这种情况下,我们总共可以求解无限高的楼层。可见,这是一种非常好的情况,但并不总是发生。
2. 如果鸡蛋没碎,我们首先排除了该层以下的 `dp[k-1][t-1]` 层楼,此时我们还有 `k` 个蛋和 `t-1` 步,那么我们去该层以上的楼层继续测得 `dp[k][t-1]` 层楼。因此这种情况下,我们总共可以求解 `dp[k-1][t-1] + 1 + dp[k][t-1]` 层楼。
@@ -70,43 +69,34 @@ What is the minimum number of moves that you need to know with certainty what
2. 如果在更高的楼层丢鸡蛋,假设是第 `dp[k-1][t-1] + 2` 层丢鸡蛋,如果这次鸡蛋碎了,剩下 `k-1` 个鸡蛋和 `t-1` 步只能保证验证 `dp[k-1][t-1]` 的楼层,这里还剩**第** `dp[k-1][t-1]+ 1` 的楼层,不能保证最终一定能找到安全楼层了。
- 用反证法就能得出每一步都应该在第 `dp[k-1][t-1] + 1` 层丢鸡蛋。
- 这道题还可以用二分搜索来解答。回到上面分析的状态转移方程:`dp[k][m] = dp[k-1][m-1] + dp[k][m-1] + 1` 。用数学方法来解析这个递推关系。令 `f(t,k)` 为 `t` 和 `k` 的函数,题目所要求能测到最大楼层是 `N` 的最小步数,即要求出 `f(t,k) ≥ N` 时候的最小 `t`。由状态转移方程可以知道:`f(t,k) = f(t-1,k) + f(t-1,k-1) + 1`,当 `k = 1` 的时候,对应一个鸡蛋的情况,`f(t,1) = t`,当 `t = 1` 的时候,对应一步的情况,`f(1,k) = 1`。有状态转移方程得:
-
-
-
-
-- 令 `g(t,k) = f(t,k) - f(t,k-1)`,可以得到:
-
-
-
-
-
-- 可以知道 `g(t,k)` 是一个杨辉三角,即二项式系数:
-
-
-
-
-
-- 利用裂项相消的方法:
-
-
-
-
-- 于是可以得到:
-
-
-
-
-- 其中:
-
-
-
-
-- 于是针对每一项的二项式常数,都可以由前一项乘以一个分数得到下一项。
-
-
-
-
-- 利用二分搜索,不断的二分 `t`,直到逼近找到 `f(t,k) ≥ N` 时候最小的 `t`。时间复杂度 `O(K * log N)`,空间复杂度 `O(1)`。
+{{< katex display >}}
+\begin{aligned} f(t,k) &= 1 + f(t-1,k-1) + f(t-1,k) \\ f(t,k-1) &= 1 + f(t-1,k-2) + f(t-1,k-1) \\ \end{aligned}
+{{< /katex >}}
+ 令 `g(t,k) = f(t,k) - f(t,k-1)`,可以得到:
+{{< katex display >}}
+g(t,k) = g(t-1,k) + g(t-1,k-1)
+{{< /katex >}}
+ 可以知道 `g(t,k)` 是一个杨辉三角,即二项式系数:
+{{< katex display >}}
+g(t,k) = \binom{t}{k+1} = C_{t}^{k+1}
+{{< /katex >}}
+ 利用裂项相消的方法:
+{{< katex display >}}
+\begin{aligned} g(t,x) &= f(t,x) - f(t,x-1) \\ g(t,x-1) &= f(t,x-1) - f(t,x-2) \\ g(t,x-2) &= f(t,x-2) - f(t,x-3) \\ \begin{matrix} .\\ .\\ .\\ \end{matrix}\\ g(t,2) &= f(t,2) - f(t,1) \\ g(t,1) &= f(t,1) - f(t,0) \\ \end{aligned}
+{{< /katex >}}
+ 于是可以得到:
+{{< katex display >}}
+\begin{aligned} f(t,k) &= \sum_{1}^{k}g(t,x) = \sum_{0}^{k} \binom{t}{x} \\ &= C_{t}^{0} + C_{t}^{1} + C_{t}^{2} + ... + C_{t}^{k} \\ \end{aligned}
+{{< /katex >}}
+ 其中:
+{{< katex display >}}
+\begin{aligned} C_{t}^{k} \cdot \frac{n-k}{k+1} &= C_{t}^{k+1} \\ C_{t}^{k} &= C_{t}^{k-1} \cdot \frac{t-k+1}{k} \\ \end{aligned}
+{{< /katex >}}
+ 于是针对每一项的二项式常数,都可以由前一项乘以一个分数得到下一项。
+{{< katex display >}}
+\begin{aligned} C_{t}^{0} &= 1 \\ C_{t}^{1} &= C_{t}^{0} \cdot \frac{t-1+1}{1} \\ C_{t}^{2} &= C_{t}^{1} \cdot \frac{t-2+1}{2} \\ C_{t}^{3} &= C_{t}^{2} \cdot \frac{t-3+1}{3} \\ \begin{matrix} .\\ .\\ .\\ \end{matrix}\\ C_{t}^{k} &= C_{t}^{k-1} \cdot \frac{t-k+1}{k} \\ \end{aligned}
+{{< /katex >}}
+ 利用二分搜索,不断的二分 `t`,直到逼近找到 `f(t,k) ≥ N` 时候最小的 `t`。时间复杂度 `O(K * log N)`,空间复杂度 `O(1)`。
@@ -152,4 +142,11 @@ func superEggDrop1(K int, N int) int {
return step
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0888.Fair-Candy-Swap.md b/website/content/ChapterFour/0888.Fair-Candy-Swap.md
index 79a2c2bc..5e805037 100644
--- a/website/content/ChapterFour/0888.Fair-Candy-Swap.md
+++ b/website/content/ChapterFour/0888.Fair-Candy-Swap.md
@@ -107,4 +107,11 @@ func max(a, b int) int {
return b
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md b/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md
index 9e5f0479..b8cf2e13 100644
--- a/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md
+++ b/website/content/ChapterFour/0891.Sum-of-Subsequence-Widths.md
@@ -65,4 +65,11 @@ func sumSubseqWidths(A []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md b/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md
index bcb6ad51..0ffd62dc 100644
--- a/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md
+++ b/website/content/ChapterFour/0892.Surface-Area-of-3D-Shapes.md
@@ -105,4 +105,11 @@ func min(a, b int) int {
return a
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md b/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md
index bd1c2060..776d3184 100644
--- a/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md
+++ b/website/content/ChapterFour/0895.Maximum-Frequency-Stack.md
@@ -110,4 +110,11 @@ func (this *FreqStack) Pop() int {
* param_2 := obj.Pop();
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0896.Monotonic-Array.md b/website/content/ChapterFour/0896.Monotonic-Array.md
index afd6b08d..56eddaa0 100644
--- a/website/content/ChapterFour/0896.Monotonic-Array.md
+++ b/website/content/ChapterFour/0896.Monotonic-Array.md
@@ -96,4 +96,11 @@ func dec(A []int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0897.Increasing-Order-Search-Tree.md b/website/content/ChapterFour/0897.Increasing-Order-Search-Tree.md
index 44076d30..f0639a17 100755
--- a/website/content/ChapterFour/0897.Increasing-Order-Search-Tree.md
+++ b/website/content/ChapterFour/0897.Increasing-Order-Search-Tree.md
@@ -120,4 +120,11 @@ func inorder(root *TreeNode, output *[]int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md b/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md
index 259871f1..c17418d4 100755
--- a/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md
+++ b/website/content/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md
@@ -140,4 +140,11 @@ func subarrayBitwiseORs1(A []int) int {
return len(res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0901.Online-Stock-Span.md b/website/content/ChapterFour/0901.Online-Stock-Span.md
index 582fa43f..b85244d1 100644
--- a/website/content/ChapterFour/0901.Online-Stock-Span.md
+++ b/website/content/ChapterFour/0901.Online-Stock-Span.md
@@ -108,4 +108,11 @@ func (this *StockSpanner) Next(price int) int {
* param_1 := obj.Next(price);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0904.Fruit-Into-Baskets.md b/website/content/ChapterFour/0904.Fruit-Into-Baskets.md
index c3786ae7..95079e7f 100644
--- a/website/content/ChapterFour/0904.Fruit-Into-Baskets.md
+++ b/website/content/ChapterFour/0904.Fruit-Into-Baskets.md
@@ -112,4 +112,11 @@ func totalFruit(tree []int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md b/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md
index 7c5374d4..21544292 100644
--- a/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md
+++ b/website/content/ChapterFour/0907.Sum-of-Subarray-Minimums.md
@@ -121,4 +121,11 @@ func sumSubarrayMins2(A []int) int {
return res % mod
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0910.Smallest-Range-II.md b/website/content/ChapterFour/0910.Smallest-Range-II.md
new file mode 100644
index 00000000..82794f39
--- /dev/null
+++ b/website/content/ChapterFour/0910.Smallest-Range-II.md
@@ -0,0 +1,89 @@
+# [910. Smallest Range II](https://leetcode.com/problems/smallest-range-ii/)
+
+## 题目
+
+Given an array `A` of integers, for each integer `A[i]` we need to choose **either `x = -K` or `x = K`**, and add `x` to `A[i]` **(only once)**.
+
+After this process, we have some array `B`.
+
+Return the smallest possible difference between the maximum value of `B` and the minimum value of `B`.
+
+**Example 1**:
+
+```
+Input: A = [1], K = 0
+Output: 0
+Explanation: B = [1]
+```
+
+**Example 2**:
+
+```
+Input: A = [0,10], K = 2
+Output: 6
+Explanation: B = [2,8]
+```
+
+**Example 3**:
+
+```
+Input: A = [1,3,6], K = 3
+Output: 3
+Explanation: B = [4,6,3]
+```
+
+**Note**:
+
+1. `1 <= A.length <= 10000`
+2. `0 <= A[i] <= 10000`
+3. `0 <= K <= 10000`
+
+## 题目大意
+
+给你一个整数数组 A,对于每个整数 A[i],可以选择 x = -K 或是 x = K (K 总是非负整数),并将 x 加到 A[i] 中。在此过程之后,得到数组 B。返回 B 的最大值和 B 的最小值之间可能存在的最小差值。
+
+## 解题思路
+
+- 简单题。先排序,找出 A 数组中最大的差值。然后循环扫一遍数组,利用双指针,选择 x = -K 或是 x = K ,每次选择都更新一次最大值和最小值之间的最小差值。循环一次以后便可以找到满足题意的答案。
+
+## 代码
+
+```go
+package leetcode
+
+import "sort"
+
+func smallestRangeII(A []int, K int) int {
+ n := len(A)
+ sort.Ints(A)
+ res := A[n-1] - A[0]
+ for i := 0; i < n-1; i++ {
+ a, b := A[i], A[i+1]
+ high := max(A[n-1]-K, a+K)
+ low := min(A[0]+K, b-K)
+ res = min(res, high-low)
+ }
+ return res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0911.Online-Election.md b/website/content/ChapterFour/0911.Online-Election.md
index 63a73bb6..eedcb5c8 100755
--- a/website/content/ChapterFour/0911.Online-Election.md
+++ b/website/content/ChapterFour/0911.Online-Election.md
@@ -96,4 +96,11 @@ func (tvc *TopVotedCandidate) Q(t int) int {
* param_1 := obj.Q(t);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md b/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md
index 02c8ebdd..8c1ad0f3 100644
--- a/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md
+++ b/website/content/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md
@@ -102,4 +102,11 @@ func gcd(a, b int) int {
return gcd(b%a, a)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md b/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md
index 1b60e16e..6f2526d7 100755
--- a/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md
+++ b/website/content/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md
@@ -98,4 +98,11 @@ func kadane(a []int) int {
return maxSoFar
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0920.Number-of-Music-Playlists.md b/website/content/ChapterFour/0920.Number-of-Music-Playlists.md
index b0efa478..cd023864 100755
--- a/website/content/ChapterFour/0920.Number-of-Music-Playlists.md
+++ b/website/content/ChapterFour/0920.Number-of-Music-Playlists.md
@@ -53,9 +53,9 @@ Return the number of possible playlists. **As the answer can be very large, ret
- 简化抽象一下题意,给 N 个数,要求从这 N 个数里面组成一个长度为 L 的序列,并且相同元素的间隔不能小于 K 个数。问总共有多少组组成方法。
- 一拿到题,会觉得这一题是三维 DP,因为存在 3 个变量,但是实际考虑一下,可以降一维。我们先不考虑 K 的限制,只考虑 N 和 L。定义 `dp[i][j]` 代表播放列表里面有 `i` 首歌,其中包含 `j` 首不同的歌曲,那么题目要求的最终解存在 `dp[L][N]` 中。考虑 `dp[i][j]` 的递归公式,音乐列表当前需要组成 `i` 首歌,有 2 种方式可以得到,由 `i - 1` 首歌的列表中添加一首列表中**不存在**的新歌曲,或者由 `i - 1` 首歌的列表中添加一首列表中**已经存在**的歌曲。即,`dp[i][j]` 可以由 `dp[i - 1][j - 1]` 得到,也可以由 `dp[i - 1][j]` 得到。如果是第一种情况,添加一首新歌,那么新歌有 N - ( j - 1 ) 首,如果是第二种情况,添加一首已经存在的歌,歌有 j 首,所以状态转移方程是 `dp[i][j] = dp[i - 1][j - 1] * ( N - ( j - 1 ) ) + dp[i - 1][j] * j` 。但是这个方程是在不考虑 K 的限制条件下得到的,距离满足题意还差一步。接下来需要考虑加入 K 这个限制条件以后,状态转移方程该如何推导。
- 如果是添加一首新歌,是不受 K 限制的,所以 `dp[i - 1][j - 1] * ( N - ( j - 1 ) )` 这里不需要变化。如果是添加一首存在的歌曲,这个时候就会受到 K 的限制了。如果当前播放列表里面的歌曲有 `j` 首,并且 `j > K`,那么选择歌曲只能从 `j - K` 里面选,因为不能选择 `j - 1` 到 `j - k` 的这些歌,选择了就不满足重复的歌之间间隔不能小于 `K` 的限制条件了。那 j ≤ K 呢?这个时候一首歌都不能选,因为歌曲数都没有超过 K,当然不能再选择重复的歌曲。(选择了就再次不满足重复的歌之间间隔不能小于 `K` 的限制条件了)。经过上述分析,可以得到最终的状态转移方程:
-
-
-
+{{< katex display >}}
+dp[i][j]= \begin{matrix} \left\{ \begin{array}{lr} dp[i - 1][j - 1] * ( N - ( j - 1 ) ) + dp[i - 1][j] * ( j - k ) , & {j > k}\\ dp[i - 1][j - 1] * ( N - ( j - 1 ) ), & {j \leq k} \end{array} \right. \end{matrix}
+{{< /katex >}}
- 上面的式子可以合并简化成下面这个式子:`dp[i][j] = dp[i - 1][j - 1]*(N - (j - 1)) + dp[i-1][j]*max(j-K, 0)`,递归初始值 `dp[0][0] = 1`。
@@ -82,4 +82,11 @@ func numMusicPlaylists(N int, L int, K int) int {
return dp[L][N]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md b/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md
index 8952fe95..d634ca3d 100644
--- a/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md
+++ b/website/content/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md
@@ -85,4 +85,11 @@ func minAddToMakeValid(S string) int {
return len(stack)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md b/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md
index ca915fd9..1b315cbb 100644
--- a/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md
+++ b/website/content/ChapterFour/0922.Sort-Array-By-Parity-II.md
@@ -58,4 +58,11 @@ func sortArrayByParityII(A []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md b/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md
index 0673f0de..b10b767f 100644
--- a/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md
+++ b/website/content/ChapterFour/0923.3Sum-With-Multiplicity.md
@@ -99,4 +99,11 @@ func threeSumMulti(A []int, target int) int {
return res % mod
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0924.Minimize-Malware-Spread.md b/website/content/ChapterFour/0924.Minimize-Malware-Spread.md
index ce5c8970..3b4fb596 100755
--- a/website/content/ChapterFour/0924.Minimize-Malware-Spread.md
+++ b/website/content/ChapterFour/0924.Minimize-Malware-Spread.md
@@ -102,4 +102,11 @@ func minMalwareSpread(graph [][]int, initial []int) int {
return minIndex
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0925.Long-Pressed-Name.md b/website/content/ChapterFour/0925.Long-Pressed-Name.md
index 4483d591..4025899b 100644
--- a/website/content/ChapterFour/0925.Long-Pressed-Name.md
+++ b/website/content/ChapterFour/0925.Long-Pressed-Name.md
@@ -61,8 +61,8 @@ Explanation: It's not necessary to long press any character.
## 解题思路
-这一题也可以借助滑动窗口的思想。2 个字符串一起比较,如果遇到有相同的字符串,窗口继续往后滑动。直到遇到了第一个不同的字符,如果遇到两个字符串不相等的情况,可以直接返回 false。具体实现见代码。
-
+- 这一题也可以借助滑动窗口的思想。2 个字符串一起比较,如果遇到有相同的字符串,窗口继续往后滑动。直到遇到了第一个不同的字符,如果遇到两个字符串不相等的情况,可以直接返回 false。具体实现见代码。
+- 这一题的测试用例修改过一次,需要注意我这里写的第二组测试用例,当 name 结束以后,如果 typed 还有多余的不同的字符,这种情况要输出 false 的。具体见 test 文件里面的第二组,第三组,第四组测试用例。
@@ -88,22 +88,27 @@ func isLongPressedName(name string, typed string) bool {
if (len(name) == 0 && len(typed) != 0) || (len(name) != 0 && len(typed) == 0) {
return false
}
-
- j := 0
- for i := 0; i < len(name); i++ {
- if j < len(typed) && name[i] == typed[j] {
+ i, j := 0, 0
+ for i < len(name) && j < len(typed) {
+ if name[i] != typed[j] {
+ return false
+ }
+ for i < len(name) && j < len(typed) && name[i] == typed[j] {
+ i++
+ j++
+ }
+ for j < len(typed) && typed[j] == typed[j-1] {
j++
- continue
- } else {
- if i > 0 && j < len(typed) && name[i-1] == typed[j] {
- j++
- i--
- } else {
- return false
- }
}
}
- return true
+ return i == len(name) && j == len(typed)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0927.Three-Equal-Parts.md b/website/content/ChapterFour/0927.Three-Equal-Parts.md
index 311b8c49..d0f0979e 100755
--- a/website/content/ChapterFour/0927.Three-Equal-Parts.md
+++ b/website/content/ChapterFour/0927.Three-Equal-Parts.md
@@ -110,4 +110,11 @@ func threeEqualParts(A []int) []int {
return []int{-1, -1}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md b/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md
index 4d83986b..22e9f45e 100755
--- a/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md
+++ b/website/content/ChapterFour/0928.Minimize-Malware-Spread-II.md
@@ -134,4 +134,11 @@ func minMalwareSpread2(graph [][]int, initial []int) int {
return minIndex
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md b/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md
index 161579ce..265f9b31 100644
--- a/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md
+++ b/website/content/ChapterFour/0930.Binary-Subarrays-With-Sum.md
@@ -62,4 +62,11 @@ func numSubarraysWithSum(A []int, S int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0933.Number-of-Recent-Calls.md b/website/content/ChapterFour/0933.Number-of-Recent-Calls.md
index 02b2340c..44cf1056 100644
--- a/website/content/ChapterFour/0933.Number-of-Recent-Calls.md
+++ b/website/content/ChapterFour/0933.Number-of-Recent-Calls.md
@@ -71,4 +71,11 @@ func (this *RecentCounter) Ping(t int) int {
* obj := Constructor();
* param_1 := obj.Ping(t);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0942.DI-String-Match.md b/website/content/ChapterFour/0942.DI-String-Match.md
index 485dee18..7254de73 100755
--- a/website/content/ChapterFour/0942.DI-String-Match.md
+++ b/website/content/ChapterFour/0942.DI-String-Match.md
@@ -70,4 +70,11 @@ func diStringMatch(S string) []int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0946.Validate-Stack-Sequences.md b/website/content/ChapterFour/0946.Validate-Stack-Sequences.md
index f69621d2..7794c71b 100644
--- a/website/content/ChapterFour/0946.Validate-Stack-Sequences.md
+++ b/website/content/ChapterFour/0946.Validate-Stack-Sequences.md
@@ -65,4 +65,11 @@ func validateStackSequences(pushed []int, popped []int) bool {
return j == N
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md b/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md
index 886bb036..b976171e 100755
--- a/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md
+++ b/website/content/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md
@@ -79,4 +79,11 @@ func removeStones(stones [][]int) int {
return len(stones) - uf.TotalCount()
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md b/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md
index 02f0bf43..6ec4fffa 100644
--- a/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md
+++ b/website/content/ChapterFour/0949.Largest-Time-for-Given-Digits.md
@@ -75,4 +75,11 @@ func largestTimeFromDigits(A []int) string {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md b/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md
index d37262bc..85c83482 100755
--- a/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md
+++ b/website/content/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md
@@ -116,4 +116,11 @@ func largestComponentSize1(A []int) int {
return uf.MaxUnionCount()
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md b/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md
index ff648c14..dfdde219 100755
--- a/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md
+++ b/website/content/ChapterFour/0953.Verifying-an-Alien-Dictionary.md
@@ -78,4 +78,11 @@ func isAlienSorted(words []string, order string) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md b/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md
index c560cc59..d9f8eed2 100755
--- a/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md
+++ b/website/content/ChapterFour/0959.Regions-Cut-By-Slashes.md
@@ -147,4 +147,11 @@ func getFaceIdx(size, i, j, k int) int {
return 4*(i*size+j) + k
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md b/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md
index a9e53e77..5fe35e97 100755
--- a/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md
+++ b/website/content/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md
@@ -57,4 +57,11 @@ func repeatedNTimes(A []int) int {
return 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0968.Binary-Tree-Cameras.md b/website/content/ChapterFour/0968.Binary-Tree-Cameras.md
index d9873a5b..d11dbab5 100755
--- a/website/content/ChapterFour/0968.Binary-Tree-Cameras.md
+++ b/website/content/ChapterFour/0968.Binary-Tree-Cameras.md
@@ -100,4 +100,11 @@ func minCameraCoverDFS(root *TreeNode, res *int) status {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0969.Pancake-Sorting.md b/website/content/ChapterFour/0969.Pancake-Sorting.md
index 68288d5c..6755f805 100644
--- a/website/content/ChapterFour/0969.Pancake-Sorting.md
+++ b/website/content/ChapterFour/0969.Pancake-Sorting.md
@@ -93,4 +93,11 @@ func find(nums []int, t int) int {
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0970.Powerful-Integers.md b/website/content/ChapterFour/0970.Powerful-Integers.md
index 9de40954..95a7db75 100755
--- a/website/content/ChapterFour/0970.Powerful-Integers.md
+++ b/website/content/ChapterFour/0970.Powerful-Integers.md
@@ -85,4 +85,11 @@ func pow(x, i int) int {
return int(math.Pow(float64(x), float64(i)))
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md b/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md
index a0b3a760..77984f7e 100644
--- a/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md
+++ b/website/content/ChapterFour/0973.K-Closest-Points-to-Origin.md
@@ -68,4 +68,11 @@ func KClosest(points [][]int, K int) [][]int {
return ans
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md b/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md
index 52b5b24c..078db7d9 100644
--- a/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md
+++ b/website/content/ChapterFour/0976.Largest-Perimeter-Triangle.md
@@ -75,4 +75,11 @@ func largestPerimeter(A []int) int {
return 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md b/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md
index 06fbd1a7..d02cfd81 100644
--- a/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md
+++ b/website/content/ChapterFour/0977.Squares-of-a-Sorted-Array.md
@@ -83,4 +83,11 @@ func sortedSquares1(A []int) []int {
return A
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md b/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md
index e4b8bea7..62ece5f2 100755
--- a/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md
+++ b/website/content/ChapterFour/0978.Longest-Turbulent-Subarray.md
@@ -97,7 +97,7 @@ func maxTurbulenceSize1(A []int) int {
flag = lastNum - A[right]
lastNum = A[right]
} else {
- if right != left && flag != 0 {
+ if flag != 0 {
res = max(res, right-left+1)
}
left++
@@ -106,4 +106,11 @@ func maxTurbulenceSize1(A []int) int {
return max(res, 1)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md b/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md
index ac98a452..93872dbb 100755
--- a/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md
+++ b/website/content/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md
@@ -93,4 +93,11 @@ func distributeCoinsDFS(root *TreeNode, res *int) int {
return left + right + root.Val - 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0980.Unique-Paths-III.md b/website/content/ChapterFour/0980.Unique-Paths-III.md
index 94f53c18..908e25c8 100755
--- a/website/content/ChapterFour/0980.Unique-Paths-III.md
+++ b/website/content/ChapterFour/0980.Unique-Paths-III.md
@@ -128,4 +128,11 @@ func findUniquePathIII(board [][]int, visited [][]bool, path []int, empty, start
return
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md b/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md
index a598ed75..4b5c51ff 100755
--- a/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md
+++ b/website/content/ChapterFour/0981.Time-Based-Key-Value-Store.md
@@ -121,4 +121,11 @@ func (t TimeMap) Get(key string, timestamp int) string {
* param_2 := obj.Get(key,timestamp);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md b/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md
index cccb67b2..f8f8a7fb 100755
--- a/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md
+++ b/website/content/ChapterFour/0984.String-Without-AAA-or-BBB.md
@@ -90,4 +90,11 @@ func strWithout3a3b(A int, B int) string {
return ans
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md b/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md
index 8811079b..53918c0e 100644
--- a/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md
+++ b/website/content/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md
@@ -69,4 +69,11 @@ func sumEvenAfterQueries(A []int, queries [][]int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0986.Interval-List-Intersections.md b/website/content/ChapterFour/0986.Interval-List-Intersections.md
index d1a46341..cd2ef563 100644
--- a/website/content/ChapterFour/0986.Interval-List-Intersections.md
+++ b/website/content/ChapterFour/0986.Interval-List-Intersections.md
@@ -70,4 +70,11 @@ func intervalIntersection(A []Interval, B []Interval) []Interval {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md b/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md
index 75f33db2..efe57ddf 100755
--- a/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md
+++ b/website/content/ChapterFour/0990.Satisfiability-of-Equality-Equations.md
@@ -96,4 +96,11 @@ func equationsPossible(equations []string) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md b/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md
index 33155fa2..642f19c2 100644
--- a/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md
+++ b/website/content/ChapterFour/0992.Subarrays-with-K-Different-Integers.md
@@ -110,4 +110,11 @@ func subarraysWithKDistinctSlideWindow(A []int, K int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md b/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md
index 1fd4a366..4579f7bd 100755
--- a/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md
+++ b/website/content/ChapterFour/0993.Cousins-in-Binary-Tree.md
@@ -160,4 +160,11 @@ func dfsCousins(root *TreeNode, val, depth, last int, parent, res *int) {
dfsCousins(root.Right, val, depth, root.Val, parent, res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md b/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md
index 768d37be..3227e1d8 100755
--- a/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md
+++ b/website/content/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md
@@ -94,4 +94,11 @@ func minKBitFlips(A []int, K int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md b/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md
index 5a420a2c..270b4cb0 100755
--- a/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md
+++ b/website/content/ChapterFour/0996.Number-of-Squareful-Arrays.md
@@ -104,4 +104,11 @@ func checkSquare(num int) bool {
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/0999.Available-Captures-for-Rook.md b/website/content/ChapterFour/0999.Available-Captures-for-Rook.md
index 47e6d127..7253b6c1 100644
--- a/website/content/ChapterFour/0999.Available-Captures-for-Rook.md
+++ b/website/content/ChapterFour/0999.Available-Captures-for-Rook.md
@@ -96,4 +96,11 @@ func caputure(board [][]byte, x, y int, bx, by int) int {
return 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1002.Find-Common-Characters.md b/website/content/ChapterFour/1002.Find-Common-Characters.md
index 9b61e205..93b72aa6 100755
--- a/website/content/ChapterFour/1002.Find-Common-Characters.md
+++ b/website/content/ChapterFour/1002.Find-Common-Characters.md
@@ -71,4 +71,11 @@ func commonChars(A []string) []string {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md b/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md
index b423f1dc..2c4ec6b3 100644
--- a/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md
+++ b/website/content/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md
@@ -104,4 +104,11 @@ func isValid1003(S string) bool {
return len(stack) == 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md b/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md
index ba6eb873..54a10366 100644
--- a/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md
+++ b/website/content/ChapterFour/1004.Max-Consecutive-Ones-III.md
@@ -77,4 +77,11 @@ func longestOnes(A []int, K int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md b/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md
index 1293b74f..cfa94c28 100644
--- a/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md
+++ b/website/content/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md
@@ -80,4 +80,11 @@ func largestSumAfterKNegations(A []int, K int) int {
return sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md b/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md
index 774c53d1..5db2dec8 100755
--- a/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md
+++ b/website/content/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md
@@ -98,4 +98,11 @@ func shipWithinDays(weights []int, D int) int {
return low
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1017.Convert-to-Base--2.md b/website/content/ChapterFour/1017.Convert-to-Base--2.md
index 77eec60f..26516464 100755
--- a/website/content/ChapterFour/1017.Convert-to-Base--2.md
+++ b/website/content/ChapterFour/1017.Convert-to-Base--2.md
@@ -72,4 +72,11 @@ func baseNeg2(N int) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1018.Binary-Prefix-Divisible-By-5.md b/website/content/ChapterFour/1018.Binary-Prefix-Divisible-By-5.md
new file mode 100644
index 00000000..98109b82
--- /dev/null
+++ b/website/content/ChapterFour/1018.Binary-Prefix-Divisible-By-5.md
@@ -0,0 +1,77 @@
+# [1018. Binary Prefix Divisible By 5](https://leetcode.com/problems/binary-prefix-divisible-by-5/)
+
+
+## 题目
+
+Given an array `A` of `0`s and `1`s, consider `N_i`: the i-th subarray from `A[0]` to `A[i]` interpreted as a binary number (from most-significant-bit to least-significant-bit.)
+
+Return a list of booleans `answer`, where `answer[i]` is `true` if and only if `N_i` is divisible by 5.
+
+**Example 1**:
+
+```
+Input: [0,1,1]
+Output: [true,false,false]
+Explanation:
+The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. Only the first number is divisible by 5, so answer[0] is true.
+
+```
+
+**Example 2**:
+
+```
+Input: [1,1,1]
+Output: [false,false,false]
+
+```
+
+**Example 3**:
+
+```
+Input: [0,1,1,1,1,1]
+Output: [true,false,false,false,true,false]
+
+```
+
+**Example 4**:
+
+```
+Input: [1,1,1,0,1]
+Output: [false,false,false,false,false]
+
+```
+
+**Note**:
+
+1. `1 <= A.length <= 30000`
+2. `A[i]` is `0` or `1`
+
+## 题目大意
+
+给定由若干 0 和 1 组成的数组 A。我们定义 N_i:从 A[0] 到 A[i] 的第 i 个子数组被解释为一个二进制数(从最高有效位到最低有效位)。返回布尔值列表 answer,只有当 N_i 可以被 5 整除时,答案 answer[i] 为 true,否则为 false。
+
+## 解题思路
+
+- 简单题。每扫描数组中的一个数字,累计转换成二进制数对 5 取余,如果余数为 0,则存入 true,否则存入 false。
+
+## 代码
+
+```go
+package leetcode
+
+func prefixesDivBy5(a []int) []bool {
+ res, num := make([]bool, len(a)), 0
+ for i, v := range a {
+ num = (num<<1 | v) % 5
+ res[i] = num == 0
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md b/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md
index 944ca8e3..82843023 100644
--- a/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md
+++ b/website/content/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md
@@ -93,4 +93,11 @@ func nextLargerNodes(head *ListNode) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1020.Number-of-Enclaves.md b/website/content/ChapterFour/1020.Number-of-Enclaves.md
index 34b72b3d..b125cd5d 100644
--- a/website/content/ChapterFour/1020.Number-of-Enclaves.md
+++ b/website/content/ChapterFour/1020.Number-of-Enclaves.md
@@ -90,4 +90,11 @@ func dfsNumEnclaves(A [][]int, x, y int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md b/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md
index d43d1b22..3bc01ab3 100644
--- a/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md
+++ b/website/content/ChapterFour/1021.Remove-Outermost-Parentheses.md
@@ -120,4 +120,11 @@ func removeOuterParentheses1(S string) string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1025.Divisor-Game.md b/website/content/ChapterFour/1025.Divisor-Game.md
index e6a45211..34dcdfe2 100755
--- a/website/content/ChapterFour/1025.Divisor-Game.md
+++ b/website/content/ChapterFour/1025.Divisor-Game.md
@@ -59,4 +59,11 @@ func divisorGame(N int) bool {
return N%2 == 0
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md b/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md
index b2c94617..6d75cc21 100644
--- a/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md
+++ b/website/content/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md
@@ -71,4 +71,11 @@ func dfsAncestorDiff(root *TreeNode, res *int) (int, int) {
*res = max(*res, max(abs(root.Val-min(leftMin, rightMin)), abs(root.Val-max(leftMax, rightMax))))
return max(leftMax, max(rightMax, root.Val)), min(leftMin, min(rightMin, root.Val))
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md b/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md
index f9c25238..01210afb 100755
--- a/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md
+++ b/website/content/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md
@@ -132,4 +132,11 @@ func dfsBuildPreorderTree(S string, index, level *int, cur *TreeNode) (newIndex
return index
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md b/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md
index ba60ec4d..62a940fb 100755
--- a/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md
+++ b/website/content/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md
@@ -81,4 +81,11 @@ func allCellsDistOrder(R int, C int, r0 int, c0 int) [][]int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1037.Valid-Boomerang.md b/website/content/ChapterFour/1037.Valid-Boomerang.md
index 89a4000d..3dc1b94c 100644
--- a/website/content/ChapterFour/1037.Valid-Boomerang.md
+++ b/website/content/ChapterFour/1037.Valid-Boomerang.md
@@ -46,4 +46,11 @@ func isBoomerang(points [][]int) bool {
return (points[0][0]-points[1][0])*(points[0][1]-points[2][1]) != (points[0][0]-points[2][0])*(points[0][1]-points[1][1])
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md b/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md
index 9c41121e..d611c135 100755
--- a/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md
+++ b/website/content/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md
@@ -118,4 +118,11 @@ func numMovesStonesII(stones []int) []int {
return []int{minStep, maxStep}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md b/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md
index 1166355f..1fd0cb3a 100644
--- a/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md
+++ b/website/content/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md
@@ -54,4 +54,11 @@ func removeDuplicates1047(S string) string {
return string(stack)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1049.Last-Stone-Weight-II.md b/website/content/ChapterFour/1049.Last-Stone-Weight-II.md
index 4159bb50..035a6afc 100755
--- a/website/content/ChapterFour/1049.Last-Stone-Weight-II.md
+++ b/website/content/ChapterFour/1049.Last-Stone-Weight-II.md
@@ -76,4 +76,11 @@ func lastStoneWeightII(stones []int) int {
return sum - 2*dp[C]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1051.Height-Checker.md b/website/content/ChapterFour/1051.Height-Checker.md
index 10653f21..6fecbda0 100644
--- a/website/content/ChapterFour/1051.Height-Checker.md
+++ b/website/content/ChapterFour/1051.Height-Checker.md
@@ -69,4 +69,11 @@ func heightChecker(heights []int) int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md b/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md
index b63f9479..40805ff8 100755
--- a/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md
+++ b/website/content/ChapterFour/1052.Grumpy-Bookstore-Owner.md
@@ -103,4 +103,11 @@ func sumSatisfied(customers []int, grumpy []int, start, end int) int {
return sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1054.Distant-Barcodes.md b/website/content/ChapterFour/1054.Distant-Barcodes.md
index 522c4e83..e9322c19 100755
--- a/website/content/ChapterFour/1054.Distant-Barcodes.md
+++ b/website/content/ChapterFour/1054.Distant-Barcodes.md
@@ -89,4 +89,11 @@ func barcodesFrequencySort(s []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md b/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md
index b8380b33..dbbdc84a 100755
--- a/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md
+++ b/website/content/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md
@@ -143,4 +143,11 @@ func intToNegabinary(num int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md b/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md
index a9a66a85..796e1700 100755
--- a/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md
+++ b/website/content/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md
@@ -53,8 +53,9 @@ Two submatrices `(x1, y1, x2, y2)` and `(x1', y1', x2', y2')` are different
- 给出一个矩阵,要求在这个矩阵中找出子矩阵的和等于 target 的矩阵个数。
- 这一题读完题感觉是滑动窗口的二维版本。如果把它拍扁,在一维数组中,求连续的子数组和为 target,这样就很好做。如果这题不降维,纯暴力解是 O(n^6)。如何优化降低时间复杂度呢?
- 联想到第 1 题 Two Sum 问题,可以把 2 个数求和的问题优化到 O(n)。这里也用类似的思想,用一个 map 来保存行方向上曾经出现过的累加和,相减就可以得到本行的和。这里可能读者会有疑惑,为什么不能每一行都单独保存呢?为什么一定要用累加和相减的方式来获取每一行的和呢?因为这一题要求子矩阵所有解,如果只单独保存每一行的和,只能求得小的子矩阵,子矩阵和子矩阵组成的大矩阵的情况会漏掉(当然再循环一遍,把子矩阵累加起来也可以,但是这样就多了一层循环了),例如子矩阵是 1*4 的,但是 2 个这样的子矩阵摞在一起形成 2 * 4 也能满足条件,如果不用累加和的办法,只单独存每一行的和,最终还要有组合的步骤。经过这样的优化,可以从 O(n^6) 优化到 O(n^4),能 AC 这道题,但是时间复杂度太高了。如何优化?
-- 首先,子矩阵需要上下左右 4 个边界,4 个变量控制循环就需要 O(n^4),行和列的区间累加还需要 O(n^2)。行和列的区间累加可以通过 preSum 来解决。例如 `sum[i,j] = sum[j] - sum[i - 1]`,其中 sum[k] 中存的是从 0 到 K 的累加和: 
-
+- 首先,子矩阵需要上下左右 4 个边界,4 个变量控制循环就需要 O(n^4),行和列的区间累加还需要 O(n^2)。行和列的区间累加可以通过 preSum 来解决。例如 `sum[i,j] = sum[j] - sum[i - 1]`,其中 sum[k] 中存的是从 0 到 K 的累加和: {{< katex display >}}
+\sum_{0}^{k} matrix[i]
+{{< /katex >}}
那么一个区间内的累加和可以由这个区间的右边界减去区间左边界左边的那个累加和得到(由于是闭区间,所需要取左边界左边的和)。经过这样的处理,列方向的维度就被我们拍扁了。
- 再来看看行方向的和,现在每一列的和都可以通过区间相减的方法得到。那么这道题就变成了第 1 题 Two Sum 的问题了。Two Sum 问题只需要 O(n) 的时间复杂度求解,这一题由于是二维的,所以两个列的边界还需要循环,所以最终优化下来的时间复杂度是 O(n^3)。计算 presum 可以直接用原数组,所以空间复杂度只有一个 O(n) 的字典。
@@ -140,4 +141,11 @@ func sumSubmatrix(matrix [][]int, startx, starty, endx, endy int) int {
return sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1078.Occurrences-After-Bigram.md b/website/content/ChapterFour/1078.Occurrences-After-Bigram.md
index 6d1806e0..37333250 100755
--- a/website/content/ChapterFour/1078.Occurrences-After-Bigram.md
+++ b/website/content/ChapterFour/1078.Occurrences-After-Bigram.md
@@ -61,4 +61,11 @@ func findOcurrences(text string, first string, second string) []string {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1079.Letter-Tile-Possibilities.md b/website/content/ChapterFour/1079.Letter-Tile-Possibilities.md
index 41a7ecfa..2dc6dd6a 100755
--- a/website/content/ChapterFour/1079.Letter-Tile-Possibilities.md
+++ b/website/content/ChapterFour/1079.Letter-Tile-Possibilities.md
@@ -33,7 +33,8 @@ You have a set of `tiles`, where each tile has one letter `tiles[i]` printed
- 题目要求输出所有非空字母序列的数目。这一题是排列和组合的结合题目。组合是可以选择一个字母,二个字母,…… n 个字母。每个组合内是排列问题。比如选择 2 个字母,字母之间相互排序不同是影响最终结果的,不同的排列顺序是不同的解。
- 这道题目由于不需要输出所有解,所以解法可以优化,例如我们在递归计算解的时候,不需要真的遍历原字符串,只需要累加一些字母的频次就可以。当然如果要输出所有解,就需要真实遍历原字符串了(见解法二)。简单的做法是每次递归按照频次累加。因为每次增加一个字母一定是 26 个大写字母中的一个。这里需要注意的是,增加的只能是 26 个字母里面还能取出“机会”的字母,例如递归到到第 3 轮了,A 用完了,这个时候只能取频次还不为 0 的字母拼上去。
-
+
+
## 代码
@@ -103,4 +104,11 @@ func findTile(tiles, tmp []byte, used *[]bool, index int, res *int, tMap map[str
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1089.Duplicate-Zeros.md b/website/content/ChapterFour/1089.Duplicate-Zeros.md
index 3c822474..a124e966 100644
--- a/website/content/ChapterFour/1089.Duplicate-Zeros.md
+++ b/website/content/ChapterFour/1089.Duplicate-Zeros.md
@@ -55,4 +55,11 @@ func duplicateZeros(arr []int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md b/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md
index 7ebf2a32..863f1f81 100755
--- a/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md
+++ b/website/content/ChapterFour/1093.Statistics-from-a-Large-Sample.md
@@ -22,7 +22,7 @@ Return the minimum, maximum, mean, median, and mode of the sample respectively,
Input: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Output: [1.00000,4.00000,2.18182,2.00000,1.00000]
-**Constraints:**
+**Constraints**:
1. `count.length == 256`
2. `1 <= sum(count) <= 10^9`
@@ -92,4 +92,11 @@ func sampleStats(count []int) []float64 {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md b/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md
index 5c248f89..e2c256c7 100755
--- a/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md
+++ b/website/content/ChapterFour/1105.Filling-Bookcase-Shelves.md
@@ -23,7 +23,7 @@ Return the minimum possible height that the total bookshelf can be after placing
The sum of the heights of the 3 shelves are 1 + 3 + 2 = 6.
Notice that book number 2 does not have to be on the first shelf.
-**Constraints:**
+**Constraints**:
- `1 <= books.length <= 1000`
- `1 <= books[i][0] <= shelf_width <= 1000`
@@ -65,4 +65,11 @@ func minHeightShelves(books [][]int, shelfWidth int) int {
return dp[len(books)]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1108.Defanging-an-IP-Address.md b/website/content/ChapterFour/1108.Defanging-an-IP-Address.md
index 0eb4a7f9..f745e3bd 100755
--- a/website/content/ChapterFour/1108.Defanging-an-IP-Address.md
+++ b/website/content/ChapterFour/1108.Defanging-an-IP-Address.md
@@ -17,7 +17,7 @@ A *defanged IP address* replaces every period `"."` with `"[.]"`.
Input: address = "255.100.50.0"
Output: "255[.]100[.]50[.]0"
-**Constraints:**
+**Constraints**:
- The given `address` is a valid IPv4 address.
@@ -51,4 +51,11 @@ func defangIPaddr(address string) string {
return strings.Replace(address, ".", "[.]", -1)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md b/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md
index 9d3c214c..971b3e1b 100644
--- a/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md
+++ b/website/content/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md
@@ -79,4 +79,11 @@ func dfsDelNodes(root *TreeNode, toDel map[int]bool, isRoot bool, res *[]*TreeNo
}
return isRoot
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md b/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md
index 8f4d8f59..bc6d761b 100755
--- a/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md
+++ b/website/content/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md
@@ -33,7 +33,7 @@ Return an `answer` array (of length `seq.length`) that encodes such a choice
Input: seq = "()(())()"
Output: [0,0,0,1,1,0,1,1]
-**Constraints:**
+**Constraints**:
- `1 <= seq.size <= 10000`
@@ -129,4 +129,11 @@ func maxDepthAfterSplit1(seq string) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1122.Relative-Sort-Array.md b/website/content/ChapterFour/1122.Relative-Sort-Array.md
index 7a536881..3ce06048 100755
--- a/website/content/ChapterFour/1122.Relative-Sort-Array.md
+++ b/website/content/ChapterFour/1122.Relative-Sort-Array.md
@@ -12,7 +12,7 @@ Sort the elements of `arr1` such that the relative ordering of items in `arr1
Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
Output: [2,2,2,1,4,3,3,9,6,7,19]
-**Constraints:**
+**Constraints**:
- `arr1.length, arr2.length <= 1000`
- `0 <= arr1[i], arr2[i] <= 1000`
@@ -98,4 +98,11 @@ func relativeSortArray1(arr1 []int, arr2 []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md b/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md
index f2838c9d..f3fb3dee 100755
--- a/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md
+++ b/website/content/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md
@@ -30,7 +30,7 @@ Recall that:
Input: root = [1,2,3,4,5]
Output: [2,4,5]
-**Constraints:**
+**Constraints**:
- The given tree will have between 1 and 1000 nodes.
- Each node of the tree will have a distinct value between 1 and 1000.
@@ -45,7 +45,7 @@ Recall that:
- 叶节点 是二叉树中没有子节点的节点
- 树的根节点的 深度 为 0,如果某一节点的深度为 d,那它的子节点的深度就是 d+1
-- 如果我们假定 A 是一组节点 S 的 最近公共祖先,S 中的每个节点都在以 A 为根节点的子树中,且 A 的深度达到此条件下可能的最大值。
+- 如果我们假定 A 是一组节点 S 的 最近公共祖先,S 中的每个节点都在以 A 为根节点的子树中,且 A 的深度达到此条件下可能的最大值。
提示:
@@ -98,4 +98,11 @@ func lcaDeepestLeavesDFS(lca **TreeNode, maxLevel *int, depth int, root *TreeNod
return max(depthLeft, depthRight)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md b/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md
index cc946659..b9f94100 100755
--- a/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md
+++ b/website/content/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md
@@ -12,7 +12,7 @@ Return the number of pairs `(i, j)` for which `0 <= i < j < dominoes.length`,
Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
Output: 1
-**Constraints:**
+**Constraints**:
- `1 <= dominoes.length <= 40000`
- `1 <= dominoes[i][j] <= 9`
@@ -65,4 +65,11 @@ func numEquivDominoPairs(dominoes [][]int) int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md b/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md
index f897528d..211d5ba6 100755
--- a/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md
+++ b/website/content/ChapterFour/1137.N-th-Tribonacci-Number.md
@@ -22,7 +22,7 @@ Given `n`, return the value of Tn.
Input: n = 25
Output: 1389537
-**Constraints:**
+**Constraints**:
- `0 <= n <= 37`
- The answer is guaranteed to fit within a 32-bit integer, ie. `answer <= 2^31 - 1`.
@@ -68,4 +68,11 @@ func tribonacci(n int) int {
return trib
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md b/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md
index 02fbc682..c1395df1 100644
--- a/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md
+++ b/website/content/ChapterFour/1145.Binary-Tree-Coloring-Game.md
@@ -79,4 +79,11 @@ func dfsBtreeGameWinningMove(node *TreeNode, left, right *int, x int) int {
}
return l + r + 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1154.Day-of-the-Year.md b/website/content/ChapterFour/1154.Day-of-the-Year.md
index 6b1bc846..b4c4bcb2 100755
--- a/website/content/ChapterFour/1154.Day-of-the-Year.md
+++ b/website/content/ChapterFour/1154.Day-of-the-Year.md
@@ -26,7 +26,7 @@ Given a string `date` representing a [Gregorian calendar](https://en.wikiped
Input: date = "2004-03-01"
Output: 61
-**Constraints:**
+**Constraints**:
- `date.length == 10`
- `date[4] == date[7] == '-'`, and all other `date[i]`'s are digits
@@ -78,4 +78,11 @@ func dayOfYear(date string) int {
return int(duration.Hours())/24 + 1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md b/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md
index ac7d539b..abfafc03 100755
--- a/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md
+++ b/website/content/ChapterFour/1157.Online-Majority-Element-In-Subarray.md
@@ -19,7 +19,7 @@ Each `query(...)` returns the element in `arr[left], arr[left+1], ..., arr[ri
majorityChecker.query(0,3,3); // returns -1
majorityChecker.query(2,3,2); // returns 2
-**Constraints:**
+**Constraints**:
- `1 <= arr.length <= 20000`
- `1 <= arr[i] <= 20000`
@@ -193,4 +193,11 @@ func (mc *MajorityChecker) Query(left int, right int, threshold int) int {
* param_1 := obj.Query(left,right,threshold);
*/
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md b/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md
index 5a73172d..2df6a209 100755
--- a/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md
+++ b/website/content/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md
@@ -78,4 +78,11 @@ func canBeFormed(w string, c []int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md b/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md
index be6dfc0d..854c1e78 100755
--- a/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md
+++ b/website/content/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md
@@ -18,7 +18,7 @@ Now, given string arrays `queries` and `words`, return an integer array `ans
Output: [1,2]
Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
-**Constraints:**
+**Constraints**:
- `1 <= queries.length <= 2000`
- `1 <= words.length <= 2000`
@@ -83,4 +83,11 @@ func countFunc(s string) int {
return count[i]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md b/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md
index b71ad63b..bee3e8a8 100755
--- a/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md
+++ b/website/content/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md
@@ -25,7 +25,7 @@ After doing so, return the head of the final linked list. You may return any suc
Input: head = [1,2,3,-3,-2]
Output: [1]
-**Constraints:**
+**Constraints**:
- The given linked list will contain between `1` and `1000` nodes.
- Each node in the linked list has `-1000 <= node.val <= 1000`.
@@ -137,4 +137,11 @@ func removeZeroSumSublists1(head *ListNode) *ListNode {
return head
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1175.Prime-Arrangements.md b/website/content/ChapterFour/1175.Prime-Arrangements.md
index e5550e67..063a2619 100755
--- a/website/content/ChapterFour/1175.Prime-Arrangements.md
+++ b/website/content/ChapterFour/1175.Prime-Arrangements.md
@@ -20,7 +20,7 @@ Since the answer may be large, return the answer **modulo `10^9 + 7`**.
Input: n = 100
Output: 682289015
-**Constraints:**
+**Constraints**:
- `1 <= n <= 100`
@@ -62,4 +62,11 @@ func factorial(n int) int {
return n * factorial(n-1) % 1000000007
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md b/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md
index 4f5f6c64..5d23749e 100755
--- a/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md
+++ b/website/content/ChapterFour/1184.Distance-Between-Bus-Stops.md
@@ -32,7 +32,7 @@ Return the shortest distance between the given `start` and `destination` sto
Output: 4
Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.
-**Constraints:**
+**Constraints**:
- `1 <= n <= 10^4`
- `distance.length == n`
@@ -79,4 +79,11 @@ func distanceBetweenBusStops(distance []int, start int, destination int) int {
return counterclockwiseDis
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1185.Day-of-the-Week.md b/website/content/ChapterFour/1185.Day-of-the-Week.md
index 0eef0bcf..5b34b8de 100755
--- a/website/content/ChapterFour/1185.Day-of-the-Week.md
+++ b/website/content/ChapterFour/1185.Day-of-the-Week.md
@@ -24,7 +24,7 @@ Return the answer as one of the following values `{"Sunday", "Monday", "Tuesday
Input: day = 15, month = 8, year = 1993
Output: "Sunday"
-**Constraints:**
+**Constraints**:
- The given dates are valid dates between the years `1971` and `2100`.
@@ -58,4 +58,11 @@ func dayOfTheWeek(day int, month int, year int) string {
return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local).Weekday().String()
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md b/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md
index 9fdae875..ac27e5eb 100755
--- a/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md
+++ b/website/content/ChapterFour/1189.Maximum-Number-of-Balloons.md
@@ -26,7 +26,7 @@ You can use each character in `text` **at most once**. Return the maximum numb
Input: text = "leetcode"
Output: 0
-**Constraints:**
+**Constraints**:
- `1 <= text.length <= 10^4`
- `text` consists of lower case English letters only.
@@ -67,4 +67,11 @@ func maxNumberOfBalloons(text string) int {
return min(fre[1], min(fre[0], min(fre[11]/2, min(fre[14]/2, fre[13]))))
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md b/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md
index c52b7799..2cbf856b 100755
--- a/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md
+++ b/website/content/ChapterFour/1200.Minimum-Absolute-Difference.md
@@ -27,7 +27,7 @@ Return a list of pairs in ascending order(with respect to pairs), each pair `[a
Input: arr = [3,8,-10,23,19,-4,-14,27]
Output: [[-14,-10],[19,23],[23,27]]
-**Constraints:**
+**Constraints**:
- `2 <= arr.length <= 10^5`
- `-10^6 <= arr[i] <= 10^6`
@@ -74,4 +74,11 @@ func minimumAbsDifference(arr []int) [][]int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1201.Ugly-Number-III.md b/website/content/ChapterFour/1201.Ugly-Number-III.md
index 171ebe8b..9382712f 100755
--- a/website/content/ChapterFour/1201.Ugly-Number-III.md
+++ b/website/content/ChapterFour/1201.Ugly-Number-III.md
@@ -30,7 +30,7 @@ Ugly numbers are **positive integers** which are divisible by `a` **or** `b
Input: n = 1000000000, a = 2, b = 217983653, c = 336916467
Output: 1999999984
-**Constraints:**
+**Constraints**:
- `1 <= n, a, b, c <= 10^9`
- `1 <= a * b * c <= 10^18`
@@ -89,4 +89,11 @@ func gcd(a, b int64) int64 {
return a
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md b/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md
index 18527ba9..903771e8 100755
--- a/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md
+++ b/website/content/ChapterFour/1202.Smallest-String-With-Swaps.md
@@ -35,7 +35,7 @@ Return the lexicographically smallest string that `s` can be changed to after
Swap s[1] and s[2], s = "bac"
Swap s[0] and s[1], s = "abc"
-**Constraints:**
+**Constraints**:
- `1 <= s.length <= 10^5`
- `0 <= pairs.length <= 10^5`
@@ -99,4 +99,11 @@ func smallestStringWithSwaps(s string, pairs [][]int) string {
return string(res)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1203.Sort-Items-by-Groups-Respecting-Dependencies.md b/website/content/ChapterFour/1203.Sort-Items-by-Groups-Respecting-Dependencies.md
new file mode 100644
index 00000000..99193c75
--- /dev/null
+++ b/website/content/ChapterFour/1203.Sort-Items-by-Groups-Respecting-Dependencies.md
@@ -0,0 +1,198 @@
+# [1203. Sort Items by Groups Respecting Dependencies](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies/)
+
+
+## 题目
+
+There are `n` items each belonging to zero or one of `m` groups where `group[i]` is the group that the `i`-th item belongs to and it's equal to `-1` if the `i`-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.
+
+Return a sorted list of the items such that:
+
+- The items that belong to the same group are next to each other in the sorted list.
+- There are some relations between these items where `beforeItems[i]` is a list containing all the items that should come before the `i`th item in the sorted array (to the left of the `i`th item).
+
+Return any solution if there is more than one solution and return an **empty list** if there is no solution.
+
+**Example 1:**
+
+
+
+```
+Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]
+Output: [6,3,4,1,5,2,0,7]
+
+```
+
+**Example 2:**
+
+```
+Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]
+Output: []
+Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.
+
+```
+
+**Constraints:**
+
+- `1 <= m <= n <= 3 * 104`
+- `group.length == beforeItems.length == n`
+- `1 <= group[i] <= m - 1`
+- `0 <= beforeItems[i].length <= n - 1`
+- `0 <= beforeItems[i][j] <= n - 1`
+- `i != beforeItems[i][j]`
+- `beforeItems[i]` does not contain duplicates elements.
+
+## 题目大意
+
+有 n 个项目,每个项目或者不属于任何小组,或者属于 m 个小组之一。group[i] 表示第 i 个小组所属的小组,如果第 i 个项目不属于任何小组,则 group[i] 等于 -1。项目和小组都是从零开始编号的。可能存在小组不负责任何项目,即没有任何项目属于这个小组。
+
+请你帮忙按要求安排这些项目的进度,并返回排序后的项目列表:
+
+- 同一小组的项目,排序后在列表中彼此相邻。
+- 项目之间存在一定的依赖关系,我们用一个列表 beforeItems 来表示,其中 beforeItems[i] 表示在进行第 i 个项目前(位于第 i 个项目左侧)应该完成的所有项目。
+
+如果存在多个解决方案,只需要返回其中任意一个即可。如果没有合适的解决方案,就请返回一个 空列表 。
+
+## 解题思路
+
+- 读完题能确定这一题是拓扑排序。但是和单纯的拓扑排序有区别的是,同一小组内的项目需要彼此相邻。用 2 次拓扑排序即可解决。第一次拓扑排序排出组间的顺序,第二次拓扑排序排出组内的顺序。为了实现方便,用 map 给虚拟分组标记编号。如下图,将 3,4,6 三个任务打包到 0 号分组里面,将 2,5 两个任务打包到 1 号分组里面,其他任务单独各自为一组。组间的依赖是 6 号任务依赖 1 号任务。由于 6 号任务封装在 0 号分组里,所以 3 号分组依赖 0 号分组。先组间排序,确定分组顺序,再组内拓扑排序,排出最终顺序。
+
+ 
+
+- 上面的解法可以 AC,但是时间太慢了。因为做了一些不必要的操作。有没有可能只用一次拓扑排序呢?将必须要在一起的结点统一依赖一个虚拟结点,例如下图中的虚拟结点 8 和 9 。3,4,6 都依赖 8 号任务,2 和 5 都依赖 9 号任务。1 号任务本来依赖 6 号任务,由于 6 由依赖 8 ,所以添加 1 依赖 8 的边。通过增加虚拟结点,增加了需要打包在一起结点的入度。构建出以上关系以后,按照入度为 0 的原则,依次进行 DFS。8 号和 9 号两个虚拟结点的入度都为 0 ,对它们进行 DFS,必定会使得与它关联的节点都被安排在一起,这样就满足了题意:同一小组的项目,排序后在列表中彼此相邻。一遍扫完,满足题意的顺序就排出来了。这个解法 beat 100%!
+
+ 
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 拓扑排序版的 DFS
+func sortItems(n int, m int, group []int, beforeItems [][]int) []int {
+ groups, inDegrees := make([][]int, n+m), make([]int, n+m)
+ for i, g := range group {
+ if g > -1 {
+ g += n
+ groups[g] = append(groups[g], i)
+ inDegrees[i]++
+ }
+ }
+ for i, ancestors := range beforeItems {
+ gi := group[i]
+ if gi == -1 {
+ gi = i
+ } else {
+ gi += n
+ }
+ for _, ancestor := range ancestors {
+ ga := group[ancestor]
+ if ga == -1 {
+ ga = ancestor
+ } else {
+ ga += n
+ }
+ if gi == ga {
+ groups[ancestor] = append(groups[ancestor], i)
+ inDegrees[i]++
+ } else {
+ groups[ga] = append(groups[ga], gi)
+ inDegrees[gi]++
+ }
+ }
+ }
+ res := []int{}
+ for i, d := range inDegrees {
+ if d == 0 {
+ sortItemsDFS(i, n, &res, &inDegrees, &groups)
+ }
+ }
+ if len(res) != n {
+ return nil
+ }
+ return res
+}
+
+func sortItemsDFS(i, n int, res, inDegrees *[]int, groups *[][]int) {
+ if i < n {
+ *res = append(*res, i)
+ }
+ (*inDegrees)[i] = -1
+ for _, ch := range (*groups)[i] {
+ if (*inDegrees)[ch]--; (*inDegrees)[ch] == 0 {
+ sortItemsDFS(ch, n, res, inDegrees, groups)
+ }
+ }
+}
+
+// 解法二 二维拓扑排序 时间复杂度 O(m+n),空间复杂度 O(m+n)
+func sortItems1(n int, m int, group []int, beforeItems [][]int) []int {
+ groupItems, res := map[int][]int{}, []int{}
+ for i := 0; i < len(group); i++ {
+ if group[i] == -1 {
+ group[i] = m + i
+ }
+ groupItems[group[i]] = append(groupItems[group[i]], i)
+ }
+ groupGraph, groupDegree, itemGraph, itemDegree := make([][]int, m+n), make([]int, m+n), make([][]int, n), make([]int, n)
+ for i := 0; i < len(beforeItems); i++ {
+ for j := 0; j < len(beforeItems[i]); j++ {
+ if group[beforeItems[i][j]] != group[i] {
+ // 不同组项目,确定组间依赖关系
+ groupGraph[group[beforeItems[i][j]]] = append(groupGraph[group[beforeItems[i][j]]], group[i])
+ groupDegree[group[i]]++
+ } else {
+ // 同组项目,确定组内依赖关系
+ itemGraph[beforeItems[i][j]] = append(itemGraph[beforeItems[i][j]], i)
+ itemDegree[i]++
+ }
+ }
+ }
+ items := []int{}
+ for i := 0; i < m+n; i++ {
+ items = append(items, i)
+ }
+ // 组间拓扑
+ groupOrders := topSort(groupGraph, groupDegree, items)
+ if len(groupOrders) < len(items) {
+ return nil
+ }
+ for i := 0; i < len(groupOrders); i++ {
+ items := groupItems[groupOrders[i]]
+ // 组内拓扑
+ orders := topSort(itemGraph, itemDegree, items)
+ if len(orders) < len(items) {
+ return nil
+ }
+ res = append(res, orders...)
+ }
+ return res
+}
+
+func topSort(graph [][]int, deg, items []int) (orders []int) {
+ q := []int{}
+ for _, i := range items {
+ if deg[i] == 0 {
+ q = append(q, i)
+ }
+ }
+ for len(q) > 0 {
+ from := q[0]
+ q = q[1:]
+ orders = append(orders, from)
+ for _, to := range graph[from] {
+ deg[to]--
+ if deg[to] == 0 {
+ q = append(q, to)
+ }
+ }
+ }
+ return
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md b/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md
index 43e3c6f8..1b3aff67 100755
--- a/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md
+++ b/website/content/ChapterFour/1207.Unique-Number-of-Occurrences.md
@@ -21,7 +21,7 @@ Given an array of integers `arr`, write a function that returns `true` if an
Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
Output: true
-**Constraints:**
+**Constraints**:
- `1 <= arr.length <= 1000`
- `-1000 <= arr[i] <= 1000`
@@ -65,4 +65,11 @@ func uniqueOccurrences(arr []int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md b/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md
index 5d0474f5..92c91739 100755
--- a/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md
+++ b/website/content/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md
@@ -29,7 +29,7 @@ If there is no substring from `s` that can be changed to its corresponding sub
Output: 1
Explanation: You can't make any change, so the maximum length is 1.
-**Constraints:**
+**Constraints**:
- `1 <= s.length, t.length <= 10^5`
- `0 <= maxCost <= 10^6`
@@ -74,4 +74,11 @@ func equalSubstring(s string, t string, maxCost int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1217.Play-with-Chips.md b/website/content/ChapterFour/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position.md
similarity index 83%
rename from website/content/ChapterFour/1217.Play-with-Chips.md
rename to website/content/ChapterFour/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position.md
index 29eec710..d1b1cda2 100755
--- a/website/content/ChapterFour/1217.Play-with-Chips.md
+++ b/website/content/ChapterFour/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position.md
@@ -1,4 +1,4 @@
-# [1217. Play with Chips](https://leetcode.com/problems/play-with-chips/)
+# [1217. Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/)
## 题目
@@ -26,7 +26,7 @@ Return the minimum cost needed to move all the chips to the same position (any
Output: 2
Explanation: Both fourth and fifth chip will be moved to position two with cost 1. Total minimum cost will be 2.
-**Constraints:**
+**Constraints**:
- `1 <= chips.length <= 100`
- `1 <= chips[i] <= 10^9`
@@ -73,4 +73,11 @@ func minCostToMoveChips(chips []int) int {
return min(odd, even)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md b/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md
index 5a50681b..4111287f 100755
--- a/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md
+++ b/website/content/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md
@@ -27,7 +27,7 @@ Return the maximum amount of splitted balanced strings.
Output: 1
Explanation: s can be split into "LLLLRRRR".
-**Constraints:**
+**Constraints**:
- `1 <= s.length <= 1000`
- `s[i] = 'L' or 'R'`
@@ -70,4 +70,11 @@ func balancedStringSplit(s string) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md b/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md
index a6bdd744..3d4fc4cb 100755
--- a/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md
+++ b/website/content/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md
@@ -20,7 +20,7 @@ You are given an array `coordinates`, `coordinates[i] = [x, y]`, where `[x, y
Input: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
Output: false
-**Constraints:**
+**Constraints**:
- `2 <= coordinates.length <= 1000`
- `coordinates[i].length == 2`
@@ -68,4 +68,11 @@ func checkStraightLine(coordinates [][]int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md b/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md
index f5584b74..8404def8 100755
--- a/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md
+++ b/website/content/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md
@@ -35,7 +35,7 @@ Return 0 if the string is already **balanced**.
Output: 3
Explanation: We can replace the last 3 'Q' to make s = "QWER".
-**Constraints:**
+**Constraints**:
- `1 <= s.length <= 10^5`
- `s.length` is a multiple of `4`
@@ -90,4 +90,11 @@ func balancedString(s string) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md b/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md
index 915b5433..831aceef 100755
--- a/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md
+++ b/website/content/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md
@@ -34,7 +34,7 @@ If you choose a job that ends at time `X` you will be able to start another j
Input: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]
Output: 6
-**Constraints:**
+**Constraints**:
- `1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4`
- `1 <= startTime[i] < endTime[i] <= 10^9`
@@ -115,4 +115,11 @@ func (s sortJobs) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md b/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md
index 14db287a..6f869e52 100755
--- a/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md
+++ b/website/content/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md
@@ -25,7 +25,7 @@ Return *the number of cells with odd values* in the matrix after applying the
Output: 0
Explanation: Final matrix = [[2,2],[2,2]]. There is no odd number in the final matrix.
-**Constraints:**
+**Constraints**:
- `1 <= n <= 50`
- `1 <= m <= 50`
@@ -100,4 +100,11 @@ func oddCells1(n int, m int, indices [][]int) int {
return count
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1254.Number-of-Closed-Islands.md b/website/content/ChapterFour/1254.Number-of-Closed-Islands.md
index 3ff8da1a..bdcdec52 100755
--- a/website/content/ChapterFour/1254.Number-of-Closed-Islands.md
+++ b/website/content/ChapterFour/1254.Number-of-Closed-Islands.md
@@ -107,4 +107,11 @@ func isIntInBoard(board [][]int, x, y int) bool {
return x >= 0 && x < len(board) && y >= 0 && y < len(board[0])
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1260.Shift-2D-Grid.md b/website/content/ChapterFour/1260.Shift-2D-Grid.md
index a63d3e77..8a10aef5 100644
--- a/website/content/ChapterFour/1260.Shift-2D-Grid.md
+++ b/website/content/ChapterFour/1260.Shift-2D-Grid.md
@@ -87,4 +87,11 @@ func shiftGrid(grid [][]int, k int) [][]int {
return newGrid
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md b/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md
index 5fe48f07..3e9ad63d 100755
--- a/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md
+++ b/website/content/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md
@@ -26,7 +26,7 @@ You can move according to the next rules:
Input: points = [[3,2],[-2,2]]
Output: 5
-**Constraints:**
+**Constraints**:
- `points.length == n`
- `1 <= n <= 100`
@@ -72,4 +72,11 @@ func minTimeToVisitAllPoints(points [][]int) int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md b/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md
index d019be1c..92f05952 100644
--- a/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md
+++ b/website/content/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md
@@ -68,7 +68,7 @@ Explanation: The game has not finished yet.
```
-**Constraints:**
+**Constraints**:
- `1 <= moves.length <= 9`
- `moves[i].length == 2`
@@ -151,4 +151,11 @@ func tictactoe(moves [][]int) string {
return "Draw"
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md b/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md
index 96cc347d..2c964c08 100644
--- a/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md
+++ b/website/content/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md
@@ -56,4 +56,11 @@ func subtractProductAndSum(n int) int {
}
return product - sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md b/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md
index f0359723..e25c1209 100644
--- a/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md
+++ b/website/content/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md
@@ -84,4 +84,11 @@ func calDivisor(nums []int, mid, threshold int) bool {
}
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md b/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md
index f9714a4d..c1c9d669 100644
--- a/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md
+++ b/website/content/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md
@@ -46,4 +46,11 @@ func findSpecialInteger(arr []int) int {
}
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md b/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md
index 1c0f9be1..28ab0065 100644
--- a/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md
+++ b/website/content/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md
@@ -78,4 +78,11 @@ func getDecimalValue(head *ListNode) int {
}
return sum
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md b/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md
index ccaa6c49..32096cd1 100644
--- a/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md
+++ b/website/content/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md
@@ -60,4 +60,11 @@ func findNumbers(nums []int) int {
}
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md b/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md
index 633c6576..fb242b8f 100644
--- a/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md
+++ b/website/content/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md
@@ -48,4 +48,11 @@ func replaceElements(arr []int) []int {
}
return arr
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1300.Sum-of-Mutated-Array-Closest-to-Target.md b/website/content/ChapterFour/1300.Sum-of-Mutated-Array-Closest-to-Target.md
index dcee2bcd..113f3d86 100644
--- a/website/content/ChapterFour/1300.Sum-of-Mutated-Array-Closest-to-Target.md
+++ b/website/content/ChapterFour/1300.Sum-of-Mutated-Array-Closest-to-Target.md
@@ -57,6 +57,7 @@ Output: 11361
## 代码
```go
+
func findBestValue(arr []int, target int) int {
low, high := 0, 100000
for low < high {
@@ -67,6 +68,15 @@ func findBestValue(arr []int, target int) int {
high = mid
}
}
+ if high == 100000 {
+ res := 0
+ for _, num := range arr {
+ if res < num {
+ res = num
+ }
+ }
+ return res
+ }
// 比较阈值线分别定在 left - 1 和 left 的时候与 target 的接近程度
sum1, sum2 := calculateSum(arr, low-1), calculateSum(arr, low)
if target-sum1 <= sum2-target {
@@ -82,4 +92,19 @@ func calculateSum(arr []int, mid int) int {
}
return sum
}
-```
\ No newline at end of file
+
+func min(a int, b int) int {
+ if a > b {
+ return b
+ }
+ return a
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md b/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md
index 70482634..a79aef4d 100644
--- a/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md
+++ b/website/content/ChapterFour/1302.Deepest-Leaves-Sum.md
@@ -55,4 +55,11 @@ func dfsDeepestLeavesSum(root *TreeNode, level int, maxLevel, sum *int) {
dfsDeepestLeavesSum(root.Left, level+1, maxLevel, sum)
dfsDeepestLeavesSum(root.Right, level+1, maxLevel, sum)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md b/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md
index 1e15836e..0fadb33f 100644
--- a/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md
+++ b/website/content/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md
@@ -59,4 +59,11 @@ func sumZero(n int) []int {
}
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md b/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md
index 247bbfbb..4de15219 100644
--- a/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md
+++ b/website/content/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md
@@ -87,4 +87,11 @@ func getAllElements1(root1 *TreeNode, root2 *TreeNode) []int {
sort.Ints(arr)
return arr
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1306.Jump-Game-III.md b/website/content/ChapterFour/1306.Jump-Game-III.md
index 63f26345..82a9fe22 100644
--- a/website/content/ChapterFour/1306.Jump-Game-III.md
+++ b/website/content/ChapterFour/1306.Jump-Game-III.md
@@ -77,4 +77,11 @@ func canReach(arr []int, start int) bool {
}
return false
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md b/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md
index 645d9057..a99baec6 100644
--- a/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md
+++ b/website/content/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md
@@ -57,4 +57,11 @@ func decompressRLElist(nums []int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md b/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md
index b7871908..b8453ec3 100644
--- a/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md
+++ b/website/content/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md
@@ -93,4 +93,11 @@ func isNoZero(n int) bool {
return true
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md b/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md
index 01d97eb8..264dc72f 100644
--- a/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md
+++ b/website/content/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md
@@ -84,4 +84,11 @@ func luckyNumbers(matrix [][]int) []int {
return res
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md b/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md
index 9d604246..3e99081b 100644
--- a/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md
+++ b/website/content/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md
@@ -95,4 +95,11 @@ func abs(a int) int {
return a
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md b/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md
index 45f4acf6..005cd089 100644
--- a/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md
+++ b/website/content/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md
@@ -87,4 +87,11 @@ func createTargetArray(nums []int, index []int) []int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md b/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md
index c8081e82..5dc63968 100644
--- a/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md
+++ b/website/content/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md
@@ -95,4 +95,11 @@ func isPrefixOfWord(sentence string, searchWord string) int {
return -1
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md b/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md
index 04dbf134..eeef6901 100644
--- a/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md
+++ b/website/content/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md
@@ -63,4 +63,11 @@ func maxProduct(nums []int) int {
return (max1 - 1) * (max2 - 1)
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1470.Shuffle-the-Array.md b/website/content/ChapterFour/1470.Shuffle-the-Array.md
index 961d200c..571c6c2e 100644
--- a/website/content/ChapterFour/1470.Shuffle-the-Array.md
+++ b/website/content/ChapterFour/1470.Shuffle-the-Array.md
@@ -61,4 +61,11 @@ func shuffle(nums []int, n int) []int {
return result
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1480.Running-Sum-of-1d-Array.md b/website/content/ChapterFour/1480.Running-Sum-of-1d-Array.md
new file mode 100644
index 00000000..12573981
--- /dev/null
+++ b/website/content/ChapterFour/1480.Running-Sum-of-1d-Array.md
@@ -0,0 +1,71 @@
+# [1480. Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/)
+
+## 题目
+
+Given an array `nums`. We define a running sum of an array as `runningSum[i] = sum(nums[0]…nums[i])`.
+
+Return the running sum of `nums`.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,4]
+Output: [1,3,6,10]
+Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,1,1,1,1]
+Output: [1,2,3,4,5]
+Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
+
+```
+
+**Example 3**:
+
+```
+Input: nums = [3,1,2,10,1]
+Output: [3,4,6,16,17]
+
+```
+
+
+**Constraints**:
+
+- `1 <= nums.length <= 1000`
+- `-10^6 <= nums[i] <= 10^6`
+
+## 题目大意
+
+给你一个数组 nums 。数组「动态和」的计算公式为:runningSum[i] = sum(nums[0]…nums[i]) 。请返回 nums 的动态和。
+
+
+## 解题思路
+
+- 简单题,按照题意依次循环计算前缀和即可。
+
+## 代码
+
+```go
+package leetcode
+
+func runningSum(nums []int) []int {
+ dp := make([]int, len(nums)+1)
+ dp[0] = 0
+ for i := 1; i <= len(nums); i++ {
+ dp[i] = dp[i-1] + nums[i-1]
+ }
+ return dp[1:]
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1512.Number-of-Good-Pairs.md b/website/content/ChapterFour/1512.Number-of-Good-Pairs.md
new file mode 100644
index 00000000..5d5db6bf
--- /dev/null
+++ b/website/content/ChapterFour/1512.Number-of-Good-Pairs.md
@@ -0,0 +1,74 @@
+# [1512. Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/)
+
+## 题目
+
+Given an array of integers `nums`.
+
+A pair `(i,j)` is called good if `nums[i] == nums[j]` and `i < j`.
+
+Return the number of good pairs.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,1,1,3]
+Output: 4
+Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,1,1,1]
+Output: 6
+Explanation: Each pair in the array are good.
+
+```
+
+**Example 3**:
+
+```
+Input: nums = [1,2,3]
+Output: 0
+
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 1000`
+- `1 <= nums[i] <= 100`
+
+## 题目大意
+
+给你一个整数数组 nums。如果一组数字 (i,j) 满足 nums[i] == nums[j] 且 i < j ,就可以认为这是一组好数对。返回好数对的数目。
+
+## 解题思路
+
+- 简单题,按照题目中好数对的定义,循环遍历判断两数是否相等,累加计数即可。
+
+## 代码
+
+```go
+package leetcode
+
+func numIdenticalPairs(nums []int) int {
+ total := 0
+ for x := 0; x < len(nums); x++ {
+ for y := x + 1; y < len(nums); y++ {
+ if nums[x] == nums[y] {
+ total++
+ }
+ }
+ }
+ return total
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1539.Kth-Missing-Positive-Number.md b/website/content/ChapterFour/1539.Kth-Missing-Positive-Number.md
new file mode 100644
index 00000000..9ec04f9e
--- /dev/null
+++ b/website/content/ChapterFour/1539.Kth-Missing-Positive-Number.md
@@ -0,0 +1,70 @@
+# [1539. Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number/)
+
+## 题目
+
+Given an array `arr` of positive integers sorted in a **strictly increasing order**, and an integer `k`.
+
+*Find the* `kth` *positive integer that is missing from this array.*
+
+**Example 1**:
+
+```
+Input: arr = [2,3,4,7,11], k = 5
+Output: 9
+Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9.
+```
+
+**Example 2**:
+
+```
+Input: arr = [1,2,3,4], k = 2
+Output: 6
+Explanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6.
+```
+
+**Constraints**:
+
+- `1 <= arr.length <= 1000`
+- `1 <= arr[i] <= 1000`
+- `1 <= k <= 1000`
+- `arr[i] < arr[j]` for `1 <= i < j <= arr.length`
+
+## 题目大意
+
+给你一个 **严格升序排列** 的正整数数组 `arr` 和一个整数 `k` 。请你找到这个数组里第 `k` 个缺失的正整数。
+
+## 解题思路
+
+- 简单题。用一个变量从 1 开始累加,依次比对数组中是否存在,不存在的话就把 k - -,直到 k 为 0 的时候即是要输出的值。特殊情况,missing positive 都在数组之外,如例子 2 。
+
+## 代码
+
+```go
+package leetcode
+
+func findKthPositive(arr []int, k int) int {
+ positive, index := 1, 0
+ for index < len(arr) {
+ if arr[index] != positive {
+ k--
+ } else {
+ index++
+ }
+ if k == 0 {
+ break
+ }
+ positive++
+ }
+ if k != 0 {
+ positive += k - 1
+ }
+ return positive
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1573.Number-of-Ways-to-Split-a-String.md b/website/content/ChapterFour/1573.Number-of-Ways-to-Split-a-String.md
new file mode 100644
index 00000000..9060eded
--- /dev/null
+++ b/website/content/ChapterFour/1573.Number-of-Ways-to-Split-a-String.md
@@ -0,0 +1,115 @@
+# [1573. Number of Ways to Split a String](https://leetcode.com/problems/number-of-ways-to-split-a-string/)
+
+
+## 题目
+
+Given a binary string `s` (a string consisting only of '0's and '1's), we can split `s` into 3 **non-empty** strings s1, s2, s3 (s1+ s2+ s3 = s).
+
+Return the number of ways `s` can be split such that the number of characters '1' is the same in s1, s2, and s3.
+
+Since the answer may be too large, return it modulo 10^9 + 7.
+
+**Example 1**:
+
+```
+Input: s = "10101"
+Output: 4
+Explanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.
+"1|010|1"
+"1|01|01"
+"10|10|1"
+"10|1|01"
+
+```
+
+**Example 2**:
+
+```
+Input: s = "1001"
+Output: 0
+
+```
+
+**Example 3**:
+
+```
+Input: s = "0000"
+Output: 3
+Explanation: There are three ways to split s in 3 parts.
+"0|0|00"
+"0|00|0"
+"00|0|0"
+
+```
+
+**Example 4**:
+
+```
+Input: s = "100100010100110"
+Output: 12
+
+```
+
+**Constraints**:
+
+- `3 <= s.length <= 10^5`
+- `s[i]` is `'0'` or `'1'`.
+
+## 题目大意
+
+给你一个二进制串 s (一个只包含 0 和 1 的字符串),我们可以将 s 分割成 3 个 非空 字符串 s1, s2, s3 (s1 + s2 + s3 = s)。请你返回分割 s 的方案数,满足 s1,s2 和 s3 中字符 '1' 的数目相同。由于答案可能很大,请将它对 10^9 + 7 取余后返回。
+
+## 解题思路
+
+- 这一题是考察的排列组合的知识。根据题意,如果 1 的个数不是 3 的倍数,直接返回 -1。如果字符串里面没有 1,那么切分的方案就是组合,在 n-1 个字母里面选出 2 个位置。利用组合的计算方法,组合数是 (n-1) * (n-2) / 2 。
+- 剩下的是 3 的倍数的情况。在字符串中选 2 个位置隔成 3 段。从第一段最后一个 1 到第二段第一个 1 之间的 0 的个数为 m1,从第二段最后一个 1 到第三段第一个 1 之间的 0 的个数为 m2。利用乘法原理,方案数为 m1 * m2。
+
+## 代码
+
+```go
+package leetcode
+
+func numWays(s string) int {
+ ones := 0
+ for _, c := range s {
+ if c == '1' {
+ ones++
+ }
+ }
+ if ones%3 != 0 {
+ return 0
+ }
+ if ones == 0 {
+ return (len(s) - 1) * (len(s) - 2) / 2 % 1000000007
+ }
+ N, a, b, c, d, count := ones/3, 0, 0, 0, 0, 0
+ for i, letter := range s {
+ if letter == '0' {
+ continue
+ }
+ if letter == '1' {
+ count++
+ }
+ if count == N {
+ a = i
+ }
+ if count == N+1 {
+ b = i
+ }
+ if count == 2*N {
+ c = i
+ }
+ if count == 2*N+1 {
+ d = i
+ }
+ }
+ return (b - a) * (d - c) % 1000000007
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md b/website/content/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md
new file mode 100644
index 00000000..5889f65b
--- /dev/null
+++ b/website/content/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md
@@ -0,0 +1,102 @@
+# [1640. Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)
+
+
+## 题目
+
+You are given an array of **distinct** integers `arr` and an array of integer arrays `pieces`, where the integers in `pieces` are **distinct**. Your goal is to form `arr` by concatenating the arrays in `pieces` **in any order**. However, you are **not** allowed to reorder the integers in each array `pieces[i]`.
+
+Return `true` *if it is possible to form the array* `arr` *from* `pieces`. Otherwise, return `false`.
+
+**Example 1**:
+
+```
+Input: arr = [85], pieces = [[85]]
+Output: true
+```
+
+**Example 2**:
+
+```
+Input: arr = [15,88], pieces = [[88],[15]]
+Output: true
+Explanation: Concatenate [15] then [88]
+```
+
+**Example 3**:
+
+```
+Input: arr = [49,18,16], pieces = [[16,18,49]]
+Output: false
+Explanation: Even though the numbers match, we cannot reorder pieces[0].
+```
+
+**Example 4**:
+
+```
+Input: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]
+Output: true
+Explanation: Concatenate [91] then [4,64] then [78]
+```
+
+**Example 5**:
+
+```
+Input: arr = [1,3,5,7], pieces = [[2,4,6,8]]
+Output: false
+
+```
+
+**Constraints**:
+
+- `1 <= pieces.length <= arr.length <= 100`
+- `sum(pieces[i].length) == arr.length`
+- `1 <= pieces[i].length <= arr.length`
+- `1 <= arr[i], pieces[i][j] <= 100`
+- The integers in `arr` are **distinct**.
+- The integers in `pieces` are **distinct** (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).
+
+## 题目大意
+
+给你一个整数数组 arr ,数组中的每个整数 互不相同 。另有一个由整数数组构成的数组 pieces,其中的整数也 互不相同 。请你以 任意顺序 连接 pieces 中的数组以形成 arr 。但是,不允许 对每个数组 pieces[i] 中的整数重新排序。如果可以连接 pieces 中的数组形成 arr ,返回 true ;否则,返回 false 。
+
+## 解题思路
+
+- 简单题。题目保证了 arr 中的元素唯一,所以可以用 map 把每个元素的 index 存起来,方便查找。遍历 pieces 数组,在每个一维数组中判断元素顺序是否和原 arr 元素相对顺序一致。这个时候就用 map 查找,如果顺序是一一相连的,那么就是正确的。有一个顺序不是一一相连,或者出现了 arr 不存在的元素,都返回 false。
+
+## 代码
+
+```go
+package leetcode
+
+func canFormArray(arr []int, pieces [][]int) bool {
+ arrMap := map[int]int{}
+ for i, v := range arr {
+ arrMap[v] = i
+ }
+ for i := 0; i < len(pieces); i++ {
+ order := -1
+ for j := 0; j < len(pieces[i]); j++ {
+ if _, ok := arrMap[pieces[i][j]]; !ok {
+ return false
+ }
+ if order == -1 {
+ order = arrMap[pieces[i][j]]
+ } else {
+ if arrMap[pieces[i][j]] == order+1 {
+ order = arrMap[pieces[i][j]]
+ } else {
+ return false
+ }
+ }
+ }
+ }
+ return true
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1641.Count-Sorted-Vowel-Strings.md b/website/content/ChapterFour/1641.Count-Sorted-Vowel-Strings.md
new file mode 100644
index 00000000..79480691
--- /dev/null
+++ b/website/content/ChapterFour/1641.Count-Sorted-Vowel-Strings.md
@@ -0,0 +1,97 @@
+# [1641. Count Sorted Vowel Strings](https://leetcode.com/problems/count-sorted-vowel-strings/)
+
+
+## 题目
+
+Given an integer `n`, return *the number of strings of length* `n` *that consist only of vowels (*`a`*,* `e`*,* `i`*,* `o`*,* `u`*) and are **lexicographically sorted**.*
+
+A string `s` is **lexicographically sorted** if for all valid `i`, `s[i]` is the same as or comes before `s[i+1]` in the alphabet.
+
+**Example 1:**
+
+```
+Input: n = 1
+Output: 5
+Explanation: The 5 sorted strings that consist of vowels only are ["a","e","i","o","u"].
+```
+
+**Example 2:**
+
+```
+Input: n = 2
+Output: 15
+Explanation: The 15 sorted strings that consist of vowels only are
+["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"].
+Note that "ea" is not a valid string since 'e' comes after 'a' in the alphabet.
+
+```
+
+**Example 3:**
+
+```
+Input: n = 33
+Output: 66045
+
+```
+
+**Constraints:**
+
+- `1 <= n <= 50`
+
+## 题目大意
+
+给你一个整数 n,请返回长度为 n 、仅由元音 (a, e, i, o, u) 组成且按 字典序排列 的字符串数量。
+
+字符串 s 按 字典序排列 需要满足:对于所有有效的 i,s[i] 在字母表中的位置总是与 s[i+1] 相同或在 s[i+1] 之前。
+
+## 解题思路
+
+- 题目给的数据量并不大,第一个思路是利用 DFS 遍历打表法。时间复杂度 O(1),空间复杂度 O(1)。
+- 第二个思路是利用数学中的组合公式计算结果。题目等价于假设现在有 n 个字母,要求取 4 次球(可以选择不取)将字母分为 5 堆,问有几种取法。确定了取法以后,`a`,`e`,`i`,`o`,`u`,每个字母的个数就确定了,据题意要求按照字母序排序,那么最终字符串也就确定了。现在关注解决这个组合问题就可以了。把问题再转化一次,等价于,有 n+4 个字母,取 4 次,问有几种取法。+4 代表 4 个空操作,取走它们意味着不取。根据组合的数学定义,答案为 C(n+4,4)。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 打表
+func countVowelStrings(n int) int {
+ res := []int{1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465, 35960, 40920, 46376, 52360, 58905, 66045, 73815, 82251, 91390, 101270, 111930, 123410, 135751, 148995, 163185, 178365, 194580, 211876, 230300, 249900, 270725, 292825, 316251}
+ return res[n]
+}
+
+func makeTable() []int {
+ res, array := 0, []int{}
+ for i := 0; i < 51; i++ {
+ countVowelStringsDFS(i, 0, []string{}, []string{"a", "e", "i", "o", "u"}, &res)
+ array = append(array, res)
+ res = 0
+ }
+ return array
+}
+
+func countVowelStringsDFS(n, index int, cur []string, vowels []string, res *int) {
+ vowels = vowels[index:]
+ if len(cur) == n {
+ (*res)++
+ return
+ }
+ for i := 0; i < len(vowels); i++ {
+ cur = append(cur, vowels[i])
+ countVowelStringsDFS(n, i, cur, vowels, res)
+ cur = cur[:len(cur)-1]
+ }
+}
+
+// 解法二 数学方法 —— 组合
+func countVowelStrings1(n int) int {
+ return (n + 1) * (n + 2) * (n + 3) * (n + 4) / 24
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1646.Get-Maximum-in-Generated-Array.md b/website/content/ChapterFour/1646.Get-Maximum-in-Generated-Array.md
new file mode 100644
index 00000000..b14b1501
--- /dev/null
+++ b/website/content/ChapterFour/1646.Get-Maximum-in-Generated-Array.md
@@ -0,0 +1,103 @@
+# [1646. Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array/)
+
+
+## 题目
+
+You are given an integer `n`. An array `nums` of length `n + 1` is generated in the following way:
+
+- `nums[0] = 0`
+- `nums[1] = 1`
+- `nums[2 * i] = nums[i]` when `2 <= 2 * i <= n`
+- `nums[2 * i + 1] = nums[i] + nums[i + 1]` when `2 <= 2 * i + 1 <= n`
+
+Return *****the **maximum** integer in the array* `nums`.
+
+**Example 1**:
+
+```
+Input: n = 7
+Output: 3
+Explanation: According to the given rules:
+ nums[0] = 0
+ nums[1] = 1
+ nums[(1 * 2) = 2] = nums[1] = 1
+ nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2
+ nums[(2 * 2) = 4] = nums[2] = 1
+ nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3
+ nums[(3 * 2) = 6] = nums[3] = 2
+ nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3
+Hence, nums = [0,1,1,2,1,3,2,3], and the maximum is 3.
+
+```
+
+**Example 2**:
+
+```
+Input: n = 2
+Output: 1
+Explanation: According to the given rules, the maximum between nums[0], nums[1], and nums[2] is 1.
+
+```
+
+**Example 3**:
+
+```
+Input: n = 3
+Output: 2
+Explanation: According to the given rules, the maximum between nums[0], nums[1], nums[2], and nums[3] is 2.
+
+```
+
+**Constraints**:
+
+- `0 <= n <= 100`
+
+## 题目大意
+
+给你一个整数 n 。按下述规则生成一个长度为 n + 1 的数组 nums :
+
+- nums[0] = 0
+- nums[1] = 1
+- 当 2 <= 2 * i <= n 时,nums[2 * i] = nums[i]
+- 当 2 <= 2 * i + 1 <= n 时,nums[2 * i + 1] = nums[i] + nums[i + 1]
+
+返回生成数组 nums 中的 最大值。
+
+## 解题思路
+
+- 给出一个 n + 1 的数组,并按照生成规则生成这个数组,求出这个数组中的最大值。
+- 简单题,按照题意生成数组,边生成边记录和更新最大值即可。
+- 注意边界条件,当 n 为 0 的时候,数组里面只有一个元素 0 。
+
+## 代码
+
+```go
+package leetcode
+
+func getMaximumGenerated(n int) int {
+ if n == 0 {
+ return 0
+ }
+ nums, max := make([]int, n+1), 0
+ nums[0], nums[1] = 0, 1
+ for i := 0; i <= n; i++ {
+ if nums[i] > max {
+ max = nums[i]
+ }
+ if 2*i >= 2 && 2*i <= n {
+ nums[2*i] = nums[i]
+ }
+ if 2*i+1 >= 2 && 2*i+1 <= n {
+ nums[2*i+1] = nums[i] + nums[i+1]
+ }
+ }
+ return max
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique.md b/website/content/ChapterFour/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique.md
new file mode 100644
index 00000000..dddd6ba1
--- /dev/null
+++ b/website/content/ChapterFour/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique.md
@@ -0,0 +1,96 @@
+# [1647. Minimum Deletions to Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/)
+
+
+## 题目
+
+A string `s` is called **good** if there are no two different characters in `s` that have the same **frequency**.
+
+Given a string `s`, return *the **minimum** number of characters you need to delete to make* `s` ***good**.*
+
+The **frequency** of a character in a string is the number of times it appears in the string. For example, in the string `"aab"`, the **frequency** of `'a'` is `2`, while the **frequency** of `'b'` is `1`.
+
+**Example 1**:
+
+```
+Input: s = "aab"
+Output: 0
+Explanation: s is already good.
+
+```
+
+**Example 2**:
+
+```
+Input: s = "aaabbbcc"
+Output: 2
+Explanation: You can delete two 'b's resulting in the good string "aaabcc".
+Another way it to delete one 'b' and one 'c' resulting in the good string "aaabbc".
+```
+
+**Example 3**:
+
+```
+Input: s = "ceabaacb"
+Output: 2
+Explanation: You can delete both 'c's resulting in the good string "eabaab".
+Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).
+
+```
+
+**Constraints**:
+
+- `1 <= s.length <= 105`
+- `s` contains only lowercase English letters.
+
+## 题目大意
+
+如果字符串 s 中 不存在 两个不同字符 频次 相同的情况,就称 s 是 优质字符串 。
+
+给你一个字符串 s,返回使 s 成为优质字符串需要删除的最小字符数。
+
+字符串中字符的 频次 是该字符在字符串中的出现次数。例如,在字符串 "aab" 中,'a' 的频次是 2,而 'b' 的频次是 1 。
+
+**提示:**
+
+- `1 <= s.length <= 105`
+- `s` 仅含小写英文字母
+
+## 解题思路
+
+- 给出一个字符串 s,要求输出使 s 变成“优质字符串”需要删除的最小字符数。“优质字符串”的定义是:字符串 s 中不存在频次相同的两个不同字符。
+- 首先将 26 个字母在字符串中的频次分别统计出来,然后把频次从大到小排列,从频次大的开始,依次调整:例如,假设前一个和后一个频次相等,就把前一个字符删除一个,频次减一,再次排序,如果频次还相等,继续调整,如果频次不同了,游标往后移,继续调整后面的频次。直到所有的频次都不同了,就可以输出最终结果了。
+- 这里需要注意频次为 0 的情况,即字母都被删光了。频次为 0 以后,就不需要再比较了。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "sort"
+)
+
+func minDeletions(s string) int {
+ frequency, res := make([]int, 26), 0
+ for i := 0; i < len(s); i++ {
+ frequency[s[i]-'a']++
+ }
+ sort.Sort(sort.Reverse(sort.IntSlice(frequency)))
+ for i := 1; i <= 25; i++ {
+ if frequency[i] == frequency[i-1] && frequency[i] != 0 {
+ res++
+ frequency[i]--
+ sort.Sort(sort.Reverse(sort.IntSlice(frequency)))
+ i--
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1648.Sell-Diminishing-Valued-Colored-Balls.md b/website/content/ChapterFour/1648.Sell-Diminishing-Valued-Colored-Balls.md
new file mode 100644
index 00000000..f65f56cb
--- /dev/null
+++ b/website/content/ChapterFour/1648.Sell-Diminishing-Valued-Colored-Balls.md
@@ -0,0 +1,138 @@
+# [1648. Sell Diminishing-Valued Colored Balls](https://leetcode.com/problems/sell-diminishing-valued-colored-balls/)
+
+
+## 题目
+
+You have an `inventory` of different colored balls, and there is a customer that wants `orders` balls of **any** color.
+
+The customer weirdly values the colored balls. Each colored ball's value is the number of balls **of that color** you currently have in your `inventory`. For example, if you own `6` yellow balls, the customer would pay `6` for the first yellow ball. After the transaction, there are only `5` yellow balls left, so the next yellow ball is then valued at `5` (i.e., the value of the balls decreases as you sell more to the customer).
+
+You are given an integer array, `inventory`, where `inventory[i]` represents the number of balls of the `ith` color that you initially own. You are also given an integer `orders`, which represents the total number of balls that the customer wants. You can sell the balls **in any order**.
+
+Return *the **maximum** total value that you can attain after selling* `orders` *colored balls*. As the answer may be too large, return it **modulo** `109 + 7`.
+
+**Example 1**:
+
+
+
+```
+Input: inventory = [2,5], orders = 4
+Output: 14
+Explanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).
+The maximum total value is 2 + 5 + 4 + 3 = 14.
+
+```
+
+**Example 2**:
+
+```
+Input: inventory = [3,5], orders = 6
+Output: 19
+Explanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).
+The maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.
+```
+
+**Example 3**:
+
+```
+Input: inventory = [2,8,4,10,6], orders = 20
+Output: 110
+```
+
+**Example 4**:
+
+```
+Input: inventory = [1000000000], orders = 1000000000
+Output: 21
+Explanation: Sell the 1st color 1000000000 times for a total value of 500000000500000000. 500000000500000000 modulo 109 + 7 = 21.
+```
+
+**Constraints**:
+
+- `1 <= inventory.length <= 10^5`
+- `1 <= inventory[i] <= 10^9`
+- `1 <= orders <= min(sum(inventory[i]), 10^9)`
+
+## 题目大意
+
+你有一些球的库存 inventory ,里面包含着不同颜色的球。一个顾客想要 任意颜色 总数为 orders 的球。这位顾客有一种特殊的方式衡量球的价值:每个球的价值是目前剩下的 同色球 的数目。比方说还剩下 6 个黄球,那么顾客买第一个黄球的时候该黄球的价值为 6 。这笔交易以后,只剩下 5 个黄球了,所以下一个黄球的价值为 5 (也就是球的价值随着顾客购买同色球是递减的)
+
+给你整数数组 inventory ,其中 inventory[i] 表示第 i 种颜色球一开始的数目。同时给你整数 orders ,表示顾客总共想买的球数目。你可以按照 任意顺序 卖球。请你返回卖了 orders 个球以后 最大 总价值之和。由于答案可能会很大,请你返回答案对 109 + 7 取余数 的结果。
+
+提示:
+
+- 1 <= inventory.length <= 10^5
+- 1 <= inventory[i] <= 10^9
+- 1 <= orders <= min(sum(inventory[i]), 10^9)
+
+## 解题思路
+
+- 给出一个 `inventory` 数组和 `orders` 次操作,要求输出数组中前 `orders` 大个元素累加和。需要注意的是,每累加一个元素 `inventory[i]`,这个元素都会减一,下次再累加的时候,需要选取更新以后的数组的最大值。
+- 拿到这个题目以后很容易想到优先队列,建立大根堆以后,`pop` 出当前最大值 `maxItem`,累加,以后把 `maxItem` 减一再 `push` 回去。循环执行 `orders` 次以后即是最终结果。题目是这个意思,但是我们不能这么写代码,因为题目条件里面给出了 `orders` 的数据大小。orders 最大为 10^9。按照优先队列的这个方法一定会超时,时间复杂度为 O(orders⋅logn)。那就换一个思路。优先队列这个思路中,重复操作了 `orders` 次,其实在这些操作中,有一些是没有必要的废操作。这些大量的“废”操作导致了超时。试想,在 `orders` 次操作中,能否合并 `n` 个 `pop` 操作,一口气先 `pop` 掉 `n` 个前 `n` 大的数呢?这个是可行的,因为每次 `pop` 出去,元素都只会减一,这个是非常有规律的。
+- 为了接下来的描述更加清晰易懂,还需要再定义 1 个值, `thresholdValue` 为操作 `n` 次以后,当前 `inventory` 数组的最大值。关于 `thresholdValue` 的理解,这里要说明一下。 `thresholdValue` 的来源有 2 种,一种是本来数组里面就有这个值,还有一种来源是 `inventory[i]` 元素减少到了 `thresholdValue` 这个值。举个例子:原始数组是 [2,3,3,4,5],`orders` = 4,取 4 次以后,剩下的数组是 [2,2,3,3,3]。3 个 3 里面其中一个 3 就来自于 `4-1=3`,或者 `5-2=3`。
+- 用二分搜索在 [0,max(`inventory`)] 区间内找到这个 `thresholdValue` 值,能满足下列不等式的最小 `thresholdValue` 值:
+
+ $$\sum_{inventory[i]\geqslant thresholdValue}^{} \left ( inventory[i] - thresholdValue \right )\leqslant orders$$
+
+ `thresholdValue` 越小,不等式左边的值越大,随着 `thresholdValue` 的增大,不等式左边的值越来越小,直到刚刚能小于等于 `orders`。求出了 `thresholdValue` 值以后,还需要再判断有多少值等于 `thresholdValue - 1` 值了。
+
+ 
+
+- 还是举上面的例子,原始数组是 [2,3,3,4,5],`orders` = 4,我们可以求得 `thresholdValue` = 3 。`inventory[i]` > `thresholdValue` 的那部分 100% 的要取走,`thresholdValue` 就像一个水平面,突出水平面的那些都要拿走,每列的值按照等差数列求和公式计算即可。但是 `orders` - `thresholdValue` = 1,说明水平面以下还要拿走一个,即 `thresholdValue` 线下的虚线框里面的那 4 个球,还需要任意取走一个。最后总的结果是这 2 部分的总和,( ( 5 + 4 ) + 4 ) + 3 = 16 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "container/heap"
+)
+
+// 解法一 贪心 + 二分搜索
+func maxProfit(inventory []int, orders int) int {
+ maxItem, thresholdValue, count, res, mod := 0, -1, 0, 0, 1000000007
+ for i := 0; i < len(inventory); i++ {
+ if inventory[i] > maxItem {
+ maxItem = inventory[i]
+ }
+ }
+ low, high := 0, maxItem
+ for low <= high {
+ mid := low + ((high - low) >> 1)
+ for i := 0; i < len(inventory); i++ {
+ count += max(inventory[i]-mid, 0)
+ }
+ if count <= orders {
+ thresholdValue = mid
+ high = mid - 1
+ } else {
+ low = mid + 1
+ }
+ count = 0
+ }
+ count = 0
+ for i := 0; i < len(inventory); i++ {
+ count += max(inventory[i]-thresholdValue, 0)
+ }
+ count = orders - count
+ for i := 0; i < len(inventory); i++ {
+ if inventory[i] >= thresholdValue {
+ if count > 0 {
+ res += (thresholdValue + inventory[i]) * (inventory[i] - thresholdValue + 1) / 2
+ count--
+ } else {
+ res += (thresholdValue + 1 + inventory[i]) * (inventory[i] - thresholdValue) / 2
+ }
+ }
+ }
+ return res % mod
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md b/website/content/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md
new file mode 100644
index 00000000..69450ff8
--- /dev/null
+++ b/website/content/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md
@@ -0,0 +1,196 @@
+# [1649. Create Sorted Array through Instructions](https://leetcode.com/problems/create-sorted-array-through-instructions/)
+
+## 题目
+
+Given an integer array `instructions`, you are asked to create a sorted array from the elements in `instructions`. You start with an empty container `nums`. For each element from **left to right** in `instructions`, insert it into `nums`. The **cost** of each insertion is the **minimum** of the following:
+
+- The number of elements currently in `nums` that are **strictly less than** `instructions[i]`.
+- The number of elements currently in `nums` that are **strictly greater than** `instructions[i]`.
+
+For example, if inserting element `3` into `nums = [1,2,3,5]`, the **cost** of insertion is `min(2, 1)` (elements `1` and `2` are less than `3`, element `5` is greater than `3`) and `nums` will become `[1,2,3,3,5]`.
+
+Return *the **total cost** to insert all elements from* `instructions` *into* `nums`. Since the answer may be large, return it **modulo** `10^9 + 7`
+
+**Example 1**:
+
+```
+Input: instructions = [1,5,6,2]
+Output: 1
+Explanation: Begin with nums = [].
+Insert 1 with cost min(0, 0) = 0, now nums = [1].
+Insert 5 with cost min(1, 0) = 0, now nums = [1,5].
+Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].
+Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].
+The total cost is 0 + 0 + 0 + 1 = 1.
+```
+
+**Example 2**:
+
+```
+Input: instructions = [1,2,3,6,5,4]
+Output: 3
+Explanation: Begin with nums = [].
+Insert 1 with cost min(0, 0) = 0, now nums = [1].
+Insert 2 with cost min(1, 0) = 0, now nums = [1,2].
+Insert 3 with cost min(2, 0) = 0, now nums = [1,2,3].
+Insert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].
+Insert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].
+Insert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].
+The total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.
+```
+
+**Example 3**:
+
+```
+Input: instructions = [1,3,3,3,2,4,2,1,2]
+Output: 4
+Explanation: Begin with nums = [].
+Insert 1 with cost min(0, 0) = 0, now nums = [1].
+Insert 3 with cost min(1, 0) = 0, now nums = [1,3].
+Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3].
+Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].
+Insert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].
+Insert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].
+Insert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].
+Insert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].
+Insert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].
+The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.
+```
+
+**Constraints**:
+
+- `1 <= instructions.length <= 105`
+- `1 <= instructions[i] <= 105`
+
+## 题目大意
+
+给你一个整数数组 instructions ,你需要根据 instructions 中的元素创建一个有序数组。一开始你有一个空的数组 nums ,你需要 从左到右 遍历 instructions 中的元素,将它们依次插入 nums 数组中。每一次插入操作的 代价 是以下两者的 较小值 :
+
+- nums 中 严格小于 instructions[i] 的数字数目。
+- nums 中 严格大于 instructions[i] 的数字数目。
+
+比方说,如果要将 3 插入到 nums = [1,2,3,5] ,那么插入操作的 代价 为 min(2, 1) (元素 1 和 2 小于 3 ,元素 5 大于 3 ),插入后 nums 变成 [1,2,3,3,5] 。请你返回将 instructions 中所有元素依次插入 nums 后的 总最小代价 。由于答案会很大,请将它对 10^9 + 7 取余 后返回。
+
+## 解题思路
+
+- 给出一个数组,要求将其中的元素从头开始往另外一个空数组中插入,每次插入前,累加代价值 cost = min(**strictly less than**, **strictly greater than**)。最后输出累加值。
+- 这一题虽然是 Hard 题,但是读完题以后就可以判定这是模板题了。可以用线段树和树状数组来解决。这里简单说说线段树的思路吧,先将待插入的数组排序,获得总的区间。每次循环做 4 步:2 次 `query` 分别得到 `strictlyLessThan` 和 `strictlyGreaterThan` ,再比较出两者中的最小值累加,最后一步就是 `update`。
+- 由于题目给的数据比较大,所以建立线段树之前记得要先离散化。这一题核心代码不超过 10 行,其他的都是模板代码。具体实现见代码。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "github.com/halfrost/LeetCode-Go/template"
+ "sort"
+)
+
+// 解法一 线段树 SegmentTree
+func createSortedArray(instructions []int) int {
+ if len(instructions) == 0 {
+ return 0
+ }
+ st, res, mod := template.SegmentCountTree{}, 0, 1000000007
+ numsMap, numsArray, tmpArray := discretization1649(instructions)
+ // 初始化线段树,节点内的值都赋值为 0,即计数为 0
+ st.Init(tmpArray, func(i, j int) int {
+ return 0
+ })
+ for i := 0; i < len(instructions); i++ {
+ strictlyLessThan := st.Query(0, numsMap[instructions[i]]-1)
+ strictlyGreaterThan := st.Query(numsMap[instructions[i]]+1, numsArray[len(numsArray)-1])
+ res = (res + min(strictlyLessThan, strictlyGreaterThan)) % mod
+ st.UpdateCount(numsMap[instructions[i]])
+ }
+ return res
+}
+
+func discretization1649(instructions []int) (map[int]int, []int, []int) {
+ tmpArray, numsArray, numsMap := []int{}, []int{}, map[int]int{}
+ for i := 0; i < len(instructions); i++ {
+ numsMap[instructions[i]] = instructions[i]
+ }
+ for _, v := range numsMap {
+ numsArray = append(numsArray, v)
+ }
+ sort.Ints(numsArray)
+ for i, num := range numsArray {
+ numsMap[num] = i
+ }
+ for i := range numsArray {
+ tmpArray = append(tmpArray, i)
+ }
+ return numsMap, numsArray, tmpArray
+}
+
+func min(a int, b int) int {
+ if a > b {
+ return b
+ }
+ return a
+}
+
+// 解法二 树状数组 Binary Indexed Tree
+func createSortedArray1(instructions []int) int {
+ b := newBIT(make([]int, 100001))
+ var res int
+ cnt := map[int]int{}
+ for i, n := range instructions {
+ less := b.get(n - 1)
+ greater := i - less - cnt[n]
+ res = (res + min(less, greater)) % (1e9 + 7)
+ b.update(n, 1)
+ cnt[n]++
+ }
+
+ return res % (1e9 + 7)
+}
+
+func max(x, y int) int {
+ if x > y {
+ return x
+ }
+ return y
+}
+
+type BIT struct {
+ data []int
+}
+
+func newBIT(nums []int) *BIT {
+ data := make([]int, len(nums)+1)
+ b := &BIT{data}
+ for i, n := range nums {
+ b.update(i, n)
+ }
+
+ return b
+}
+
+func (b *BIT) update(i, num int) {
+ i++
+ for i < len(b.data) {
+ b.data[i] += num
+ i += (i & -i)
+ }
+}
+
+func (b *BIT) get(i int) int {
+ i++
+ var sum int
+ for i > 0 {
+ sum += b.data[i]
+ i -= (i & -i)
+ }
+ return sum
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1652.Defuse-the-Bomb.md b/website/content/ChapterFour/1652.Defuse-the-Bomb.md
new file mode 100644
index 00000000..3ae46fce
--- /dev/null
+++ b/website/content/ChapterFour/1652.Defuse-the-Bomb.md
@@ -0,0 +1,132 @@
+# [1652. Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)
+
+
+## 题目
+
+You have a bomb to defuse, and your time is running out! Your informer will provide you with a **circular** array `code` of length of `n` and a key `k`.
+
+To decrypt the code, you must replace every number. All the numbers are replaced **simultaneously**.
+
+- If `k > 0`, replace the `ith` number with the sum of the **next** `k` numbers.
+- If `k < 0`, replace the `ith` number with the sum of the **previous** `k` numbers.
+- If `k == 0`, replace the `ith` number with `0`.
+
+As `code` is circular, the next element of `code[n-1]` is `code[0]`, and the previous element of `code[0]` is `code[n-1]`.
+
+Given the **circular** array `code` and an integer key `k`, return *the decrypted code to defuse the bomb*!
+
+**Example 1**:
+
+```
+Input: code = [5,7,1,4], k = 3
+Output: [12,10,16,13]
+Explanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.
+```
+
+**Example 2**:
+
+```
+Input: code = [1,2,3,4], k = 0
+Output: [0,0,0,0]
+Explanation: When k is zero, the numbers are replaced by 0.
+```
+
+**Example 3**:
+
+```
+Input: code = [2,4,9,3], k = -2
+Output: [12,5,6,13]
+Explanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.
+```
+
+**Constraints**:
+
+- `n == code.length`
+- `1 <= n <= 100`
+- `1 <= code[i] <= 100`
+- `(n - 1) <= k <= n - 1`
+
+## 题目大意
+
+你有一个炸弹需要拆除,时间紧迫!你的情报员会给你一个长度为 n 的 循环 数组 code 以及一个密钥 k 。为了获得正确的密码,你需要替换掉每一个数字。所有数字会 同时 被替换。
+
+- 如果 k > 0 ,将第 i 个数字用 接下来 k 个数字之和替换。
+- 如果 k < 0 ,将第 i 个数字用 之前 k 个数字之和替换。
+- 如果 k == 0 ,将第 i 个数字用 0 替换。
+
+由于 code 是循环的, code[n-1] 下一个元素是 code[0] ,且 code[0] 前一个元素是 code[n-1] 。
+
+给你 循环 数组 code 和整数密钥 k ,请你返回解密后的结果来拆除炸弹!
+
+## 解题思路
+
+- 给出一个 code 数组,要求按照规则替换每个字母。
+- 简单题,按照题意描述循环即可。
+
+## 代码
+
+```go
+package leetcode
+
+func decrypt(code []int, k int) []int {
+ if k == 0 {
+ for i := 0; i < len(code); i++ {
+ code[i] = 0
+ }
+ return code
+ }
+ count, sum, res := k, 0, make([]int, len(code))
+ if k > 0 {
+ for i := 0; i < len(code); i++ {
+ for j := i + 1; j < len(code); j++ {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count--
+ }
+ if count > 0 {
+ for j := 0; j < len(code); j++ {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count--
+ }
+ }
+ res[i] = sum
+ sum, count = 0, k
+ }
+ }
+ if k < 0 {
+ for i := 0; i < len(code); i++ {
+ for j := i - 1; j >= 0; j-- {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count++
+ }
+ if count < 0 {
+ for j := len(code) - 1; j >= 0; j-- {
+ if count == 0 {
+ break
+ }
+ sum += code[j]
+ count++
+ }
+ }
+ res[i] = sum
+ sum, count = 0, k
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1653.Minimum-Deletions-to-Make-String-Balanced.md b/website/content/ChapterFour/1653.Minimum-Deletions-to-Make-String-Balanced.md
new file mode 100644
index 00000000..bd2ee314
--- /dev/null
+++ b/website/content/ChapterFour/1653.Minimum-Deletions-to-Make-String-Balanced.md
@@ -0,0 +1,97 @@
+# [1653. Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/)
+
+
+## 题目
+
+You are given a string `s` consisting only of characters `'a'` and `'b'`.
+
+You can delete any number of characters in `s` to make `s` **balanced**. `s` is **balanced** if there is no pair of indices `(i,j)` such that `i < j` and `s[i] = 'b'` and `s[j]= 'a'`.
+
+Return *the **minimum** number of deletions needed to make* `s` ***balanced***.
+
+**Example 1**:
+
+```
+Input: s = "aababbab"
+Output: 2
+Explanation: You can either:
+Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
+Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
+```
+
+**Example 2**:
+
+```
+Input: s = "bbaaaaabb"
+Output: 2
+Explanation: The only solution is to delete the first two characters.
+```
+
+**Constraints**:
+
+- `1 <= s.length <= 105`
+- `s[i]` is `'a'` or `'b'`.
+
+## 题目大意
+
+给你一个字符串 s ,它仅包含字符 'a' 和 'b' 。你可以删除 s 中任意数目的字符,使得 s 平衡 。我们称 s 平衡的 当不存在下标对 (i,j) 满足 i < j 且 s[i] = 'b' 同时 s[j]= 'a' 。请你返回使 s 平衡 的 最少 删除次数。
+
+## 解题思路
+
+- 给定一个字符串,要求删除最少次数,使得字母 a 都排在字母 b 的前面。
+- 很容易想到的一个解题思路是 DP。定义 `dp[i]` 为字符串下标 [ 0, i ] 这个区间内使得字符串平衡的最少删除次数。当 `s[i] == 'a'` 的时候,有 2 种情况,一种是 `s[i]` 前面全是 `[aa……aa]` 的情况,这个时候只需要把其中的所有的字母 `b` 删除即可。还有一种情况是 `s[i]` 前面有字母 `a` 也有字母 `b`,即 `[aaa……abb……b]`,这种情况就需要考虑 `dp[i-1]` 了。当前字母是 `a`,那么肯定要删除字母 `a`,来维持前面有一段字母 `b` 的情况。当 `s[i] == 'b'` 的时候,不管是 `[aa……aa]` 这种情况,还是 `[aaa……abb……b]` 这种情况,当前字母 `b` 都可以直接附加在后面,也能保证整个字符串是平衡的。所以状态转移方程为 `dp[i+1] = min(dp[i] + 1, bCount), s[i] == 'a'`,`dp[i+1] = dp[i], s[i] == 'b'`。最终答案存在 `dp[n]` 中。由于前后项的递推关系中只用到一次前一项,所以我们还可以优化一下空间,用一个变量保存前一项的结果。优化以后的代码见解法一。
+- 这一题还有一个模拟的思路。题目要求找到最小删除字数,那么就是要找到一个“临界点”,在这个临界点的左边删除所有的字母 b,在这个临界点的右边删除所有的字母 a。在所有的“临界点”中找到删除最少的次数。代码实现见解法二。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 DP
+func minimumDeletions(s string) int {
+ prev, res, bCount := 0, 0, 0
+ for _, c := range s {
+ if c == 'a' {
+ res = min(prev+1, bCount)
+ prev = res
+ } else {
+ bCount++
+ }
+ }
+ return res
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+// 解法二 模拟
+func minimumDeletions1(s string) int {
+ aCount, bCount, res := 0, 0, 0
+ for i := 0; i < len(s); i++ {
+ if s[i] == 'a' {
+ aCount++
+ }
+ }
+ res = aCount
+ for i := 0; i < len(s); i++ {
+ if s[i] == 'a' {
+ aCount--
+ } else {
+ bCount++
+ }
+ res = min(res, aCount+bCount)
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1654.Minimum-Jumps-to-Reach-Home.md b/website/content/ChapterFour/1654.Minimum-Jumps-to-Reach-Home.md
new file mode 100644
index 00000000..793f382c
--- /dev/null
+++ b/website/content/ChapterFour/1654.Minimum-Jumps-to-Reach-Home.md
@@ -0,0 +1,108 @@
+# [1654. Minimum Jumps to Reach Home](https://leetcode.com/problems/minimum-jumps-to-reach-home/)
+
+
+## 题目
+
+A certain bug's home is on the x-axis at position `x`. Help them get there from position `0`.
+
+The bug jumps according to the following rules:
+
+- It can jump exactly `a` positions **forward** (to the right).
+- It can jump exactly `b` positions **backward** (to the left).
+- It cannot jump backward twice in a row.
+- It cannot jump to any `forbidden` positions.
+
+The bug may jump forward **beyond** its home, but it **cannot jump** to positions numbered with **negative** integers.
+
+Given an array of integers `forbidden`, where `forbidden[i]` means that the bug cannot jump to the position `forbidden[i]`, and integers `a`, `b`, and `x`, return *the minimum number of jumps needed for the bug to reach its home*. If there is no possible sequence of jumps that lands the bug on position `x`, return `1.`
+
+**Example 1**:
+
+```
+Input: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9
+Output: 3
+Explanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.
+```
+
+**Example 2**:
+
+```
+Input: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11
+Output: -1
+```
+
+**Example 3**:
+
+```
+Input: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7
+Output: 2
+Explanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.
+
+```
+
+**Constraints**:
+
+- `1 <= forbidden.length <= 1000`
+- `1 <= a, b, forbidden[i] <= 2000`
+- `0 <= x <= 2000`
+- All the elements in `forbidden` are distinct.
+- Position `x` is not forbidden.
+
+## 题目大意
+
+有一只跳蚤的家在数轴上的位置 x 处。请你帮助它从位置 0 出发,到达它的家。
+
+跳蚤跳跃的规则如下:
+
+- 它可以 往前 跳恰好 a 个位置(即往右跳)。
+- 它可以 往后 跳恰好 b 个位置(即往左跳)。
+- 它不能 连续 往后跳 2 次。
+- 它不能跳到任何 forbidden 数组中的位置。
+
+跳蚤可以往前跳 超过 它的家的位置,但是它 不能跳到负整数 的位置。给你一个整数数组 forbidden ,其中 forbidden[i] 是跳蚤不能跳到的位置,同时给你整数 a, b 和 x ,请你返回跳蚤到家的最少跳跃次数。如果没有恰好到达 x 的可行方案,请你返回 -1 。
+
+## 解题思路
+
+- 给出坐标 x ,可以往前跳的步长 a,往后跳的步长 b。要求输出能跳回家的最少跳跃次数。
+- 求最少跳跃次数,思路用 BFS 求解,最先到达坐标 x 的方案即是最少跳跃次数。对`forbidden` 的处理是把记忆化数组里面把他们标记为 true。禁止连续往后跳 2 次的限制,要求我们在 BFS 入队的时候再记录一下跳跃方向,每次往后跳的时候判断前一跳是否是往后跳,如果是往后跳,此次就不能往后跳了。
+
+## 代码
+
+```go
+package leetcode
+
+func minimumJumps(forbidden []int, a int, b int, x int) int {
+ visited := make([]bool, 6000)
+ for i := range forbidden {
+ visited[forbidden[i]] = true
+ }
+ queue, res := [][2]int{{0, 0}}, -1
+ for len(queue) > 0 {
+ length := len(queue)
+ res++
+ for i := 0; i < length; i++ {
+ cur, isBack := queue[i][0], queue[i][1]
+ if cur == x {
+ return res
+ }
+ if isBack == 0 && cur-b > 0 && !visited[cur-b] {
+ visited[cur-b] = true
+ queue = append(queue, [2]int{cur - b, 1})
+ }
+ if cur+a < len(visited) && !visited[cur+a] {
+ visited[cur+a] = true
+ queue = append(queue, [2]int{cur + a, 0})
+ }
+ }
+ queue = queue[length:]
+ }
+ return -1
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1655.Distribute-Repeating-Integers.md b/website/content/ChapterFour/1655.Distribute-Repeating-Integers.md
new file mode 100644
index 00000000..41977eef
--- /dev/null
+++ b/website/content/ChapterFour/1655.Distribute-Repeating-Integers.md
@@ -0,0 +1,119 @@
+# [1655. Distribute Repeating Integers](https://leetcode.com/problems/distribute-repeating-integers/)
+
+
+## 题目
+
+You are given an array of `n` integers, `nums`, where there are at most `50` unique values in the array. You are also given an array of `m` customer order quantities, `quantity`, where `quantity[i]` is the amount of integers the `ith` customer ordered. Determine if it is possible to distribute `nums` such that:
+
+- The `ith` customer gets **exactly** `quantity[i]` integers,
+- The integers the `ith` customer gets are **all equal**, and
+- Every customer is satisfied.
+
+Return `true` *if it is possible to distribute* `nums` *according to the above conditions*.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,4], quantity = [2]
+Output: false
+Explanation: The 0th customer cannot be given two different integers.
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,2,3,3], quantity = [2]
+Output: true
+Explanation: The 0th customer is given [3,3]. The integers [1,2] are not used.
+```
+
+**Example 3**:
+
+```
+Input: nums = [1,1,2,2], quantity = [2,2]
+Output: true
+Explanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].
+```
+
+**Example 4**:
+
+```
+Input: nums = [1,1,2,3], quantity = [2,2]
+Output: false
+Explanation: Although the 0th customer could be given [1,1], the 1st customer cannot be satisfied.
+```
+
+**Example 5**:
+
+```
+Input: nums = [1,1,1,1,1], quantity = [2,3]
+Output: true
+Explanation: The 0th customer is given [1,1], and the 1st customer is given [1,1,1].
+```
+
+**Constraints**:
+
+- `n == nums.length`
+- `1 <= n <= 105`
+- `1 <= nums[i] <= 1000`
+- `m == quantity.length`
+- `1 <= m <= 10`
+- `1 <= quantity[i] <= 105`
+- There are at most `50` unique values in `nums`.
+
+## 题目大意
+
+给你一个长度为 n 的整数数组 nums ,这个数组中至多有 50 个不同的值。同时你有 m 个顾客的订单 quantity ,其中,整数 quantity[i] 是第 i 位顾客订单的数目。请你判断是否能将 nums 中的整数分配给这些顾客,且满足:
+
+- 第 i 位顾客 恰好 有 quantity[i] 个整数。
+- 第 i 位顾客拿到的整数都是 相同的 。
+- 每位顾客都满足上述两个要求。
+
+如果你可以分配 nums 中的整数满足上面的要求,那么请返回 true ,否则返回 false 。
+
+## 解题思路
+
+- 给定一个数组 nums,订单数组 quantity,要求按照订单满足顾客的需求。如果能满足输出 true,不能满足输出 false。
+- 用 DFS 记忆化暴力搜索。代码实现不难。(不知道此题为什么是 Hard)
+
+## 代码
+
+```go
+package leetcode
+
+func canDistribute(nums []int, quantity []int) bool {
+ freq := make(map[int]int)
+ for _, n := range nums {
+ freq[n]++
+ }
+ return dfs(freq, quantity)
+}
+
+func dfs(freq map[int]int, quantity []int) bool {
+ if len(quantity) == 0 {
+ return true
+ }
+ visited := make(map[int]bool)
+ for i := range freq {
+ if visited[freq[i]] {
+ continue
+ }
+ visited[freq[i]] = true
+ if freq[i] >= quantity[0] {
+ freq[i] -= quantity[0]
+ if dfs(freq, quantity[1:]) {
+ return true
+ }
+ freq[i] += quantity[0]
+ }
+ }
+ return false
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1656.Design-an-Ordered-Stream.md b/website/content/ChapterFour/1656.Design-an-Ordered-Stream.md
new file mode 100644
index 00000000..39c33d70
--- /dev/null
+++ b/website/content/ChapterFour/1656.Design-an-Ordered-Stream.md
@@ -0,0 +1,113 @@
+# [1656. Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)
+
+## 题目
+
+There is a stream of `n` `(id, value)` pairs arriving in an **arbitrary** order, where `id` is an integer between `1` and `n` and `value` is a string. No two pairs have the same `id`.
+
+Design a stream that returns the values in **increasing order of their IDs** by returning a **chunk** (list) of values after each insertion. The concatenation of all the **chunks** should result in a list of the sorted values.
+
+Implement the `OrderedStream` class:
+
+- `OrderedStream(int n)` Constructs the stream to take `n` values.
+- `String[] insert(int id, String value)` Inserts the pair `(id, value)` into the stream, then returns the **largest possible chunk** of currently inserted values that appear next in the order.
+
+**Example**:
+
+
+
+```
+Input
+["OrderedStream", "insert", "insert", "insert", "insert", "insert"]
+[[5], [3, "ccccc"], [1, "aaaaa"], [2, "bbbbb"], [5, "eeeee"], [4, "ddddd"]]
+Output
+[null, [], ["aaaaa"], ["bbbbb", "ccccc"], [], ["ddddd", "eeeee"]]
+
+Explanation
+// Note that the values ordered by ID is ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"].
+OrderedStream os = new OrderedStream(5);
+os.insert(3, "ccccc"); // Inserts (3, "ccccc"), returns [].
+os.insert(1, "aaaaa"); // Inserts (1, "aaaaa"), returns ["aaaaa"].
+os.insert(2, "bbbbb"); // Inserts (2, "bbbbb"), returns ["bbbbb", "ccccc"].
+os.insert(5, "eeeee"); // Inserts (5, "eeeee"), returns [].
+os.insert(4, "ddddd"); // Inserts (4, "ddddd"), returns ["ddddd", "eeeee"].
+// Concatentating all the chunks returned:
+// [] + ["aaaaa"] + ["bbbbb", "ccccc"] + [] + ["ddddd", "eeeee"] = ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"]
+// The resulting order is the same as the order above.
+
+```
+
+**Constraints**:
+
+- `1 <= n <= 1000`
+- `1 <= id <= n`
+- `value.length == 5`
+- `value` consists only of lowercase letters.
+- Each call to `insert` will have a unique `id.`
+- Exactly `n` calls will be made to `insert`.
+
+## 题目大意
+
+有 n 个 (id, value) 对,其中 id 是 1 到 n 之间的一个整数,value 是一个字符串。不存在 id 相同的两个 (id, value) 对。
+
+设计一个流,以 任意 顺序获取 n 个 (id, value) 对,并在多次调用时 按 id 递增的顺序 返回一些值。
+
+实现 OrderedStream 类:
+
+- OrderedStream(int n) 构造一个能接收 n 个值的流,并将当前指针 ptr 设为 1 。
+- String[] insert(int id, String value) 向流中存储新的 (id, value) 对。存储后:
+如果流存储有 id = ptr 的 (id, value) 对,则找出从 id = ptr 开始的 最长 id 连续递增序列 ,并 按顺序 返回与这些 id 关联的值的列表。然后,将 ptr 更新为最后那个 id + 1 。
+否则,返回一个空列表。
+
+## 解题思路
+
+- 设计一个具有插入操作的 Ordered Stream。insert 操作先在指定位置插入 value,然后返回当前指针 ptr 到最近一个空位置的最长连续递增字符串。如果字符串不为空,ptr 移动到非空 value 的后一个下标位置处。
+- 简单题。按照题目描述模拟即可。注意控制好 ptr 的位置。
+
+## 代码
+
+```go
+package leetcode
+
+type OrderedStream struct {
+ ptr int
+ stream []string
+}
+
+func Constructor(n int) OrderedStream {
+ ptr, stream := 1, make([]string, n+1)
+ return OrderedStream{ptr: ptr, stream: stream}
+}
+
+func (this *OrderedStream) Insert(id int, value string) []string {
+ this.stream[id] = value
+ res := []string{}
+ if this.ptr == id || this.stream[this.ptr] != "" {
+ res = append(res, this.stream[this.ptr])
+ for i := id + 1; i < len(this.stream); i++ {
+ if this.stream[i] != "" {
+ res = append(res, this.stream[i])
+ } else {
+ this.ptr = i
+ return res
+ }
+ }
+ }
+ if len(res) > 0 {
+ return res
+ }
+ return []string{}
+}
+
+/**
+ * Your OrderedStream object will be instantiated and called as such:
+ * obj := Constructor(n);
+ * param_1 := obj.Insert(id,value);
+ */
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1657.Determine-if-Two-Strings-Are-Close.md b/website/content/ChapterFour/1657.Determine-if-Two-Strings-Are-Close.md
new file mode 100644
index 00000000..82d429e8
--- /dev/null
+++ b/website/content/ChapterFour/1657.Determine-if-Two-Strings-Are-Close.md
@@ -0,0 +1,121 @@
+# [1657. Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/)
+
+
+## 题目
+
+Two strings are considered **close** if you can attain one from the other using the following operations:
+
+- Operation 1: Swap any two **existing** characters.
+ - For example, `abcde -> aecdb`
+- Operation 2: Transform **every** occurrence of one **existing** character into another **existing** character, and do the same with the other character.
+ - For example, `aacabb -> bbcbaa` (all `a`'s turn into `b`'s, and all `b`'s turn into `a`'s)
+
+You can use the operations on either string as many times as necessary.
+
+Given two strings, `word1` and `word2`, return `true` *if* `word1` *and* `word2` *are **close**, and* `false` *otherwise.*
+
+**Example 1**:
+
+```
+Input: word1 = "abc", word2 = "bca"
+Output: true
+Explanation: You can attain word2 from word1 in 2 operations.
+Apply Operation 1: "abc" -> "acb"
+Apply Operation 1: "acb" -> "bca"
+
+```
+
+**Example 2**:
+
+```
+Input: word1 = "a", word2 = "aa"
+Output: false
+Explanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.
+
+```
+
+**Example 3**:
+
+```
+Input: word1 = "cabbba", word2 = "abbccc"
+Output: true
+Explanation: You can attain word2 from word1 in 3 operations.
+Apply Operation 1: "cabbba" -> "caabbb"
+Apply Operation 2: "caabbb" -> "baaccc"
+Apply Operation 2: "baaccc" -> "abbccc"
+
+```
+
+**Example 4**:
+
+```
+Input: word1 = "cabbba", word2 = "aabbss"
+Output: false
+Explanation: It is impossible to attain word2 from word1, or vice versa, in any amount of operations.
+
+```
+
+**Constraints**:
+
+- `1 <= word1.length, word2.length <= 105`
+- `word1` and `word2` contain only lowercase English letters.
+
+## 题目大意
+
+如果可以使用以下操作从一个字符串得到另一个字符串,则认为两个字符串 接近 :
+
+- 操作 1:交换任意两个 现有 字符。例如,abcde -> aecdb
+- 操作 2:将一个 现有 字符的每次出现转换为另一个 现有 字符,并对另一个字符执行相同的操作。例如,aacabb -> bbcbaa(所有 a 转化为 b ,而所有的 b 转换为 a )
+
+你可以根据需要对任意一个字符串多次使用这两种操作。给你两个字符串,word1 和 word2 。如果 word1 和 word2 接近 ,就返回 true ;否则,返回 false 。
+
+## 解题思路
+
+- 判断 2 个字符串是否“接近”。“接近”的定义是能否通过交换 2 个字符或者 2 个字母互换,从一个字符串变换成另外一个字符串,如果存在这样的变换,即是“接近”。
+- 先统计 2 个字符串的 26 个字母的频次,如果频次有不相同的,直接返回 false。在频次相同的情况下,再从小到大排序,再次扫描判断频次是否相同。
+- 注意几种特殊情况:频次相同,再判断字母交换是否合法存在,如果字母不存在,输出 false。例如测试文件中的 case 5 。出现频次个数相同,但是频次不同。例如测试文件中的 case 6 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "sort"
+)
+
+func closeStrings(word1 string, word2 string) bool {
+ if len(word1) != len(word2) {
+ return false
+ }
+ freqCount1, freqCount2 := make([]int, 26), make([]int, 26)
+ for _, c := range word1 {
+ freqCount1[c-97]++
+ }
+ for _, c := range word2 {
+ freqCount2[c-97]++
+ }
+ for i := 0; i < 26; i++ {
+ if (freqCount1[i] == freqCount2[i]) ||
+ (freqCount1[i] > 0 && freqCount2[i] > 0) {
+ continue
+ }
+ return false
+ }
+ sort.Ints(freqCount1)
+ sort.Ints(freqCount2)
+ for i := 0; i < 26; i++ {
+ if freqCount1[i] != freqCount2[i] {
+ return false
+ }
+ }
+ return true
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md b/website/content/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md
new file mode 100644
index 00000000..955f6f2b
--- /dev/null
+++ b/website/content/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md
@@ -0,0 +1,103 @@
+# [1658. Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/)
+
+
+## 题目
+
+You are given an integer array `nums` and an integer `x`. In one operation, you can either remove the leftmost or the rightmost element from the array `nums` and subtract its value from `x`. Note that this **modifies** the array for future operations.
+
+Return *the **minimum number** of operations to reduce* `x` *to **exactly*** `0` *if it's possible, otherwise, return* `1`.
+
+**Example 1**:
+
+```
+Input: nums = [1,1,4,2,3], x = 5
+Output: 2
+Explanation: The optimal solution is to remove the last two elements to reduce x to zero.
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [5,6,7,8,9], x = 4
+Output: -1
+
+```
+
+**Example 3**:
+
+```
+Input: nums = [3,2,20,1,1,3], x = 10
+Output: 5
+Explanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.
+
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 104`
+- `1 <= x <= 109`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个整数 x 。每一次操作时,你应当移除数组 nums 最左边或最右边的元素,然后从 x 中减去该元素的值。请注意,需要 修改 数组以供接下来的操作使用。如果可以将 x 恰好 减到 0 ,返回 最小操作数 ;否则,返回 -1 。
+
+## 解题思路
+
+- 给定一个数组 nums 和一个整数 x,要求从数组两端分别移除一些数,使得这些数加起来正好等于整数 x,要求输出最小操作数。
+- 要求输出最小操作数,即数组两头的数字个数最少,并且加起来和正好等于整数 x。由于在数组的两头,用 2 个指针分别操作不太方便。我当时解题的时候的思路是把它变成循环数组,这样两边的指针就在一个区间内了。利用滑动窗口找到一个最小的窗口,使得窗口内的累加和等于整数 k。这个方法可行,但是代码挺多的。
+- 有没有更优美的方法呢?有的。要想两头的长度最少,也就是中间这段的长度最大。这样就转换成直接在数组上使用滑动窗口求解,累加和等于一个固定值的连续最长的子数组。
+- 和这道题类似思路的题目,209,1040(循环数组),325。强烈推荐这 3 题。
+
+## 代码
+
+```go
+package leetcode
+
+func minOperations(nums []int, x int) int {
+ total := 0
+ for _, n := range nums {
+ total += n
+ }
+ target := total - x
+ if target < 0 {
+ return -1
+ }
+ if target == 0 {
+ return len(nums)
+ }
+ left, right, sum, res := 0, 0, 0, -1
+ for right < len(nums) {
+ if sum < target {
+ sum += nums[right]
+ right++
+ }
+ for sum >= target {
+ if sum == target {
+ res = max(res, right-left)
+ }
+ sum -= nums[left]
+ left++
+ }
+ }
+ if res == -1 {
+ return -1
+ }
+ return len(nums) - res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1659.Maximize-Grid-Happiness.md b/website/content/ChapterFour/1659.Maximize-Grid-Happiness.md
new file mode 100644
index 00000000..73f3ed57
--- /dev/null
+++ b/website/content/ChapterFour/1659.Maximize-Grid-Happiness.md
@@ -0,0 +1,192 @@
+# [1659. Maximize Grid Happiness](https://leetcode.com/problems/maximize-grid-happiness/)
+
+## 题目
+
+You are given four integers, `m`, `n`, `introvertsCount`, and `extrovertsCount`. You have an `m x n` grid, and there are two types of people: introverts and extroverts. There are `introvertsCount` introverts and `extrovertsCount` extroverts.
+
+You should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you **do not** have to have all the people living in the grid.
+
+The **happiness** of each person is calculated as follows:
+
+- Introverts **start** with `120` happiness and **lose** `30` happiness for each neighbor (introvert or extrovert).
+- Extroverts **start** with `40` happiness and **gain** `20` happiness for each neighbor (introvert or extrovert).
+
+Neighbors live in the directly adjacent cells north, east, south, and west of a person's cell.
+
+The **grid happiness** is the **sum** of each person's happiness. Return *the **maximum possible grid happiness**.*
+
+**Example 1**:
+
+
+
+```
+Input: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2
+Output: 240
+Explanation: Assume the grid is 1-indexed with coordinates (row, column).
+We can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).
+- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120
+- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60
+- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60
+The grid happiness is 120 + 60 + 60 = 240.
+The above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.
+```
+
+**Example 2**:
+
+```
+Input: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1
+Output: 260
+Explanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).
+- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90
+- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80
+- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90
+The grid happiness is 90 + 80 + 90 = 260.
+```
+
+**Example 3**:
+
+```
+Input: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0
+Output: 240
+```
+
+**Constraints**:
+
+- `1 <= m, n <= 5`
+- `0 <= introvertsCount, extrovertsCount <= min(m * n, 6)`
+
+## 题目大意
+
+给你四个整数 m、n、introvertsCount 和 extrovertsCount 。有一个 m x n 网格,和两种类型的人:内向的人和外向的人。总共有 introvertsCount 个内向的人和 extrovertsCount 个外向的人。请你决定网格中应当居住多少人,并为每个人分配一个网格单元。 注意,不必 让所有人都生活在网格中。每个人的 幸福感 计算如下:
+
+- 内向的人 开始 时有 120 个幸福感,但每存在一个邻居(内向的或外向的)他都会 失去 30 个幸福感。
+- 外向的人 开始 时有 40 个幸福感,每存在一个邻居(内向的或外向的)他都会 得到 20 个幸福感。
+
+邻居是指居住在一个人所在单元的上、下、左、右四个直接相邻的单元中的其他人。网格幸福感 是每个人幸福感的 总和 。 返回 最大可能的网格幸福感 。
+
+## 解题思路
+
+- 给出 `m` x `n` 网格和两种人,要求如何安排这两种人能使得网格的得分最大。两种人有各自的初始分,相邻可能会加分也有可能减分。
+- 这一题状态很多。首先每个格子有 3 种状态,那么每一行有 3^6 = 729 种不同的状态。每行行内分数变化值可能是 -60(两个内向),+40(两个外向),-10(一个内向一个外向)。两行行间分数变化值可能是 -60(两个内向),+40(两个外向),-10(一个内向一个外向)。那么我们可以把每行的状态压缩成一个三进制,那么网格就变成了一维,每两个三进制之间的关系是行间关系,每个三进制内部还需要根据内向和外向的人数决定行内最终分数。定义 `dp[lineStatusLast][row][introvertsCount][extrovertsCount]` 代表在上一行 `row - 1` 的状态是 `lineStatusLast` 的情况下,当前枚举到了第 `row` 行,内向还有 `introvertsCount` 个人,外向还有 `extrovertsCount` 个人能获得的最大分数。状态转移方程是 `dp[lineStatusLast(row-1)][row][introvertsCount][extrovertsCount] = max{dp[lineStatusLast(row)][row+1][introvertsCount - countIC(lineStatusLast(row)) ][extrovertsCount - countEC(lineStatusLast(row)) ] + scoreInner(lineStatusLast(row)) + scoreOuter(lineStatusLast(row-1),lineStatusLast(row))}` ,这里有 2 个统计函数,`countIC` 是统计当前行状态三进制里面有多少个内向人。`countEC` 是统计当前行状态三进制里面有多少个外向人。`scoreInner` 是计算当前行状态三进制的行内分数。`scoreOuter` 是计算 `row -1` 行和 `row` 行之间的行间分数。
+- 由于这个状态转移方程的计算量是巨大的。所以需要预先初始化一些计算结果。比如把 729 中行状态分别对应的行内、行间的分数都计算好,在动态规划状态转移的时候,直接查表获取分数即可。这样我们在深搜的时候,利用 dp 的记忆化,可以大幅减少时间复杂度。
+- 题目中还提到,人数可以不用完。如果 `introvertsCount = 0`, `extrovertsCount = 0` ,即人数都用完了的情况,这时候 `dp = 0`。如果 `row = m`,即已经枚举完了所有行,那么不管剩下多少人,这一行的 `dp = 0` 。
+- 初始化的时候,注意,特殊处理 0 的情况,0 行 0 列都初始化为 -1 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math"
+)
+
+func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int {
+ // lineStatus 将每一行中 3 种状态进行编码,空白 - 0,内向人 - 1,外向人 - 2,每行状态用三进制表示
+ // lineStatusList[729][6] 每一行的三进制表示
+ // introvertsCountInner[729] 每一个 lineStatus 包含的内向人数
+ // extrovertsCountInner[729] 每一个 lineStatus 包含的外向人数
+ // scoreInner[729] 每一个 lineStatus 包含的行内得分(只统计 lineStatus 本身的得分,不包括它与上一行的)
+ // scoreOuter[729][729] 每一个 lineStatus 包含的行外得分
+ // dp[上一行的 lineStatus][当前处理到的行][剩余的内向人数][剩余的外向人数]
+ n3, lineStatus, introvertsCountInner, extrovertsCountInner, scoreInner, scoreOuter, lineStatusList, dp := math.Pow(3.0, float64(n)), 0, [729]int{}, [729]int{}, [729]int{}, [729][729]int{}, [729][6]int{}, [729][6][7][7]int{}
+ for i := 0; i < 729; i++ {
+ lineStatusList[i] = [6]int{}
+ }
+ for i := 0; i < 729; i++ {
+ dp[i] = [6][7][7]int{}
+ for j := 0; j < 6; j++ {
+ dp[i][j] = [7][7]int{}
+ for k := 0; k < 7; k++ {
+ dp[i][j][k] = [7]int{-1, -1, -1, -1, -1, -1, -1}
+ }
+ }
+ }
+ // 预处理
+ for lineStatus = 0; lineStatus < int(n3); lineStatus++ {
+ tmp := lineStatus
+ for i := 0; i < n; i++ {
+ lineStatusList[lineStatus][i] = tmp % 3
+ tmp /= 3
+ }
+ introvertsCountInner[lineStatus], extrovertsCountInner[lineStatus], scoreInner[lineStatus] = 0, 0, 0
+ for i := 0; i < n; i++ {
+ if lineStatusList[lineStatus][i] != 0 {
+ // 个人分数
+ if lineStatusList[lineStatus][i] == 1 {
+ introvertsCountInner[lineStatus]++
+ scoreInner[lineStatus] += 120
+ } else if lineStatusList[lineStatus][i] == 2 {
+ extrovertsCountInner[lineStatus]++
+ scoreInner[lineStatus] += 40
+ }
+ // 行内分数
+ if i-1 >= 0 {
+ scoreInner[lineStatus] += closeScore(lineStatusList[lineStatus][i], lineStatusList[lineStatus][i-1])
+ }
+ }
+ }
+ }
+ // 行外分数
+ for lineStatus0 := 0; lineStatus0 < int(n3); lineStatus0++ {
+ for lineStatus1 := 0; lineStatus1 < int(n3); lineStatus1++ {
+ scoreOuter[lineStatus0][lineStatus1] = 0
+ for i := 0; i < n; i++ {
+ scoreOuter[lineStatus0][lineStatus1] += closeScore(lineStatusList[lineStatus0][i], lineStatusList[lineStatus1][i])
+ }
+ }
+ }
+ return dfs(0, 0, introvertsCount, extrovertsCount, m, int(n3), &dp, &introvertsCountInner, &extrovertsCountInner, &scoreInner, &scoreOuter)
+}
+
+// 如果 x 和 y 相邻,需要加上的分数
+func closeScore(x, y int) int {
+ if x == 0 || y == 0 {
+ return 0
+ }
+ // 两个内向的人,每个人要 -30,一共 -60
+ if x == 1 && y == 1 {
+ return -60
+ }
+ if x == 2 && y == 2 {
+ return 40
+ }
+ return -10
+}
+
+// dfs(上一行的 lineStatus,当前处理到的行,剩余的内向人数,剩余的外向人数)
+func dfs(lineStatusLast, row, introvertsCount, extrovertsCount, m, n3 int, dp *[729][6][7][7]int, introvertsCountInner, extrovertsCountInner, scoreInner *[729]int, scoreOuter *[729][729]int) int {
+ // 边界条件:如果已经处理完,或者没有人了
+ if row == m || introvertsCount+extrovertsCount == 0 {
+ return 0
+ }
+ // 记忆化
+ if dp[lineStatusLast][row][introvertsCount][extrovertsCount] != -1 {
+ return dp[lineStatusLast][row][introvertsCount][extrovertsCount]
+ }
+ best := 0
+ for lineStatus := 0; lineStatus < n3; lineStatus++ {
+ if introvertsCountInner[lineStatus] > introvertsCount || extrovertsCountInner[lineStatus] > extrovertsCount {
+ continue
+ }
+ score := scoreInner[lineStatus] + scoreOuter[lineStatus][lineStatusLast]
+ best = max(best, score+dfs(lineStatus, row+1, introvertsCount-introvertsCountInner[lineStatus], extrovertsCount-extrovertsCountInner[lineStatus], m, n3, dp, introvertsCountInner, extrovertsCountInner, scoreInner, scoreOuter))
+ }
+ dp[lineStatusLast][row][introvertsCount][extrovertsCount] = best
+ return best
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1662.Check-If-Two-String-Arrays-are-Equivalent.md b/website/content/ChapterFour/1662.Check-If-Two-String-Arrays-are-Equivalent.md
new file mode 100644
index 00000000..84931259
--- /dev/null
+++ b/website/content/ChapterFour/1662.Check-If-Two-String-Arrays-are-Equivalent.md
@@ -0,0 +1,72 @@
+# [1662. Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)
+
+
+## 题目
+
+Given two string arrays `word1` and `word2`, return **`true` *if the two arrays **represent** the same string, and* `false` *otherwise.*
+
+A string is **represented** by an array if the array elements concatenated **in order** forms the string.
+
+**Example 1**:
+
+```
+Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
+Output: true
+Explanation:
+word1 represents string "ab" + "c" -> "abc"
+word2 represents string "a" + "bc" -> "abc"
+The strings are the same, so return true.
+```
+
+**Example 2**:
+
+```
+Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
+Output: false
+```
+
+**Example 3**:
+
+```
+Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"]
+Output: true
+```
+
+**Constraints**:
+
+- `1 <= word1.length, word2.length <= 103`
+- `1 <= word1[i].length, word2[i].length <= 103`
+- `1 <= sum(word1[i].length), sum(word2[i].length) <= 103`
+- `word1[i]` and `word2[i]` consist of lowercase letters.
+
+## 题目大意
+
+给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。数组表示的字符串 是由数组中的所有元素 按顺序 连接形成的字符串。
+
+## 解题思路
+
+- 简单题,依次拼接 2 个数组内的字符串,然后比较 str1 和 str2 是否相同即可。
+
+## 代码
+
+```go
+package leetcode
+
+func arrayStringsAreEqual(word1 []string, word2 []string) bool {
+ str1, str2 := "", ""
+ for i := 0; i < len(word1); i++ {
+ str1 += word1[i]
+ }
+ for i := 0; i < len(word2); i++ {
+ str2 += word2[i]
+ }
+ return str1 == str2
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1663.Smallest-String-With-A-Given-Numeric-Value.md b/website/content/ChapterFour/1663.Smallest-String-With-A-Given-Numeric-Value.md
new file mode 100644
index 00000000..9eb095dc
--- /dev/null
+++ b/website/content/ChapterFour/1663.Smallest-String-With-A-Given-Numeric-Value.md
@@ -0,0 +1,111 @@
+# [1663. Smallest String With A Given Numeric Value](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/)
+
+## 题目
+
+The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on.
+
+The **numeric value** of a **string** consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string `"abe"` is equal to `1 + 2 + 5 = 8`.
+
+You are given two integers `n` and `k`. Return *the **lexicographically smallest string** with **length** equal to `n` and **numeric value** equal to `k`.*
+
+Note that a string `x` is lexicographically smaller than string `y` if `x` comes before `y` in dictionary order, that is, either `x` is a prefix of `y`, or if `i` is the first position such that `x[i] != y[i]`, then `x[i]` comes before `y[i]` in alphabetic order.
+
+**Example 1**:
+
+```
+Input: n = 3, k = 27
+Output: "aay"
+Explanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.
+```
+
+**Example 2**:
+
+```
+Input: n = 5, k = 73
+Output: "aaszz"
+```
+
+**Constraints**:
+
+- `1 <= n <= 105`
+- `n <= k <= 26 * n`
+
+## 题目大意
+
+小写字符 的 数值 是它在字母表中的位置(从 1 开始),因此 a 的数值为 1 ,b 的数值为 2 ,c 的数值为 3 ,以此类推。字符串由若干小写字符组成,字符串的数值 为各字符的数值之和。例如,字符串 "abe" 的数值等于 1 + 2 + 5 = 8 。给你两个整数 n 和 k 。返回 长度 等于 n 且 数值 等于 k 的 字典序最小 的字符串。注意,如果字符串 x 在字典排序中位于 y 之前,就认为 x 字典序比 y 小,有以下两种情况:
+
+- x 是 y 的一个前缀;
+- 如果 i 是 x[i] != y[i] 的第一个位置,且 x[i] 在字母表中的位置比 y[i] 靠前。
+
+## 解题思路
+
+- 给出 n 和 k,要求找到字符串长度为 n,字母在字母表内位置总和为 k 的最小字典序字符串。
+- 这一题笔者读完题,比赛的时候直接用 DFS 撸了一版。赛后看了时间复杂度马马虎虎,感觉还有优化的空间。DFS 会遍历出所有的解,实际上这一题只要求最小字典序,所以 DFS 剪枝的时候要加上判断字典序的判断,如果新添加进来的字母比已经保存的字符串的相应位置上的字母字典序大,那么就直接 return,这个答案一定不会是最小字典序。代码见解法二
+- 想到这里,其实 DFS 不必要,直接用 for 循环就可找到最小字典序的字符串。代码见解法一。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 贪心
+func getSmallestString(n int, k int) string {
+ res := make([]rune, n)
+ for i := n - 1; i >= 0; i-- {
+ diff := k - i
+ if diff >= 26 {
+ // Need to add z
+ res[i] = 'z'
+ k = k - 26
+ } else {
+ res[i] = rune('a' + diff - 1)
+ k = k - diff
+ }
+ }
+ return string(res)
+}
+
+// 解法二 DFS
+func getSmallestString1(n int, k int) string {
+ if n == 0 {
+ return ""
+ }
+ res, c := "", []byte{}
+ findSmallestString(0, n, k, 0, c, &res)
+ return res
+}
+
+func findSmallestString(value int, length, k, index int, str []byte, res *string) {
+ if len(str) == length && value == k {
+ tmp := string(str)
+ if (*res) == "" {
+ *res = tmp
+ }
+ if tmp < *res && *res != "" {
+ *res = tmp
+ }
+ return
+ }
+ if len(str) >= index && (*res) != "" && str[index-1] > (*res)[index-1] {
+ return
+ }
+ for j := 0; j < 26; j++ {
+ if k-value > (length-len(str))*26 || value > k {
+ return
+ }
+ str = append(str, byte(int('a')+j))
+ value += j + 1
+ findSmallestString(value, length, k, index+1, str, res)
+ str = str[:len(str)-1]
+ value -= j + 1
+
+ }
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1664.Ways-to-Make-a-Fair-Array.md b/website/content/ChapterFour/1664.Ways-to-Make-a-Fair-Array.md
new file mode 100644
index 00000000..45d86fc9
--- /dev/null
+++ b/website/content/ChapterFour/1664.Ways-to-Make-a-Fair-Array.md
@@ -0,0 +1,123 @@
+# [1664. Ways to Make a Fair Array](https://leetcode.com/problems/ways-to-make-a-fair-array/)
+
+
+## 题目
+
+You are given an integer array `nums`. You can choose **exactly one** index (**0-indexed**) and remove the element. Notice that the index of the elements may change after the removal.
+
+For example, if `nums = [6,1,7,4,1]`:
+
+- Choosing to remove index `1` results in `nums = [6,7,4,1]`.
+- Choosing to remove index `2` results in `nums = [6,1,4,1]`.
+- Choosing to remove index `4` results in `nums = [6,1,7,4]`.
+
+An array is **fair** if the sum of the odd-indexed values equals the sum of the even-indexed values.
+
+Return the ***number** of indices that you could choose such that after the removal,* `nums` *is **fair**.*
+
+**Example 1**:
+
+```
+Input: nums = [2,1,6,4]
+Output: 1
+Explanation:
+Remove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.
+Remove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.
+Remove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.
+Remove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.
+There is 1 index that you can remove to make nums fair.
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,1,1]
+Output: 3
+Explanation: You can remove any index and the remaining array is fair.
+```
+
+**Example 3**:
+
+```
+Input: nums = [1,2,3]
+Output: 0
+Explanation: You cannot make a fair array after removing any index.
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 104`
+
+## 题目大意
+
+给你一个整数数组 nums 。你需要选择 恰好 一个下标(下标从 0 开始)并删除对应的元素。请注意剩下元素的下标可能会因为删除操作而发生改变。
+
+比方说,如果 nums = [6,1,7,4,1] ,那么:
+
+- 选择删除下标 1 ,剩下的数组为 nums = [6,7,4,1] 。
+- 选择删除下标 2 ,剩下的数组为 nums = [6,1,4,1] 。
+- 选择删除下标 4 ,剩下的数组为 nums = [6,1,7,4] 。
+
+如果一个数组满足奇数下标元素的和与偶数下标元素的和相等,该数组就是一个 平衡数组 。请你返回删除操作后,剩下的数组 nums 是 平衡数组 的 方案数 。
+
+## 解题思路
+
+- 给定一个数组 nums,要求输出仅删除一个元素以后能使得整个数组平衡的方案数。平衡的定义是奇数下标元素总和等于偶数下标元素总和。
+- 这一题如果暴力解答,会超时。原因是每次删除元素以后,都重新计算奇偶数位总和比较耗时。应该利用前面计算过的累加和,推导出此次删除元素以后的情况。这样修改以后就不超时了。具体的,如果删除的是元素是奇数位,这个下标的前缀和不变,要变化的是后面的。删除元素后面,原来偶数位的总和变成了奇数位了,原来奇数位的总和变成偶数位了。删除元素后面这半段的总和可以用前缀和计算出来,奇数位的总和减去删除元素的前缀和,就得到了删除元素后面的后缀和。通过这个办法就可以得到删除元素后面的,奇数位总和,偶数位总和。注意这个后缀和是包含了删除元素的。所以最后需要判断删除元素是奇数位还是偶数位,如果是奇数位,那么在计算出来的偶数和上再减去这个删除元素;如果是偶数位,就在计算出来的奇数和上再减去这个删除元素。代码见解法二。
+- 这一题还有一种更简洁的写法,就是解法一了。通过了解法二的思考,我们可以知道,每次变换以后的操作可以抽象出来,即三步,减去一个数,判断是否相等,再加上一个数。只不过这三步在解法二中都去判断了奇偶性。如果我们不判断奇偶性,那么代码就可以写成解法一的样子。为什么可以不用管奇偶性呢?因为每次删除一个元素以后,下次再删除,奇偶就发生颠倒了,上次的奇数和到了下次就是偶数和了。想通这一点就可以把代码写成解法一的样子。
+
+## 代码
+
+```go
+// 解法一 超简洁写法
+func waysToMakeFair(nums []int) int {
+ sum, res := [2]int{}, 0
+ for i := 0; i < len(nums); i++ {
+ sum[i%2] += nums[i]
+ }
+ for i := 0; i < len(nums); i++ {
+ sum[i%2] -= nums[i]
+ if sum[i%2] == sum[1-(i%2)] {
+ res++
+ }
+ sum[1-(i%2)] += nums[i]
+ }
+ return res
+}
+
+// 解法二 前缀和,后缀和
+func waysToMakeFair1(nums []int) int {
+ evenPrefix, oddPrefix, evenSuffix, oddSuffix, res := 0, 0, 0, 0, 0
+ for i := 0; i < len(nums); i++ {
+ if i%2 == 0 {
+ evenSuffix += nums[i]
+ } else {
+ oddSuffix += nums[i]
+ }
+ }
+ for i := 0; i < len(nums); i++ {
+ if i%2 == 0 {
+ evenSuffix -= nums[i]
+ } else {
+ oddSuffix -= nums[i]
+ }
+ if (evenPrefix + oddSuffix) == (oddPrefix + evenSuffix) {
+ res++
+ }
+ if i%2 == 0 {
+ evenPrefix += nums[i]
+ } else {
+ oddPrefix += nums[i]
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1665.Minimum-Initial-Energy-to-Finish-Tasks.md b/website/content/ChapterFour/1665.Minimum-Initial-Energy-to-Finish-Tasks.md
new file mode 100644
index 00000000..6518e98a
--- /dev/null
+++ b/website/content/ChapterFour/1665.Minimum-Initial-Energy-to-Finish-Tasks.md
@@ -0,0 +1,135 @@
+# [1665. Minimum Initial Energy to Finish Tasks](https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/)
+
+## 题目
+
+You are given an array `tasks` where `tasks[i] = [actuali, minimumi]`:
+
+- `actuali` is the actual amount of energy you **spend to finish** the `ith` task.
+- `minimumi` is the minimum amount of energy you **require to begin** the `ith` task.
+
+For example, if the task is `[10, 12]` and your current energy is `11`, you cannot start this task. However, if your current energy is `13`, you can complete this task, and your energy will be `3` after finishing it.
+
+You can finish the tasks in **any order** you like.
+
+Return *the **minimum** initial amount of energy you will need* *to finish all the tasks*.
+
+**Example 1**:
+
+```
+Input: tasks = [[1,2],[2,4],[4,8]]
+Output: 8
+Explanation:
+Starting with 8 energy, we finish the tasks in the following order:
+ - 3rd task. Now energy = 8 - 4 = 4.
+ - 2nd task. Now energy = 4 - 2 = 2.
+ - 1st task. Now energy = 2 - 1 = 1.
+Notice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.
+```
+
+**Example 2**:
+
+```
+Input: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]
+Output: 32
+Explanation:
+Starting with 32 energy, we finish the tasks in the following order:
+ - 1st task. Now energy = 32 - 1 = 31.
+ - 2nd task. Now energy = 31 - 2 = 29.
+ - 3rd task. Now energy = 29 - 10 = 19.
+ - 4th task. Now energy = 19 - 10 = 9.
+ - 5th task. Now energy = 9 - 8 = 1.
+```
+
+**Example 3**:
+
+```
+Input: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]
+Output: 27
+Explanation:
+Starting with 27 energy, we finish the tasks in the following order:
+ - 5th task. Now energy = 27 - 5 = 22.
+ - 2nd task. Now energy = 22 - 2 = 20.
+ - 3rd task. Now energy = 20 - 3 = 17.
+ - 1st task. Now energy = 17 - 1 = 16.
+ - 4th task. Now energy = 16 - 4 = 12.
+ - 6th task. Now energy = 12 - 6 = 6.
+
+```
+
+**Constraints**:
+
+- `1 <= tasks.length <= 105`
+- `1 <= actuali <= minimumi <= 104`
+
+## 题目大意
+
+给你一个任务数组 tasks ,其中 tasks[i] = [actuali, minimumi] :
+
+- actual i 是完成第 i 个任务 需要耗费 的实际能量。
+- minimum i 是开始第 i 个任务前需要达到的最低能量。
+
+比方说,如果任务为 [10, 12] 且你当前的能量为 11 ,那么你不能开始这个任务。如果你当前的能量为 13 ,你可以完成这个任务,且完成它后剩余能量为 3 。你可以按照 任意顺序 完成任务。请你返回完成所有任务的 最少 初始能量。
+
+## 解题思路
+
+- 给出一个 task 数组,每个元素代表一个任务,每个任务有实际消费能量值和开始这个任务需要的最低能量。要求输出能完成所有任务的最少初始能量。
+- 这一题直觉是贪心。先将任务按照 `minimum - actual` 进行排序。先完成差值大的任务,那么接下来的能量能最大限度的满足接下来的任务。这样可能完成所有任务的可能性越大。循环任务数组的时候,保存当前能量在 `cur` 中,如果当前能量不够开启下一个任务,那么这个差值就是需要弥补的,这些能量就是最少初始能量中的,所以加上这些差值能量。如果当前能量可以开启下一个任务,那么就更新当前能量,减去实际消耗的能量以后,再继续循环。循环结束就能得到最少初始能量了。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "sort"
+)
+
+func minimumEffort(tasks [][]int) int {
+ sort.Sort(Task(tasks))
+ res, cur := 0, 0
+ for _, t := range tasks {
+ if t[1] > cur {
+ res += t[1] - cur
+ cur = t[1] - t[0]
+ } else {
+ cur -= t[0]
+ }
+ }
+ return res
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+// Task define
+type Task [][]int
+
+func (task Task) Len() int {
+ return len(task)
+}
+
+func (task Task) Less(i, j int) bool {
+ t1, t2 := task[i][1]-task[i][0], task[j][1]-task[j][0]
+ if t1 != t2 {
+ return t2 < t1
+ }
+ return task[j][1] < task[i][1]
+}
+
+func (task Task) Swap(i, j int) {
+ t := task[i]
+ task[i] = task[j]
+ task[j] = t
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1668.Maximum-Repeating-Substring.md b/website/content/ChapterFour/1668.Maximum-Repeating-Substring.md
new file mode 100644
index 00000000..91c3fd9d
--- /dev/null
+++ b/website/content/ChapterFour/1668.Maximum-Repeating-Substring.md
@@ -0,0 +1,76 @@
+# [1668. Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring/)
+
+
+## 题目
+
+For a string `sequence`, a string `word` is **`k`-repeating** if `word` concatenated `k` times is a substring of `sequence`. The `word`'s **maximum `k`-repeating value** is the highest value `k` where `word` is `k`-repeating in `sequence`. If `word` is not a substring of `sequence`, `word`'s maximum `k`-repeating value is `0`.
+
+Given strings `sequence` and `word`, return *the **maximum `k`-repeating value** of `word` in `sequence`*.
+
+**Example 1**:
+
+```
+Input: sequence = "ababc", word = "ab"
+Output: 2
+Explanation: "abab" is a substring in "ababc".
+```
+
+**Example 2**:
+
+```
+Input: sequence = "ababc", word = "ba"
+Output: 1
+Explanation: "ba" is a substring in "ababc". "baba" is not a substring in "ababc".
+```
+
+**Example 3**:
+
+```
+Input: sequence = "ababc", word = "ac"
+Output: 0
+Explanation: "ac" is not a substring in "ababc".
+```
+
+**Constraints**:
+
+- `1 <= sequence.length <= 100`
+- `1 <= word.length <= 100`
+- `sequence` and `word` contains only lowercase English letters.
+
+## 题目大意
+
+给你一个字符串 sequence ,如果字符串 word 连续重复 k 次形成的字符串是 sequence 的一个子字符串,那么单词 word 的 重复值为 k 。单词 word 的 最大重复值 是单词 word 在 sequence 中最大的重复值。如果 word 不是 sequence 的子串,那么重复值 k 为 0 。给你一个字符串 sequence 和 word ,请你返回 最大重复值 k 。
+
+## 解题思路
+
+- 循环叠加构造 `word`,每次构造出新的 `word` 都在 `sequence` 查找一次,如果找到就输出叠加次数,否则继续叠加构造,直到字符串长度和 `sequence` 一样长,最终都没有找到则输出 0 。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "strings"
+)
+
+func maxRepeating(sequence string, word string) int {
+ for i := len(sequence) / len(word); i >= 0; i-- {
+ tmp := ""
+ for j := 0; j < i; j++ {
+ tmp += word
+ }
+ if strings.Contains(sequence, tmp) {
+ return i
+ }
+ }
+ return 0
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1669.Merge-In-Between-Linked-Lists.md b/website/content/ChapterFour/1669.Merge-In-Between-Linked-Lists.md
new file mode 100644
index 00000000..fdd831d1
--- /dev/null
+++ b/website/content/ChapterFour/1669.Merge-In-Between-Linked-Lists.md
@@ -0,0 +1,82 @@
+# [1669. Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists/)
+
+
+## 题目
+
+You are given two linked lists: `list1` and `list2` of sizes `n` and `m` respectively.
+
+Remove `list1`'s nodes from the `ath` node to the `bth` node, and put `list2` in their place.
+
+The blue edges and nodes in the following figure incidate the result:
+
+
+
+*Build the result list and return its head.*
+
+**Example 1**:
+
+
+
+```
+Input: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]
+Output: [0,1,2,1000000,1000001,1000002,5]
+Explanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.
+
+```
+
+**Example 2**:
+
+
+
+```
+Input: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]
+Output: [0,1,1000000,1000001,1000002,1000003,1000004,6]
+Explanation: The blue edges and nodes in the above figure indicate the result.
+
+```
+
+**Constraints**:
+
+- `3 <= list1.length <= 104`
+- `1 <= a <= b < list1.length - 1`
+- `1 <= list2.length <= 104`
+
+## 题目大意
+
+给你两个链表 list1 和 list2 ,它们包含的元素分别为 n 个和 m 个。请你将 list1 中第 a 个节点到第 b 个节点删除,并将list2 接在被删除节点的位置。
+
+## 解题思路
+
+- 简单题,考查链表的基本操作。此题注意 a == b 的情况。
+
+## 代码
+
+```go
+func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {
+ n := list1
+ var startRef, endRef *ListNode
+ for i := 0; i <= b; i++ {
+ if i == a-1 {
+ startRef = n
+ }
+ if i == b {
+ endRef = n
+ }
+ n = n.Next
+ }
+ startRef.Next = list2
+ n = list2
+ for n.Next != nil {
+ n = n.Next
+ }
+ n.Next = endRef.Next
+ return list1
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1670.Design-Front-Middle-Back-Queue.md b/website/content/ChapterFour/1670.Design-Front-Middle-Back-Queue.md
new file mode 100644
index 00000000..533fa366
--- /dev/null
+++ b/website/content/ChapterFour/1670.Design-Front-Middle-Back-Queue.md
@@ -0,0 +1,179 @@
+# [1670. Design Front Middle Back Queue](https://leetcode.com/problems/design-front-middle-back-queue/)
+
+
+## 题目
+
+Design a queue that supports `push` and `pop` operations in the front, middle, and back.
+
+Implement the `FrontMiddleBack` class:
+
+- `FrontMiddleBack()` Initializes the queue.
+- `void pushFront(int val)` Adds `val` to the **front** of the queue.
+- `void pushMiddle(int val)` Adds `val` to the **middle** of the queue.
+- `void pushBack(int val)` Adds `val` to the **back** of the queue.
+- `int popFront()` Removes the **front** element of the queue and returns it. If the queue is empty, return `1`.
+- `int popMiddle()` Removes the **middle** element of the queue and returns it. If the queue is empty, return `1`.
+- `int popBack()` Removes the **back** element of the queue and returns it. If the queue is empty, return `1`.
+
+**Notice** that when there are **two** middle position choices, the operation is performed on the **frontmost** middle position choice. For example:
+
+- Pushing `6` into the middle of `[1, 2, 3, 4, 5]` results in `[1, 2, 6, 3, 4, 5]`.
+- Popping the middle from `[1, 2, 3, 4, 5, 6]` returns `3` and results in `[1, 2, 4, 5, 6]`.
+
+**Example 1**:
+
+```
+Input:
+["FrontMiddleBackQueue", "pushFront", "pushBack", "pushMiddle", "pushMiddle", "popFront", "popMiddle", "popMiddle", "popBack", "popFront"]
+[[], [1], [2], [3], [4], [], [], [], [], []]
+Output:
+[null, null, null, null, null, 1, 3, 4, 2, -1]
+
+Explanation:
+FrontMiddleBackQueue q = new FrontMiddleBackQueue();
+q.pushFront(1); // [1]
+q.pushBack(2); // [1, 2]
+q.pushMiddle(3); // [1, 3, 2]
+q.pushMiddle(4); // [1, 4, 3, 2]
+q.popFront(); // return 1 -> [4, 3, 2]
+q.popMiddle(); // return 3 -> [4, 2]
+q.popMiddle(); // return 4 -> [2]
+q.popBack(); // return 2 -> []
+q.popFront(); // return -1 -> [] (The queue is empty)
+
+```
+
+**Constraints**:
+
+- `1 <= val <= 109`
+- At most `1000` calls will be made to `pushFront`, `pushMiddle`, `pushBack`, `popFront`, `popMiddle`, and `popBack`.
+
+## 题目大意
+
+请你设计一个队列,支持在前,中,后三个位置的 push 和 pop 操作。
+
+请你完成 FrontMiddleBack 类:
+
+- FrontMiddleBack() 初始化队列。
+- void pushFront(int val) 将 val 添加到队列的 最前面 。
+- void pushMiddle(int val) 将 val 添加到队列的 正中间 。
+- void pushBack(int val) 将 val 添加到队里的 最后面 。
+- int popFront() 将 最前面 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 -1 。
+- int popMiddle() 将 正中间 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 -1 。
+- int popBack() 将 最后面 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 -1 。
+
+请注意当有 两个 中间位置的时候,选择靠前面的位置进行操作。比方说:
+
+- 将 6 添加到 [1, 2, 3, 4, 5] 的中间位置,结果数组为 [1, 2, 6, 3, 4, 5] 。
+- 从 [1, 2, 3, 4, 5, 6] 的中间位置弹出元素,返回 3 ,数组变为 [1, 2, 4, 5, 6] 。
+
+## 解题思路
+
+- 简单题,利用 go 原生的双向队列 list 的实现,可以轻松实现这个“前中后队列”。
+- 具体实现见代码,几组特殊测试用例见测试文件。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "container/list"
+)
+
+type FrontMiddleBackQueue struct {
+ list *list.List
+ middle *list.Element
+}
+
+func Constructor() FrontMiddleBackQueue {
+ return FrontMiddleBackQueue{list: list.New()}
+}
+
+func (this *FrontMiddleBackQueue) PushFront(val int) {
+ e := this.list.PushFront(val)
+ if this.middle == nil {
+ this.middle = e
+ } else if this.list.Len()%2 == 0 && this.middle.Prev() != nil {
+ this.middle = this.middle.Prev()
+ }
+}
+
+func (this *FrontMiddleBackQueue) PushMiddle(val int) {
+ if this.middle == nil {
+ this.PushFront(val)
+ } else {
+ if this.list.Len()%2 != 0 {
+ this.middle = this.list.InsertBefore(val, this.middle)
+ } else {
+ this.middle = this.list.InsertAfter(val, this.middle)
+ }
+ }
+}
+
+func (this *FrontMiddleBackQueue) PushBack(val int) {
+ e := this.list.PushBack(val)
+ if this.middle == nil {
+ this.middle = e
+ } else if this.list.Len()%2 != 0 && this.middle.Next() != nil {
+ this.middle = this.middle.Next()
+ }
+}
+
+func (this *FrontMiddleBackQueue) PopFront() int {
+ if this.list.Len() == 0 {
+ return -1
+ }
+ e := this.list.Front()
+ if this.list.Len() == 1 {
+ this.middle = nil
+ } else if this.list.Len()%2 == 0 && this.middle.Next() != nil {
+ this.middle = this.middle.Next()
+ }
+ return this.list.Remove(e).(int)
+}
+
+func (this *FrontMiddleBackQueue) PopMiddle() int {
+ if this.middle == nil {
+ return -1
+ }
+ e := this.middle
+ if this.list.Len()%2 != 0 {
+ this.middle = e.Prev()
+ } else {
+ this.middle = e.Next()
+ }
+ return this.list.Remove(e).(int)
+}
+
+func (this *FrontMiddleBackQueue) PopBack() int {
+ if this.list.Len() == 0 {
+ return -1
+ }
+ e := this.list.Back()
+ if this.list.Len() == 1 {
+ this.middle = nil
+ } else if this.list.Len()%2 != 0 && this.middle.Prev() != nil {
+ this.middle = this.middle.Prev()
+ }
+ return this.list.Remove(e).(int)
+}
+
+/**
+ * Your FrontMiddleBackQueue object will be instantiated and called as such:
+ * obj := Constructor();
+ * obj.PushFront(val);
+ * obj.PushMiddle(val);
+ * obj.PushBack(val);
+ * param_4 := obj.PopFront();
+ * param_5 := obj.PopMiddle();
+ * param_6 := obj.PopBack();
+ */
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1672.Richest-Customer-Wealth.md b/website/content/ChapterFour/1672.Richest-Customer-Wealth.md
new file mode 100644
index 00000000..13a3b114
--- /dev/null
+++ b/website/content/ChapterFour/1672.Richest-Customer-Wealth.md
@@ -0,0 +1,79 @@
+# [1672. Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/)
+
+
+## 题目
+
+You are given an `m x n` integer grid `accounts` where `accounts[i][j]` is the amount of money the `ith` customer has in the `jth` bank. Return *the **wealth** that the richest customer has.*
+
+A customer's **wealth** is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum **wealth**.
+
+**Example 1**:
+
+```
+Input: accounts = [[1,2,3],[3,2,1]]
+Output: 6
+Explanation:1st customer has wealth = 1 + 2 + 3 = 6
+2nd customer has wealth = 3 + 2 + 1 = 6
+Both customers are considered the richest with a wealth of 6 each, so return 6.
+```
+
+**Example 2**:
+
+```
+Input: accounts = [[1,5],[7,3],[3,5]]
+Output: 10
+Explanation:
+1st customer has wealth = 6
+2nd customer has wealth = 10
+3rd customer has wealth = 8
+The 2nd customer is the richest with a wealth of 10.
+```
+
+**Example 3**:
+
+```
+Input: accounts = [[2,8,7],[7,1,3],[1,9,5]]
+Output: 17
+```
+
+**Constraints**:
+
+- `m == accounts.length`
+- `n == accounts[i].length`
+- `1 <= m, n <= 50`
+- `1 <= accounts[i][j] <= 100`
+
+## 题目大意
+
+给你一个 m x n 的整数网格 accounts ,其中 accounts[i][j] 是第 i 位客户在第 j 家银行托管的资产数量。返回最富有客户所拥有的 资产总量 。客户的 资产总量 就是他们在各家银行托管的资产数量之和。最富有客户就是 资产总量 最大的客户。
+
+## 解题思路
+
+- 简单题。计算二维数组中每个一位数组的元素总和,然后动态维护这些一位数组和的最大值即可。
+
+## 代码
+
+```go
+package leetcode
+
+func maximumWealth(accounts [][]int) int {
+ res := 0
+ for _, banks := range accounts {
+ sAmount := 0
+ for _, amount := range banks {
+ sAmount += amount
+ }
+ if sAmount > res {
+ res = sAmount
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1673.Find-the-Most-Competitive-Subsequence.md b/website/content/ChapterFour/1673.Find-the-Most-Competitive-Subsequence.md
new file mode 100644
index 00000000..b0b30764
--- /dev/null
+++ b/website/content/ChapterFour/1673.Find-the-Most-Competitive-Subsequence.md
@@ -0,0 +1,69 @@
+# [1673. Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence/)
+
+
+## 题目
+
+Given an integer array `nums` and a positive integer `k`, return *the most **competitive** subsequence of* `nums` *of size* `k`.
+
+An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.
+
+We define that a subsequence `a` is more **competitive** than a subsequence `b` (of the same length) if in the first position where `a` and `b` differ, subsequence `a` has a number **less** than the corresponding number in `b`. For example, `[1,3,4]` is more competitive than `[1,3,5]` because the first position they differ is at the final number, and `4` is less than `5`.
+
+**Example 1**:
+
+```
+Input: nums = [3,5,2,6], k = 2
+Output: [2,6]
+Explanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.
+
+```
+
+**Example 2**:
+
+```
+Input: nums = [2,4,3,3,5,4,9,6], k = 4
+Output: [2,3,3,4]
+
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 105`
+- `0 <= nums[i] <= 109`
+- `1 <= k <= nums.length`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个正整数 k ,返回长度为 k 且最具 竞争力 的 nums 子序列。数组的子序列是从数组中删除一些元素(可能不删除元素)得到的序列。
+
+在子序列 a 和子序列 b 第一个不相同的位置上,如果 a 中的数字小于 b 中对应的数字,那么我们称子序列 a 比子序列 b(相同长度下)更具 竞争力 。 例如,[1,3,4] 比 [1,3,5] 更具竞争力,在第一个不相同的位置,也就是最后一个位置上, 4 小于 5 。
+
+## 解题思路
+
+- 这一题是单调栈的典型题型。利用单调栈,可以保证原数组中元素相对位置不变,这满足题意中删除元素但不移动元素的要求。单调栈又能保证每次进栈,元素是最小的。
+- 类似的题目还有第 42 题,第 84 题,第 496 题,第 503 题,第 856 题,第 901 题,第 907 题,第 1130 题,第 1425 题,第 1673 题。
+
+## 代码
+
+```go
+package leetcode
+
+// 单调栈
+func mostCompetitive(nums []int, k int) []int {
+ stack := make([]int, 0, len(nums))
+ for i := 0; i < len(nums); i++ {
+ for len(stack)+len(nums)-i > k && len(stack) > 0 && nums[i] < stack[len(stack)-1] {
+ stack = stack[:len(stack)-1]
+ }
+ stack = append(stack, nums[i])
+ }
+ return stack[:k]
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1674.Minimum-Moves-to-Make-Array-Complementary.md b/website/content/ChapterFour/1674.Minimum-Moves-to-Make-Array-Complementary.md
new file mode 100644
index 00000000..31ade1f0
--- /dev/null
+++ b/website/content/ChapterFour/1674.Minimum-Moves-to-Make-Array-Complementary.md
@@ -0,0 +1,104 @@
+# [1674. Minimum Moves to Make Array Complementary](https://leetcode.com/problems/minimum-moves-to-make-array-complementary/)
+
+## 题目
+
+You are given an integer array `nums` of **even** length `n` and an integer `limit`. In one move, you can replace any integer from `nums` with another integer between `1` and `limit`, inclusive.
+
+The array `nums` is **complementary** if for all indices `i` (**0-indexed**), `nums[i] + nums[n - 1 - i]` equals the same number. For example, the array `[1,2,3,4]` is complementary because for all indices `i`, `nums[i] + nums[n - 1 - i] = 5`.
+
+Return the ***minimum** number of moves required to make* `nums` ***complementary***.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,4,3], limit = 4
+Output: 1
+Explanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).
+nums[0] + nums[3] = 1 + 3 = 4.
+nums[1] + nums[2] = 2 + 2 = 4.
+nums[2] + nums[1] = 2 + 2 = 4.
+nums[3] + nums[0] = 3 + 1 = 4.
+Therefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,2,2,1], limit = 2
+Output: 2
+Explanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.
+```
+
+**Example 3**:
+
+```
+Input: nums = [1,2,1,2], limit = 2
+Output: 0
+Explanation: nums is already complementary.
+```
+
+**Constraints**:
+
+- `n == nums.length`
+- `2 <= n <= 105`
+- `1 <= nums[i] <= limit <= 105`
+- `n` is even.
+
+## 题目大意
+
+给你一个长度为 偶数 n 的整数数组 nums 和一个整数 limit 。每一次操作,你可以将 nums 中的任何整数替换为 1 到 limit 之间的另一个整数。
+
+如果对于所有下标 i(下标从 0 开始),nums[i] + nums[n - 1 - i] 都等于同一个数,则数组 nums 是 互补的 。例如,数组 [1,2,3,4] 是互补的,因为对于所有下标 i ,nums[i] + nums[n - 1 - i] = 5 。
+
+返回使数组 互补 的 最少 操作次数。
+
+## 解题思路
+
+- 这一题考察的是差分数组。通过分析题意,可以得出,针对每一个 `sum` 的取值范围是 `[2, 2* limt]`,定义 `a = min(nums[i], nums[n - i - 1])`,`b = max(nums[i], nums[n - i - 1])`,在这个区间内,又可以细分成 5 个区间,`[2, a + 1)`,`[a + 1, a + b)`,`[a + b + 1, a + b + 1)`,`[a + b + 1, b + limit + 1)`,`[b + limit + 1, 2 * limit)`,在这 5 个区间内使得数组互补的最小操作次数分别是 `2(减少 a, 减少 b)`,`1(减少 b)`,`0(不用操作)`,`1(增大 a)`,`+2(增大 a, 增大 b)`,换个表达方式,按照扫描线从左往右扫描,在这 5 个区间内使得数组互补的最小操作次数叠加变化分别是 `+2(减少 a, 减少 b)`,`-1(减少 a)`,`-1(不用操作)`,`+1(增大 a)`,`+1(增大 a, 增大 b)`,利用这前后两个区间的关系,就可以构造一个差分数组。差分数组反应的是前后两者的关系。如果想求得 0 ~ n 的总关系,只需要求一次前缀和即可。
+- 这道题要求输出最少的操作次数,所以利用差分数组 + 前缀和,累加前缀和的同时维护最小值。从左往右扫描完一遍以后,输出最小值即可。
+
+## 代码
+
+```go
+package leetcode
+
+func minMoves(nums []int, limit int) int {
+ diff := make([]int, limit*2+2) // nums[i] <= limit, b+limit+1 is maximum limit+limit+1
+ for j := 0; j < len(nums)/2; j++ {
+ a, b := min(nums[j], nums[len(nums)-j-1]), max(nums[j], nums[len(nums)-j-1])
+ // using prefix sum: most interesting point, and is the key to reduce complexity
+ diff[2] += 2
+ diff[a+1]--
+ diff[a+b]--
+ diff[a+b+1]++
+ diff[b+limit+1]++
+ }
+ cur, res := 0, len(nums)
+ for i := 2; i <= 2*limit; i++ {
+ cur += diff[i]
+ res = min(res, cur)
+ }
+ return res
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1678.Goal-Parser-Interpretation.md b/website/content/ChapterFour/1678.Goal-Parser-Interpretation.md
new file mode 100644
index 00000000..0027dd5b
--- /dev/null
+++ b/website/content/ChapterFour/1678.Goal-Parser-Interpretation.md
@@ -0,0 +1,80 @@
+# [1678. Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation/)
+
+## 题目
+
+You own a **Goal Parser** that can interpret a string `command`. The `command` consists of an alphabet of `"G"`, `"()"` and/or `"(al)"` in some order. The Goal Parser will interpret `"G"` as the string `"G"`, `"()"` as the string `"o"`, and `"(al)"` as the string `"al"`. The interpreted strings are then concatenated in the original order.
+
+Given the string `command`, return *the **Goal Parser**'s interpretation of* `command`.
+
+**Example 1**:
+
+```
+Input: command = "G()(al)"
+Output: "Goal"
+Explanation: The Goal Parser interprets the command as follows:
+G -> G
+() -> o
+(al) -> al
+The final concatenated result is "Goal".
+```
+
+**Example 2**:
+
+```
+Input: command = "G()()()()(al)"
+Output: "Gooooal"
+```
+
+**Example 3**:
+
+```
+Input: command = "(al)G(al)()()G"
+Output: "alGalooG"
+```
+
+**Constraints**:
+
+- `1 <= command.length <= 100`
+- `command` consists of `"G"`, `"()"`, and/or `"(al)"` in some order.
+
+## 题目大意
+
+请你设计一个可以解释字符串 command 的 Goal 解析器 。command 由 "G"、"()" 和/或 "(al)" 按某种顺序组成。Goal 解析器会将 "G" 解释为字符串 "G"、"()" 解释为字符串 "o" ,"(al)" 解释为字符串 "al" 。然后,按原顺序将经解释得到的字符串连接成一个字符串。给你字符串 command ,返回 Goal 解析器 对 command 的解释结果。
+
+## 解题思路
+
+- 简单题,按照题意修改字符串即可。由于是简单题,这一题也不用考虑嵌套的情况。
+
+## 代码
+
+```go
+package leetcode
+
+func interpret(command string) string {
+ if command == "" {
+ return ""
+ }
+ res := ""
+ for i := 0; i < len(command); i++ {
+ if command[i] == 'G' {
+ res += "G"
+ } else {
+ if command[i] == '(' && command[i+1] == 'a' {
+ res += "al"
+ i += 3
+ } else {
+ res += "o"
+ i ++
+ }
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1679.Max-Number-of-K-Sum-Pairs.md b/website/content/ChapterFour/1679.Max-Number-of-K-Sum-Pairs.md
new file mode 100644
index 00000000..a573fadc
--- /dev/null
+++ b/website/content/ChapterFour/1679.Max-Number-of-K-Sum-Pairs.md
@@ -0,0 +1,105 @@
+# [1679. Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/)
+
+
+## 题目
+
+You are given an integer array `nums` and an integer `k`.
+
+In one operation, you can pick two numbers from the array whose sum equals `k` and remove them from the array.
+
+Return *the maximum number of operations you can perform on the array*.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,3,4], k = 5
+Output: 2
+Explanation: Starting with nums = [1,2,3,4]:
+- Remove numbers 1 and 4, then nums = [2,3]
+- Remove numbers 2 and 3, then nums = []
+There are no more pairs that sum up to 5, hence a total of 2 operations.
+```
+
+**Example 2**:
+
+```
+Input: nums = [3,1,3,4,3], k = 6
+Output: 1
+Explanation: Starting with nums = [3,1,3,4,3]:
+- Remove the first two 3's, then nums = [1,4,3]
+There are no more pairs that sum up to 6, hence a total of 1 operation.
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 109`
+- `1 <= k <= 109`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个整数 k 。每一步操作中,你需要从数组中选出和为 k 的两个整数,并将它们移出数组。返回你可以对数组执行的最大操作数。
+
+## 解题思路
+
+- 读完题第一感觉这道题是 TWO SUM 题目的加强版。需要找到所有满足和是 k 的数对。先考虑能不能找到两个数都是 k/2 ,如果能找到多个这样的数,可以先移除他们。其次在利用 TWO SUM 的思路,找出和为 k 的数对。利用 TWO SUM 里面 map 的做法,时间复杂度 O(n)。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 优化版
+func maxOperations(nums []int, k int) int {
+ counter, res := make(map[int]int), 0
+ for _, n := range nums {
+ counter[n]++
+ }
+ if (k & 1) == 0 {
+ res += counter[k>>1] >> 1
+ // 能够由 2 个相同的数构成 k 的组合已经都排除出去了,剩下的一个单独的也不能组成 k 了
+ // 所以这里要把它的频次置为 0 。如果这里不置为 0,下面代码判断逻辑还需要考虑重复使用数字的情况
+ counter[k>>1] = 0
+ }
+ for num, freq := range counter {
+ if num <= k/2 {
+ remain := k - num
+ if counter[remain] < freq {
+ res += counter[remain]
+ } else {
+ res += freq
+ }
+ }
+ }
+ return res
+}
+
+// 解法二
+func maxOperations_(nums []int, k int) int {
+ counter, res := make(map[int]int), 0
+ for _, num := range nums {
+ counter[num]++
+ remain := k - num
+ if num == remain {
+ if counter[num] >= 2 {
+ res++
+ counter[num] -= 2
+ }
+ } else {
+ if counter[remain] > 0 {
+ res++
+ counter[remain]--
+ counter[num]--
+ }
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1680.Concatenation-of-Consecutive-Binary-Numbers.md b/website/content/ChapterFour/1680.Concatenation-of-Consecutive-Binary-Numbers.md
new file mode 100644
index 00000000..5fc06173
--- /dev/null
+++ b/website/content/ChapterFour/1680.Concatenation-of-Consecutive-Binary-Numbers.md
@@ -0,0 +1,102 @@
+# [1680. Concatenation of Consecutive Binary Numbers](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/)
+
+
+## 题目
+
+Given an integer `n`, return *the **decimal value** of the binary string formed by concatenating the binary representations of* `1` *to* `n` *in order, **modulo*** `109 + 7`.
+
+**Example 1**:
+
+```
+Input: n = 1
+Output: 1
+Explanation: "1" in binary corresponds to the decimal value 1.
+```
+
+**Example 2**:
+
+```
+Input: n = 3
+Output: 27
+Explanation: In binary, 1, 2, and 3 corresponds to "1", "10", and "11".
+After concatenating them, we have "11011", which corresponds to the decimal value 27.
+```
+
+**Example 3**:
+
+```
+Input: n = 12
+Output: 505379714
+Explanation: The concatenation results in "1101110010111011110001001101010111100".
+The decimal value of that is 118505380540.
+After modulo 109 + 7, the result is 505379714.
+```
+
+**Constraints**:
+
+- `1 <= n <= 10^5`
+
+## 题目大意
+
+给你一个整数 n ,请你将 1 到 n 的二进制表示连接起来,并返回连接结果对应的 十进制 数字对 10^9 + 7 取余的结果。
+
+## 解题思路
+
+- 理解题意以后,先找到如何拼接最终二进制数的规律。假设 `f(n)` 为最终变换以后的十进制数。那么根据题意,`f(n) = f(n-1) << shift + n` 这是一个递推公式。`shift` 左移的位数就是 `n` 的二进制对应的长度。`shift` 的值是随着 `n` 变化而变化的。由二进制进位规律可以知道,2 的整数次幂的时候,对应的二进制长度会增加 1 位。这里可以利用位运算来判断是否是 2 的整数次幂。
+- 这道题另外一个需要处理的是模运算的法则。此题需要用到模运算的加法法则。
+
+ ```go
+ 模运算与基本四则运算有些相似,但是除法例外。
+ (a + b) % p = (a % p + b % p) % p (1)
+ (a - b) % p = (a % p - b % p) % p (2)
+ (a * b) % p = (a % p * b % p) % p (3)
+ a ^ b % p = ((a % p)^b) % p (4)
+ 结合律:
+ ((a+b) % p + c) % p = (a + (b+c) % p) % p (5)
+ ((a*b) % p * c)% p = (a * (b*c) % p) % p (6)
+ 交换律:
+ (a + b) % p = (b+a) % p (7)
+ (a * b) % p = (b * a) % p (8)
+ 分配律:
+ ((a +b)% p * c) % p = ((a * c) % p + (b * c) % p) % p (9)
+ ```
+
+ 这一题需要用到模运算的加法运算法则。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math/bits"
+)
+
+// 解法一 模拟
+func concatenatedBinary(n int) int {
+ res, mod, shift := 0, 1000000007, 0
+ for i := 1; i <= n; i++ {
+ if (i & (i - 1)) == 0 {
+ shift++
+ }
+ res = ((res << shift) + i) % mod
+ }
+ return res
+}
+
+// 解法二 位运算
+func concatenatedBinary1(n int) int {
+ res := 0
+ for i := 1; i <= n; i++ {
+ res = (res<
+⬅️上一页
+下一页➡️
+
diff --git a/website/content/ChapterFour/1681.Minimum-Incompatibility.md b/website/content/ChapterFour/1681.Minimum-Incompatibility.md
new file mode 100644
index 00000000..ebc5c06a
--- /dev/null
+++ b/website/content/ChapterFour/1681.Minimum-Incompatibility.md
@@ -0,0 +1,129 @@
+# [1681. Minimum Incompatibility](https://leetcode.com/problems/minimum-incompatibility/)
+
+
+## 题目
+
+You are given an integer array `nums` and an integer `k`. You are asked to distribute this array into `k` subsets of **equal size** such that there are no two equal elements in the same subset.
+
+A subset's **incompatibility** is the difference between the maximum and minimum elements in that array.
+
+Return *the **minimum possible sum of incompatibilities** of the* `k` *subsets after distributing the array optimally, or return* `-1` *if it is not possible.*
+
+A subset is a group integers that appear in the array with no particular order.
+
+**Example 1**:
+
+```
+Input: nums = [1,2,1,4], k = 2
+Output: 4
+Explanation: The optimal distribution of subsets is [1,2] and [1,4].
+The incompatibility is (2-1) + (4-1) = 4.
+Note that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.
+```
+
+**Example 2**:
+
+```
+Input: nums = [6,3,8,1,3,1,2,2], k = 4
+Output: 6
+Explanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].
+The incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.
+
+```
+
+**Example 3**:
+
+```
+Input: nums = [5,3,3,6,3,3], k = 3
+Output: -1
+Explanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.
+
+```
+
+**Constraints**:
+
+- `1 <= k <= nums.length <= 16`
+- `nums.length` is divisible by `k`
+- `1 <= nums[i] <= nums.length`
+
+## 题目大意
+
+给你一个整数数组 nums 和一个整数 k 。你需要将这个数组划分到 k 个相同大小的子集中,使得同一个子集里面没有两个相同的元素。一个子集的 不兼容性 是该子集里面最大值和最小值的差。
+
+请你返回将数组分成 k 个子集后,各子集 **不兼容性** 的 **和** 的 **最小值** ,如果无法分成分成 k 个子集,返回 -1 。子集的定义是数组中一些数字的集合,对数字顺序没有要求。
+
+## 解题思路
+
+- 读完题最直白的思路就是 DFS。做法类似第 77 题。这里就不赘述了。可以见第 77 题题解。
+- 这一题还需要用到贪心的思想。每次取数都取最小的数。这样可以不会让最大数和最小数在一个集合中。由于每次取数都是取最小的,那么能保证不兼容性每次都尽量最小。于是在 order 数组中定义取数的顺序。然后再把数组从小到大排列。这样每次按照 order 顺序取数,都是取的最小值。
+- 正常的 DFS 写完提交,耗时是很长的。大概是 1532ms。如何优化到极致呢?这里需要加上 2 个剪枝条件。第一个剪枝条件比较简单,如果累计 sum 比之前存储的 res 大,那么直接 return,不需要继续递归了。第二个剪枝条件就非常重要了,可以一下子减少很多次递归。每次取数产生新的集合的时候,要从第一个最小数开始取,一旦取了,后面就不需要再循环递归了。举个例子,[1,2,3,4],第一个数如果取 2,集合可以是 [[2,3],[1,4]] 或 [[2,4], [1,3]], 这个集合和[[1,3],[2,4]]、[[1,4], [2,3]] 情况一样。可以看到如果取出第一个最小值以后,后面的循环是不必要的了。所以在取下标为 0 的数的时候,递归到底层以后,返回就可以直接 break,不用接下去的循环了,接下去的循环和递归是不必要的。每组组内的顺序我们并不关心,只要最大值和最小值在分组内即可。另外组间顺序我们也不关心。所以可以把排列问题 O(n!) 时间复杂度降低到组合问题 O(2^n)。加了这 2 个剪枝条件以后,耗时就变成了 0ms 了。beats 100%
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math"
+ "sort"
+)
+
+func minimumIncompatibility(nums []int, k int) int {
+ sort.Ints(nums)
+ eachSize, counts := len(nums)/k, make([]int, len(nums)+1)
+ for i := range nums {
+ counts[nums[i]]++
+ if counts[nums[i]] > k {
+ return -1
+ }
+ }
+ orders := []int{}
+ for i := range counts {
+ orders = append(orders, i)
+ }
+ sort.Ints(orders)
+ res := math.MaxInt32
+ generatePermutation1681(nums, counts, orders, 0, 0, eachSize, &res, []int{})
+ if res == math.MaxInt32 {
+ return -1
+ }
+ return res
+}
+
+func generatePermutation1681(nums, counts, order []int, index, sum, eachSize int, res *int, current []int) {
+ if len(current) > 0 && len(current)%eachSize == 0 {
+ sum += current[len(current)-1] - current[len(current)-eachSize]
+ index = 0
+ }
+ if sum >= *res {
+ return
+ }
+ if len(current) == len(nums) {
+ if sum < *res {
+ *res = sum
+ }
+ return
+ }
+ for i := index; i < len(counts); i++ {
+ if counts[order[i]] == 0 {
+ continue
+ }
+ counts[order[i]]--
+ current = append(current, order[i])
+ generatePermutation1681(nums, counts, order, i+1, sum, eachSize, res, current)
+ current = current[:len(current)-1]
+ counts[order[i]]++
+ // 这里是关键的剪枝
+ if index == 0 {
+ break
+ }
+ }
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1684.Count-the-Number-of-Consistent-Strings.md b/website/content/ChapterFour/1684.Count-the-Number-of-Consistent-Strings.md
new file mode 100644
index 00000000..9cce9fd7
--- /dev/null
+++ b/website/content/ChapterFour/1684.Count-the-Number-of-Consistent-Strings.md
@@ -0,0 +1,86 @@
+# [1684. Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings/)
+
+
+## 题目
+
+You are given a string `allowed` consisting of **distinct** characters and an array of strings `words`. A string is **consistent** if all characters in the string appear in the string `allowed`.
+
+Return *the number of **consistent** strings in the array* `words`.
+
+**Example 1**:
+
+```
+Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
+Output: 2
+Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.
+
+```
+
+**Example 2**:
+
+```
+Input: allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]
+Output: 7
+Explanation: All strings are consistent.
+
+```
+
+**Example 3**:
+
+```
+Input: allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]
+Output: 4
+Explanation: Strings "cc", "acd", "ac", and "d" are consistent.
+
+```
+
+**Constraints**:
+
+- `1 <= words.length <= 104`
+- `1 <= allowed.length <= 26`
+- `1 <= words[i].length <= 10`
+- The characters in `allowed` are **distinct**.
+- `words[i]` and `allowed` contain only lowercase English letters.
+
+## 题目大意
+
+给你一个由不同字符组成的字符串 `allowed` 和一个字符串数组 `words` 。如果一个字符串的每一个字符都在 `allowed` 中,就称这个字符串是 一致字符串 。
+
+请你返回 `words` 数组中 一致字符串 的数目。
+
+## 解题思路
+
+- 简单题。先将 `allowed` 转化成 map。将 `words` 数组中每个单词的字符都在 map 中查找一遍,如果都存在就累加 res。如果有不存在的字母,不累加。最终输出 res 即可。
+
+## 代码
+
+```go
+package leetcode
+
+func countConsistentStrings(allowed string, words []string) int {
+ allowedMap, res, flag := map[rune]int{}, 0, true
+ for _, str := range allowed {
+ allowedMap[str]++
+ }
+ for i := 0; i < len(words); i++ {
+ flag = true
+ for j := 0; j < len(words[i]); j++ {
+ if _, ok := allowedMap[rune(words[i][j])]; !ok {
+ flag = false
+ break
+ }
+ }
+ if flag {
+ res++
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md b/website/content/ChapterFour/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md
new file mode 100644
index 00000000..690f9b1d
--- /dev/null
+++ b/website/content/ChapterFour/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md
@@ -0,0 +1,95 @@
+# [1685. Sum of Absolute Differences in a Sorted Array](https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array/)
+
+
+## 题目
+
+You are given an integer array `nums` sorted in **non-decreasing** order.
+
+Build and return *an integer array* `result` *with the same length as* `nums` *such that* `result[i]` *is equal to the **summation of absolute differences** between* `nums[i]` *and all the other elements in the array.*
+
+In other words, `result[i]` is equal to `sum(|nums[i]-nums[j]|)` where `0 <= j < nums.length` and `j != i` (**0-indexed**).
+
+**Example 1**:
+
+```
+Input: nums = [2,3,5]
+Output: [4,3,5]
+Explanation: Assuming the arrays are 0-indexed, then
+result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
+result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
+result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.
+```
+
+**Example 2**:
+
+```
+Input: nums = [1,4,6,8,10]
+Output: [24,15,13,15,21]
+```
+
+**Constraints**:
+
+- `2 <= nums.length <= 105`
+- `1 <= nums[i] <= nums[i + 1] <= 104`
+
+## 题目大意
+
+给你一个 非递减 有序整数数组 `nums` 。请你建立并返回一个整数数组 `result`,它跟 `nums` 长度相同,且`result[i]` 等于 `nums[i]` 与数组中所有其他元素差的绝对值之和。换句话说, `result[i]` 等于 `sum(|nums[i]-nums[j]|)` ,其中 `0 <= j < nums.length` 且 `j != i` (下标从 0 开始)。
+
+## 解题思路
+
+- 利用前缀和思路解题。题目中说明了是有序数组,所以在计算绝对值的时候可以拆开绝对值符号。假设要计算当前 `result[i]`,以 `i` 为界,把原数组 `nums` 分成了 3 段。`nums[0 ~ i-1]` 和 `nums[i+1 ~ n]`,前面一段 `nums[0 ~ i-1]` 中的每个元素都比 `nums[i]` 小,拆掉绝对值以后,`sum(|nums[i]-nums[j]|) = nums[i] * i - prefixSum[0 ~ i-1]`,后面一段 `nums[i+1 ~ n]` 中的每个元素都比 `nums[i]` 大,拆掉绝对值以后,`sum(|nums[i]-nums[j]|) = prefixSum[i+1 ~ n] - nums[i] * (n - 1 - i)`。特殊的情况,`i = 0` 和 `i = n` 的情况特殊处理一下就行。
+
+## 代码
+
+```go
+package leetcode
+
+//解法一 优化版 prefixSum + sufixSum
+func getSumAbsoluteDifferences(nums []int) []int {
+ size := len(nums)
+ sufixSum := make([]int, size)
+ sufixSum[size-1] = nums[size-1]
+ for i := size - 2; i >= 0; i-- {
+ sufixSum[i] = sufixSum[i+1] + nums[i]
+ }
+ ans, preSum := make([]int, size), 0
+ for i := 0; i < size; i++ {
+ // 后面可以加到的值
+ res, sum := 0, sufixSum[i]-nums[i]
+ res += (sum - (size-i-1)*nums[i])
+ // 前面可以加到的值
+ res += (i*nums[i] - preSum)
+ ans[i] = res
+ preSum += nums[i]
+ }
+ return ans
+}
+
+// 解法二 prefixSum
+func getSumAbsoluteDifferences1(nums []int) []int {
+ preSum, res, sum := []int{}, []int{}, nums[0]
+ preSum = append(preSum, nums[0])
+ for i := 1; i < len(nums); i++ {
+ sum += nums[i]
+ preSum = append(preSum, sum)
+ }
+ for i := 0; i < len(nums); i++ {
+ if i == 0 {
+ res = append(res, preSum[len(nums)-1]-preSum[0]-nums[i]*(len(nums)-1))
+ } else if i > 0 && i < len(nums)-1 {
+ res = append(res, preSum[len(nums)-1]-preSum[i]-preSum[i-1]+nums[i]*i-nums[i]*(len(nums)-1-i))
+ } else {
+ res = append(res, nums[i]*len(nums)-preSum[len(nums)-1])
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1688.Count-of-Matches-in-Tournament.md b/website/content/ChapterFour/1688.Count-of-Matches-in-Tournament.md
new file mode 100644
index 00000000..fc73c685
--- /dev/null
+++ b/website/content/ChapterFour/1688.Count-of-Matches-in-Tournament.md
@@ -0,0 +1,87 @@
+# [1688. Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament/)
+
+
+## 题目
+
+You are given an integer `n`, the number of teams in a tournament that has strange rules:
+
+- If the current number of teams is **even**, each team gets paired with another team. A total of `n / 2` matches are played, and `n / 2` teams advance to the next round.
+- If the current number of teams is **odd**, one team randomly advances in the tournament, and the rest gets paired. A total of `(n - 1) / 2` matches are played, and `(n - 1) / 2 + 1` teams advance to the next round.
+
+Return *the number of matches played in the tournament until a winner is decided.*
+
+**Example 1**:
+
+```
+Input: n = 7
+Output: 6
+Explanation: Details of the tournament:
+- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
+- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
+- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
+Total number of matches = 3 + 2 + 1 = 6.
+```
+
+**Example 2**:
+
+```
+Input: n = 14
+Output: 13
+Explanation: Details of the tournament:
+- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
+- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
+- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
+- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
+Total number of matches = 7 + 3 + 2 + 1 = 13.
+```
+
+**Constraints**:
+
+- `1 <= n <= 200`
+
+## 题目大意
+
+给你一个整数 n ,表示比赛中的队伍数。比赛遵循一种独特的赛制:
+
+- 如果当前队伍数是 偶数 ,那么每支队伍都会与另一支队伍配对。总共进行 n / 2 场比赛,且产生 n / 2 支队伍进入下一轮。
+- 如果当前队伍数为 奇数 ,那么将会随机轮空并晋级一支队伍,其余的队伍配对。总共进行 (n - 1) / 2 场比赛,且产生 (n - 1) / 2 + 1 支队伍进入下一轮。
+
+返回在比赛中进行的配对次数,直到决出获胜队伍为止。
+
+## 解题思路
+
+- 简单题,按照题目的规则模拟。
+- 这一题还有更加简洁的代码,见解法一。n 个队伍,一个冠军,需要淘汰 n-1 个队伍。每一场比赛淘汰一个队伍,因此进行了 n-1 场比赛。所以共有 n-1 个配对。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一
+func numberOfMatches(n int) int {
+ return n - 1
+}
+
+// 解法二 模拟
+func numberOfMatches1(n int) int {
+ sum := 0
+ for n != 1 {
+ if n&1 == 0 {
+ sum += n / 2
+ n = n / 2
+ } else {
+ sum += (n - 1) / 2
+ n = (n-1)/2 + 1
+ }
+ }
+ return sum
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers.md b/website/content/ChapterFour/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers.md
new file mode 100644
index 00000000..bb6b7c53
--- /dev/null
+++ b/website/content/ChapterFour/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers.md
@@ -0,0 +1,67 @@
+# [1689. Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/)
+
+## 题目
+
+A decimal number is called **deci-binary** if each of its digits is either `0` or `1` without any leading zeros. For example, `101` and `1100` are **deci-binary**, while `112` and `3001` are not.
+
+Given a string `n` that represents a positive decimal integer, return *the **minimum** number of positive **deci-binary** numbers needed so that they sum up to* `n`*.*
+
+**Example 1**:
+
+```
+Input: n = "32"
+Output: 3
+Explanation: 10 + 11 + 11 = 32
+```
+
+**Example 2**:
+
+```
+Input: n = "82734"
+Output: 8
+```
+
+**Example 3**:
+
+```
+Input: n = "27346209830709182346"
+Output: 9
+```
+
+**Constraints**:
+
+- `1 <= n.length <= 105`
+- `n` consists of only digits.
+- `n` does not contain any leading zeros and represents a positive integer.
+
+## 题目大意
+
+如果一个十进制数字不含任何前导零,且每一位上的数字不是 0 就是 1 ,那么该数字就是一个 十-二进制数 。例如,101 和 1100 都是 十-二进制数,而 112 和 3001 不是。给你一个表示十进制整数的字符串 n ,返回和为 n 的 十-二进制数 的最少数目。
+
+## 解题思路
+
+- 这一题也算是简单题,相通了以后,代码就 3 行。
+- 要想由 01 组成的十进制数组成 n,只需要在 n 这个数的各个数位上依次排上 0 和 1 即可。例如 n = 23423723,这是一个 8 位数。最大数字是 7,所以至少需要 7 个数累加能得到这个 n。这 7 个数的百位都为 1,其他数位按需求取 0 和 1 即可。例如万位是 2,那么这 7 个数中任找 2 个数的万位是 1 ,其他 5 个数的万位是 0 即可。
+
+## 代码
+
+```go
+package leetcode
+
+func minPartitions(n string) int {
+ res := 0
+ for i := 0; i < len(n); i++ {
+ if int(n[i]-'0') > res {
+ res = int(n[i] - '0')
+ }
+ }
+ return res
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1690.Stone-Game-VII.md b/website/content/ChapterFour/1690.Stone-Game-VII.md
new file mode 100644
index 00000000..cdb41310
--- /dev/null
+++ b/website/content/ChapterFour/1690.Stone-Game-VII.md
@@ -0,0 +1,137 @@
+# [1690. Stone Game VII](https://leetcode.com/problems/stone-game-vii/)
+
+## 题目
+
+Alice and Bob take turns playing a game, with **Alice starting first**.
+
+There are `n` stones arranged in a row. On each player's turn, they can **remove** either the leftmost stone or the rightmost stone from the row and receive points equal to the **sum** of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.
+
+Bob found that he will always lose this game (poor Bob, he always loses), so he decided to **minimize the score's difference**. Alice's goal is to **maximize the difference** in the score.
+
+Given an array of integers `stones` where `stones[i]` represents the value of the `ith` stone **from the left**, return *the **difference** in Alice and Bob's score if they both play **optimally**.*
+
+**Example 1**:
+
+```
+Input: stones = [5,3,1,4,2]
+Output: 6
+Explanation:
+- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].
+- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].
+- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].
+- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].
+- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].
+The score difference is 18 - 12 = 6.
+```
+
+**Example 2**:
+
+```
+Input: stones = [7,90,5,1,100,10,10,2]
+Output: 122
+```
+
+**Constraints**:
+
+- `n == stones.length`
+- `2 <= n <= 1000`
+- `1 <= stones[i] <= 1000`
+
+## 题目大意
+
+石子游戏中,爱丽丝和鲍勃轮流进行自己的回合,爱丽丝先开始 。有 n 块石子排成一排。每个玩家的回合中,可以从行中 移除 最左边的石头或最右边的石头,并获得与该行中剩余石头值之 和 相等的得分。当没有石头可移除时,得分较高者获胜。鲍勃发现他总是输掉游戏(可怜的鲍勃,他总是输),所以他决定尽力 减小得分的差值 。爱丽丝的目标是最大限度地 扩大得分的差值 。
+
+给你一个整数数组 stones ,其中 stones[i] 表示 从左边开始 的第 i 个石头的值,如果爱丽丝和鲍勃都 发挥出最佳水平 ,请返回他们 得分的差值 。
+
+## 解题思路
+
+- 首先考虑 Bob 缩小分值差距意味着什么,意味着他想让他和 Alice 相对分数最小。Bob 已经明确肯定是输,所以他的分数一定比 Alice 小,那么 Bob - Alice 分数相减一定是负数。相对分数越小,意味着差值越大。负数越大,差值越小。-50 和 -10,-10 数值大,相差小。所以 Bob 的操作是让相对分数越大。Alice 的目的也是这样,要让 Alice - Bob 的相对分数越大,这里是正数的越大。综上,两者的目的相同,都是让相对分数最大化。
+- 定义 `dp[i][j]` 代表在当前 `stone[i ~ j]` 区间内能获得的最大分差。状态转移方程为:
+
+ ```go
+ dp[i][j] = max(
+ sum(i + 1, j) - dp[i + 1][j], // 这一局取走 `stone[i]`,获得 sum(i + 1, j) 分数,再减去剩下对手能获得的分数,即是此局能获得的最大分差。
+ sum(i, j - 1) - dp[i][j - 1] // 这一局取走 `stone[j]`,获得 sum(i, j - 1) 分数,再减去剩下对手能获得的分数,即是此局能获得的最大分差。
+ )
+ ```
+
+ 计算 `sum(i + 1, j) = stone[i + 1] + stone[i + 2] + …… + stone[j]` 利用前缀和计算区间和。
+
+- 解法二是正常思路解答出来的代码。解法一是压缩了 DP 数组,在 DP 状态转移的时候,生成下一个 `dp[j]` 实际上是有规律的。利用这个规律可以少存一维数据,压缩空间。解法一的代码直接写出来,比较难想。先写出解法二的代码,然后找到递推规律,优化空间压缩一维,再写出解法一的代码。
+
+## 代码
+
+```go
+package leetcode
+
+// 解法一 优化空间版 DP
+func stoneGameVII(stones []int) int {
+ n := len(stones)
+ sum := make([]int, n)
+ dp := make([]int, n)
+ for i, d := range stones {
+ sum[i] = d
+ }
+ for i := 1; i < n; i++ {
+ for j := 0; j+i < n; j++ {
+ if (n-i)%2 == 1 {
+ d0 := dp[j] + sum[j]
+ d1 := dp[j+1] + sum[j+1]
+ if d0 > d1 {
+ dp[j] = d0
+ } else {
+ dp[j] = d1
+ }
+ } else {
+ d0 := dp[j] - sum[j]
+ d1 := dp[j+1] - sum[j+1]
+ if d0 < d1 {
+ dp[j] = d0
+ } else {
+ dp[j] = d1
+ }
+ }
+ sum[j] = sum[j] + stones[i+j]
+ }
+ }
+ return dp[0]
+}
+
+// 解法二 常规 DP
+func stoneGameVII1(stones []int) int {
+ prefixSum := make([]int, len(stones))
+ for i := 0; i < len(stones); i++ {
+ if i == 0 {
+ prefixSum[i] = stones[i]
+ } else {
+ prefixSum[i] = prefixSum[i-1] + stones[i]
+ }
+ }
+ dp := make([][]int, len(stones))
+ for i := range dp {
+ dp[i] = make([]int, len(stones))
+ dp[i][i] = 0
+ }
+ n := len(stones)
+ for l := 2; l <= n; l++ {
+ for i := 0; i+l <= n; i++ {
+ dp[i][i+l-1] = max(prefixSum[i+l-1]-prefixSum[i+1]+stones[i+1]-dp[i+1][i+l-1], prefixSum[i+l-2]-prefixSum[i]+stones[i]-dp[i][i+l-2])
+ }
+ }
+ return dp[0][n-1]
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1694.Reformat-Phone-Number.md b/website/content/ChapterFour/1694.Reformat-Phone-Number.md
new file mode 100644
index 00000000..b878af68
--- /dev/null
+++ b/website/content/ChapterFour/1694.Reformat-Phone-Number.md
@@ -0,0 +1,142 @@
+# [1694. Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number/)
+
+
+## 题目
+
+You are given a phone number as a string `number`. `number` consists of digits, spaces `' '`, and/or dashes `'-'`.
+
+You would like to reformat the phone number in a certain manner. Firstly, **remove** all spaces and dashes. Then, **group** the digits from left to right into blocks of length 3 **until** there are 4 or fewer digits. The final digits are then grouped as follows:
+
+- 2 digits: A single block of length 2.
+- 3 digits: A single block of length 3.
+- 4 digits: Two blocks of length 2 each.
+
+The blocks are then joined by dashes. Notice that the reformatting process should **never** produce any blocks of length 1 and produce **at most** two blocks of length 2.
+
+Return *the phone number after formatting.*
+
+**Example 1**:
+
+```
+Input: number = "1-23-45 6"
+Output: "123-456"
+Explanation: The digits are "123456".
+Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".
+Step 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is "456".
+Joining the blocks gives "123-456".
+
+```
+
+**Example 2**:
+
+```
+Input: number = "123 4-567"
+Output: "123-45-67"
+Explanation: The digits are "1234567".
+Step 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".
+Step 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are "45" and "67".
+Joining the blocks gives "123-45-67".
+
+```
+
+**Example 3**:
+
+```
+Input: number = "123 4-5678"
+Output: "123-456-78"
+Explanation: The digits are "12345678".
+Step 1: The 1st block is "123".
+Step 2: The 2nd block is "456".
+Step 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is "78".
+Joining the blocks gives "123-456-78".
+
+```
+
+**Example 4**:
+
+```
+Input: number = "12"
+Output: "12"
+
+```
+
+**Example 5**:
+
+```
+Input: number = "--17-5 229 35-39475 "
+Output: "175-229-353-94-75"
+
+```
+
+**Constraints**:
+
+- `2 <= number.length <= 100`
+- `number` consists of digits and the characters `'-'` and `' '`.
+- There are at least **two** digits in `number`.
+
+## 题目大意
+
+给你一个字符串形式的电话号码 number 。number 由数字、空格 ' '、和破折号 '-' 组成。
+
+请你按下述方式重新格式化电话号码。
+
+- 首先,删除 所有的空格和破折号。
+- 其次,将数组从左到右 每 3 个一组 分块,直到 剩下 4 个或更少数字。剩下的数字将按下述规定再分块:
+ - 2 个数字:单个含 2 个数字的块。
+ - 3 个数字:单个含 3 个数字的块。
+ - 4 个数字:两个分别含 2 个数字的块。
+
+最后用破折号将这些块连接起来。注意,重新格式化过程中 不应该 生成仅含 1 个数字的块,并且 最多 生成两个含 2 个数字的块。返回格式化后的电话号码。
+
+## 解题思路
+
+- 简单题。先判断号码是不是 2 位和 4 位,如果是,单独输出这 2 种情况。剩下的都是 3 位以上了,取余,判断剩余的数字是 2 个还是 4 个。这时不可能存在剩 1 位数的情况。除 3 余 1,即剩 4 位的情况,末尾 4 位需要 2 个一组输出。除 3 余 2,即剩 2 位的情况。处理好末尾,再逆序每 3 个一组连接 "-" 即可。可能需要注意的 case 见 test 文件。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "strings"
+)
+
+func reformatNumber(number string) string {
+ parts, nums := []string{}, []rune{}
+ for _, r := range number {
+ if r != '-' && r != ' ' {
+ nums = append(nums, r)
+ }
+ }
+ threeDigits, twoDigits := len(nums)/3, 0
+ switch len(nums) % 3 {
+ case 1:
+ threeDigits--
+ twoDigits = 2
+ case 2:
+ twoDigits = 1
+ default:
+ twoDigits = 0
+ }
+ for i := 0; i < threeDigits; i++ {
+ s := ""
+ s += string(nums[0:3])
+ nums = nums[3:]
+ parts = append(parts, s)
+ }
+ for i := 0; i < twoDigits; i++ {
+ s := ""
+ s += string(nums[0:2])
+ nums = nums[2:]
+ parts = append(parts, s)
+ }
+ return strings.Join(parts, "-")
+}
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1695.Maximum-Erasure-Value.md b/website/content/ChapterFour/1695.Maximum-Erasure-Value.md
new file mode 100644
index 00000000..890a6128
--- /dev/null
+++ b/website/content/ChapterFour/1695.Maximum-Erasure-Value.md
@@ -0,0 +1,82 @@
+# [1695. Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/)
+
+
+## 题目
+
+You are given an array of positive integers `nums` and want to erase a subarray containing **unique elements**. The **score** you get by erasing the subarray is equal to the **sum** of its elements.
+
+Return *the **maximum score** you can get by erasing **exactly one** subarray.*
+
+An array `b` is called to be a subarray of `a` if it forms a contiguous subsequence of `a`, that is, if it is equal to `a[l],a[l+1],...,a[r]` for some `(l,r)`.
+
+**Example 1**:
+
+```
+Input: nums = [4,2,4,5,6]
+Output: 17
+Explanation: The optimal subarray here is [2,4,5,6].
+```
+
+**Example 2**:
+
+```
+Input: nums = [5,2,1,2,5,2,1,2,5]
+Output: 8
+Explanation: The optimal subarray here is [5,2,1] or [1,2,5].
+```
+
+**Constraints**:
+
+- `1 <= nums.length <= 105`
+- `1 <= nums[i] <= 104`
+
+## 题目大意
+
+给你一个正整数数组 nums ,请你从中删除一个含有 若干不同元素 的子数组。删除子数组的 得分 就是子数组各元素之 和 。返回 只删除一个 子数组可获得的 最大得分 。如果数组 b 是数组 a 的一个连续子序列,即如果它等于 a[l],a[l+1],...,a[r] ,那么它就是 a 的一个子数组。
+
+## 解题思路
+
+- 读完题立马能识别出这是经典的滑动窗口题。利用滑动窗口从左往右滑动窗口,滑动过程中统计频次,如果是不同元素,右边界窗口又移,否则左边窗口缩小。每次移动更新 max 值。最终扫完一遍以后,max 值即为所求。
+
+## 代码
+
+```go
+package leetcode
+
+func maximumUniqueSubarray(nums []int) int {
+ if len(nums) == 0 {
+ return 0
+ }
+ result, left, right, freq := 0, 0, -1, map[int]int{}
+ for left < len(nums) {
+ if right+1 < len(nums) && freq[nums[right+1]] == 0 {
+ freq[nums[right+1]]++
+ right++
+ } else {
+ freq[nums[left]]--
+ left++
+ }
+ sum := 0
+ for i := left; i <= right; i++ {
+ sum += nums[i]
+ }
+ result = max(result, sum)
+ }
+ return result
+}
+
+func max(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/1696.Jump-Game-VI.md b/website/content/ChapterFour/1696.Jump-Game-VI.md
new file mode 100644
index 00000000..9186a0f5
--- /dev/null
+++ b/website/content/ChapterFour/1696.Jump-Game-VI.md
@@ -0,0 +1,114 @@
+# [1696. Jump Game VI](https://leetcode.com/problems/jump-game-vi/)
+
+## 题目
+
+You are given a **0-indexed** integer array `nums` and an integer `k`.
+
+You are initially standing at index `0`. In one move, you can jump at most `k` steps forward without going outside the boundaries of the array. That is, you can jump from index `i` to any index in the range `[i + 1, min(n - 1, i + k)]` **inclusive**.
+
+You want to reach the last index of the array (index `n - 1`). Your **score** is the **sum** of all `nums[j]` for each index `j` you visited in the array.
+
+Return *the **maximum score** you can get*.
+
+**Example 1:**
+
+```
+Input: nums = [1,-1,-2,4,-7,3], k = 2
+Output: 7
+Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.
+
+```
+
+**Example 2:**
+
+```
+Input: nums = [10,-5,-2,4,0,3], k = 3
+Output: 17
+Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.
+
+```
+
+**Example 3:**
+
+```
+Input: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2
+Output: 0
+
+```
+
+**Constraints:**
+
+- `1 <= nums.length, k <= 10^5`
+- `10^4 <= nums[i] <= 10^4`
+
+## 题目大意
+
+给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。一开始你在下标 0 处。每一步,你最多可以往前跳 k 步,但你不能跳出数组的边界。也就是说,你可以从下标 i 跳到 [i + 1, min(n - 1, i + k)] 包含 两个端点的任意位置。你的目标是到达数组最后一个位置(下标为 n - 1 ),你的 得分 为经过的所有数字之和。请你返回你能得到的 最大得分 。
+
+## 解题思路
+
+- 首先能想到的解题思路是动态规划。定义 `dp[i]` 为跳到第 `i` 个位子能获得的最大分数。题目要求的是 `dp[n-1]`,状态转移方程是:`dp[i] = nums[i] + max(dp[j]), max(0, i - k ) <= j < i`,这里需要注意 `j` 的下界,题目中说到不能跳到负数区间,所以左边界下界为 0 。求 `max(dp[j])` 需要遍历一次求得最大值,所以这个解法整体时间复杂度是 O((n - k) * k),但是提交以后提示超时了。
+- 分析一下超时原因。每次都要在 `[max(0, i - k ), i)` 区间内扫描找到最大值,下一轮的区间是 `[max(0, i - k + 1), i + 1)`,前后这两轮扫描的区间存在大量重合部分 `[max(0, i - k + 1), i)`,正是这部分反反复复的扫描导致算法低效。如何高效的在一个区间内找到最大值是本题的关键。利用单调队列可以完成此题。单调队列里面存一个区间内最大值的下标。这里单调队列有 2 个性质。性质一,队列的队首永远都是最大值,队列从大到小降序排列。如果来了一个比队首更大的值的下标,需要将单调队列清空,只存这个新的最大值的下标。性质二,队列的长度为 k。从队尾插入新值,并把队头的最大值“挤”出队首。拥有了这个单调队列以后,再进行 DP 状态转移,效率就很高了。每次只需取出队首的最大值即可。具体代码见下面。
+
+## 代码
+
+```go
+package leetcode
+
+import (
+ "math"
+)
+
+// 单调队列
+func maxResult(nums []int, k int) int {
+ dp := make([]int, len(nums))
+ dp[0] = nums[0]
+ for i := 1; i < len(dp); i++ {
+ dp[i] = math.MinInt32
+ }
+ window := make([]int, k)
+ for i := 1; i < len(nums); i++ {
+ dp[i] = nums[i] + dp[window[0]]
+ for len(window) > 0 && dp[window[len(window)-1]] <= dp[i] {
+ window = window[:len(window)-1]
+ }
+ for len(window) > 0 && i-k >= window[0] {
+ window = window[1:]
+ }
+ window = append(window, i)
+ }
+ return dp[len(nums)-1]
+}
+
+// 超时
+func maxResult1(nums []int, k int) int {
+ dp := make([]int, len(nums))
+ if k > len(nums) {
+ k = len(nums)
+ }
+ dp[0] = nums[0]
+ for i := 1; i < len(dp); i++ {
+ dp[i] = math.MinInt32
+ }
+ for i := 1; i < len(nums); i++ {
+ left, tmp := max(0, i-k), math.MinInt32
+ for j := left; j < i; j++ {
+ tmp = max(tmp, dp[j])
+ }
+ dp[i] = nums[i] + tmp
+ }
+ return dp[len(nums)-1]
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+----------------------------------------------
+⬅️上一页
+
diff --git a/website/content/ChapterFour/_index.md b/website/content/ChapterFour/_index.md
index 3daf13a7..bcc5b320 100644
--- a/website/content/ChapterFour/_index.md
+++ b/website/content/ChapterFour/_index.md
@@ -14,4 +14,11 @@ type: docs
题解慢慢更新中,欢迎大家提出更好的解法。点击页面下方的 edit,会跳转到 github 对应的页面 markdown 中,可以提交你的最优解 PR。
-让我们在题解的太空遨游吧~
\ No newline at end of file
+让我们在题解的太空遨游吧~
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterFour/pytool/CutContent.py b/website/content/ChapterFour/pytool/CutContent.py
new file mode 100644
index 00000000..28dbc720
--- /dev/null
+++ b/website/content/ChapterFour/pytool/CutContent.py
@@ -0,0 +1,24 @@
+import os
+import re
+import glob
+
+# file_name = 'Array.md'
+reg = "## 题目大意"
+
+current_working_dir = os.getcwd()
+# print(f"current_working_dir: {current_working_dir}")
+
+dir_names = glob.glob("*.md")
+dir_names.sort()
+print(len(dir_names))
+
+for file_name in dir_names:
+ # print(file_name)
+ with open(file_name, "r") as myfile:
+ codeContent = myfile.read()
+ findIndex = codeContent.find(reg)
+ # print(findIndex)
+ content = codeContent[findIndex:]
+ with open(file_name, "w") as myfile:
+ myfile.write(content)
+print("Finished")
\ No newline at end of file
diff --git a/website/content/ChapterFour/pytool/WordCount.py b/website/content/ChapterFour/pytool/WordCount.py
new file mode 100644
index 00000000..3bae213e
--- /dev/null
+++ b/website/content/ChapterFour/pytool/WordCount.py
@@ -0,0 +1,29 @@
+from collections import defaultdict
+import glob
+import os
+
+
+def str_count2(str):
+ count_zh = count_dg = 0
+ for s in str:
+ # 中文字符范围
+ if '\u4e00' <= s <= '\u9fff':
+ count_zh += 1
+ if s.isdigit():
+ count_dg += 1
+ # print(count_zh + count_dg)
+ return count_zh + count_dg
+
+current_working_dir = os.getcwd()
+# print(f"current_working_dir: {current_working_dir}")
+
+dir_names = glob.glob("*.md")
+dir_names.sort()
+
+word_count = 0
+for file_name in dir_names:
+ with open(file_name, "r") as myfile:
+ codeContent = myfile.read()
+ print("当前读取文件: {}, 字数统计: {}".format(file_name, str_count2(codeContent)))
+ word_count += str_count2(codeContent)
+print(word_count)
\ No newline at end of file
diff --git a/website/content/ChapterOne/Algorithm.md b/website/content/ChapterOne/Algorithm.md
index bd094783..bdf96932 100644
--- a/website/content/ChapterOne/Algorithm.md
+++ b/website/content/ChapterOne/Algorithm.md
@@ -23,4 +23,11 @@ type: docs
|几何||1. 凸包 - Gift wrapping 2. 凸包 - Graham scan 3. 线段问题 4. 多边形和多面体相关问题 ||
|NP 完全|1. 计算模型 2. P 类与 NP 类问题 3. NP 完全问题 4. NP 完全问题的近似算法 |1. 随机存取机 RAM 2. 随机存取存储程序机 RASP 3. 图灵机 4. 非确定性图灵机 5. P 类与 NP 类语言 6. 多项式时间验证 7. 多项式时间变换 8. Cook定理 9. 合取范式的可满足性问题 CNF-SAT 10. 3 元合取范式的可满足性问题 3-SAT 11. 团问题 CLIQUE 12. 顶点覆盖问题 VERTEX-COVER 13. 子集和问题 SUBSET-SUM 14. 哈密顿回路问题 HAM-CYCLE 15. 旅行售货员问题 TSP 16. 顶点覆盖问题的近似算法 17. 旅行售货员问题近似算法 18. 具有三角不等式性质的旅行售货员问题 19. 一般的旅行售货员问题 20. 集合覆盖问题的近似算法 21. 子集和问题的近似算法 22. 子集和问题的指数时间算法 23. 子集和问题的多项式时间近似格式 ||
|位运算| 位操作包括: 1. 取反(NOT) 2. 按位或(OR) 3. 按位异或(XOR) 4. 按位与(AND) 5. 移位: 是一个二元运算符,用来将一个二进制数中的每一位全部都向一个方向移动指定位,溢出的部分将被舍弃,而空缺的部分填入一定的值。 | 1.数字范围按位与 2.UTF-8 编码验证 3.数字转换为十六进制数 4.找出最长的超赞子字符串 5.数组异或操作 6.幂集 7.位1的个数 8.二进制表示中质数个计算置位 9.子数组异或查询 | [力扣:位运算](https://leetcode-cn.com/tag/bit-manipulation/)
-|------------|------------------------------------------------------------------|-----------------------------------------------------------------|--------------------|
\ No newline at end of file
+|------------|------------------------------------------------------------------|-----------------------------------------------------------------|--------------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterOne/Data_Structure.md b/website/content/ChapterOne/Data_Structure.md
index f4aec542..1d9ca35f 100644
--- a/website/content/ChapterOne/Data_Structure.md
+++ b/website/content/ChapterOne/Data_Structure.md
@@ -11,14 +11,21 @@ type: docs
| 数据结构 | 变种 | 相关题目 | 讲解文章 |
|:-------:|:-------|:------|:------|
-|顺序线性表:向量||||
-|单链表|1. 双向链表 2. 静态链表 3. 对称矩阵 4. 稀疏矩阵|||
-|哈希表|1. 散列函数 2. 解决碰撞/填充因子 |||
-|栈和队列|1. 广义栈 2. 双端队列 |||
-|队列|1. 链表实现 2. 循环数组实现 3. 双端队列|||
-|字符串|1. KMP算法 2. 有限状态自动机 3. 模式匹配有限状态自动机 4. BM 模式匹配算法 5. BM-KMP 算法 6. BF 算法|||
-|树|1. 二叉树 2. 并查集 3. Huffman 树|||
-|数组实现的堆|1. 极大堆和极小堆 2. 极大极小堆 3. 双端堆 4. d 叉堆|||
-|树实现的堆|1. 左堆 2. 扁堆 3. 二项式堆 4. 斐波那契堆 5. 配对堆|||
-|查找|1. 哈希表 2. 跳跃表 3. 排序二叉树 4. AVL 树 5. B 树 / B+ 树 / B* 树 6. AA 树 7. 红黑树 8. 排序二叉堆 9. Splay 树 10. 双链树 11. Trie 树 12. R 树|||
-|--------------------------------------------|--------------------------------------------------------------------------------------------|---------------------------|-----------------------------------|
\ No newline at end of file
+|顺序线性表:向量 Vector||||
+|单链表 Singly Linked List|1. 双向链表 Double Linked Lists 2. 静态链表 Static List 3. 对称矩阵 Symmetric Matrix 4. 稀疏矩阵 Sparse Matrix|||
+|哈希表 Hash Table|1. 散列函数 Hash Function 2. 解决碰撞/填充因子 |||
+|栈和队列 Stack & Queue|1. 广义栈 2. 双端队列 Deque |||
+|队列 Queue|1. 链表实现 2. 循环数组实现 3. 双端队列 Deque|||
+|字符串 String|1. KMP 算法 2. 有限状态自动机 3. 模式匹配有限状态自动机 4. BM 模式匹配算法 5. BM-KMP 算法 6. BF 算法|||
+|树 Tree|1. 二叉树 Binary Tree 2. 并查集 Union-Find 3. Huffman 树|||
+|数组实现的堆 Heap|1. 极大堆和极小堆 2. 极大极小堆 3. 双端堆 Deap 4. d 叉堆|||
+|树实现的堆 Heap|1. 左堆 2. 扁堆 3. 二项式堆 4. 斐波那契堆 Fibonacco Heap 5. 配对堆 Pairing Heap|||
+|查找 Find|1. 哈希表 Hash 2. 跳跃表 Skip List 3. 排序二叉树 Binary Sort Tree 4. AVL 树 5. B 树 / B+ 树 / B* 树 6. AA 树 7. 红黑树 Red Black Tree 8. 排序二叉堆 Binary Heap 9. Splay 树 10. 双链树 Double Chained Tree 11. Trie 树 12. R 树|||
+|--------------------------------------------|--------------------------------------------------------------------------------------------|---------------------------|-----------------------------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterOne/_index.md b/website/content/ChapterOne/_index.md
index 1016b57c..0eba551e 100644
--- a/website/content/ChapterOne/_index.md
+++ b/website/content/ChapterOne/_index.md
@@ -86,4 +86,9 @@ LeetCode 统计代码运行时长会有波动的,相同的代码提交 10 次
本作品采用 [知识署名-非商业性使用-禁止演绎 (BY-NC-ND) 4.0 国际许可协议](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode.zh-Hans) 进行许可。
-题解里面的所有题目版权均归 [LeetCode](https://leetcode.com/) 和 [力扣中国](https://leetcode-cn.com/) 所有
\ No newline at end of file
+题解里面的所有题目版权均归 [LeetCode](https://leetcode.com/) 和 [力扣中国](https://leetcode-cn.com/) 所有
+
+
+----------------------------------------------
+下一页➡️
+
diff --git a/website/content/ChapterThree/LFUCache.md b/website/content/ChapterThree/LFUCache.md
new file mode 100644
index 00000000..b176f6db
--- /dev/null
+++ b/website/content/ChapterThree/LFUCache.md
@@ -0,0 +1,367 @@
+---
+title: LFUCache
+type: docs
+---
+
+# 最不经常最少使用 LFUCache
+
+
+
+LFU 是 Least Frequently Used 的缩写,即最不经常最少使用,也是一种常用的页面置换算法,选择访问计数器最小的页面予以淘汰。如下图,缓存中每个页面带一个访问计数器。
+
+
+
+
+根据 LFU 的策略,每访问一次都要更新访问计数器。当插入 B 的时候,发现缓存中有 B,所以增加访问计数器的计数,并把 B 移动到访问计数器从大到小排序的地方。再插入 D,同理先更新计数器,再移动到它排序以后的位置。当插入 F 的时候,缓存中不存在 F,所以淘汰计数器最小的页面的页面,所以淘汰 A 页面。此时 F 排在最下面,计数为 1。
+
+
+
+这里有一个比 LRU 特别的地方。如果淘汰的页面访问次数有多个相同的访问次数,选择最靠尾部的。如上图中,A、B、C 三者的访问次数相同,都是 1 次。要插入 F,F 不在缓存中,此时要淘汰 A 页面。F 是新插入的页面,访问次数为 1,排在 C 的前面。也就是说相同的访问次数,按照新旧顺序排列,淘汰掉最旧的页面。这一点是和 LRU 最大的不同的地方。
+
+可以发现,**LFU 更新和插入新页面可以发生在链表中任意位置,删除页面都发生在表尾**。
+
+
+## 解法一 Get O(1) / Put O(1)
+
+LFU 同样要求查询尽量高效,O(1) 内查询。依旧选用 map 查询。修改和删除也需要 O(1) 完成,依旧选用双向链表,继续复用 container 包中的 list 数据结构。LFU 需要记录访问次数,所以每个结点除了存储 key,value,需要再多存储 frequency 访问次数。
+
+还有 1 个问题需要考虑,一个是如何按频次排序?相同频次,按照先后顺序排序。如果你开始考虑排序算法的话,思考方向就偏离最佳答案了。排序至少 O(nlogn)。重新回看 LFU 的工作原理,会发现它只关心最小频次。其他频次之间的顺序并不关心。所以不需要排序。用一个 min 变量保存最小频次,淘汰时读取这个最小值能找到要删除的结点。相同频次按照先后顺序排列,这个需求还是用双向链表实现,双向链表插入的顺序体现了结点的先后顺序。相同频次对应一个双向链表,可能有多个相同频次,所以可能有多个双向链表。用一个 map 维护访问频次和双向链表的对应关系。删除最小频次时,通过 min 找到最小频次,然后再这个 map 中找到这个频次对应的双向链表,在双向链表中找到最旧的那个结点删除。这就解决了 LFU 删除操作。
+
+LFU 的更新操作和 LRU 类似,也需要用一个 map 保存 key 和双向链表结点的映射关系。这个双向链表结点中存储的是 key-value-frequency 三个元素的元组。这样通过结点中的 key 和 frequency 可以反过来删除 map 中的 key。
+
+定义 LFUCache 的数据结构如下:
+
+```go
+
+import "container/list"
+
+type LFUCache struct {
+ nodes map[int]*list.Element
+ lists map[int]*list.List
+ capacity int
+ min int
+}
+
+type node struct {
+ key int
+ value int
+ frequency int
+}
+
+func Constructor(capacity int) LFUCache {
+ return LFUCache{nodes: make(map[int]*list.Element),
+ lists: make(map[int]*list.List),
+ capacity: capacity,
+ min: 0,
+ }
+}
+
+```
+
+LFUCache 的 Get 操作涉及更新 frequency 值和 2 个 map。在 nodes map 中通过 key 获取到结点信息。在 lists 删除结点当前 frequency 结点。删完以后 frequency ++。新的 frequency 如果在 lists 中存在,添加到双向链表表首,如果不存在,需要新建一个双向链表并把当前结点加到表首。再更新双向链表结点作为 value 的 map。最后更新 min 值,判断老的 frequency 对应的双向链表中是否已经为空,如果空了,min++。
+
+```go
+func (this *LFUCache) Get(key int) int {
+ value, ok := this.nodes[key]
+ if !ok {
+ return -1
+ }
+ currentNode := value.Value.(*node)
+ this.lists[currentNode.frequency].Remove(value)
+ currentNode.frequency++
+ if _, ok := this.lists[currentNode.frequency]; !ok {
+ this.lists[currentNode.frequency] = list.New()
+ }
+ newList := this.lists[currentNode.frequency]
+ newNode := newList.PushFront(currentNode)
+ this.nodes[key] = newNode
+ if currentNode.frequency-1 == this.min && this.lists[currentNode.frequency-1].Len() == 0 {
+ this.min++
+ }
+ return currentNode.value
+}
+
+```
+
+LFU 的 Put 操作逻辑稍微多一点。先在 nodes map 中查询 key 是否存在,如果存在,获取这个结点,更新它的 value 值,然后手动调用一次 Get 操作,因为下面的更新逻辑和 Get 操作一致。如果 map 中不存在,接下来进行插入或者删除操作。判断 capacity 是否装满,如果装满,执行删除操作。在 min 对应的双向链表中删除表尾的结点,对应的也要删除 nodes map 中的键值。
+
+由于新插入的页面访问次数一定为 1,所以 min 此时置为 1。新建结点,插入到 2 个 map 中。
+
+```go
+
+func (this *LFUCache) Put(key int, value int) {
+ if this.capacity == 0 {
+ return
+ }
+ // 如果存在,更新访问次数
+ if currentValue, ok := this.nodes[key]; ok {
+ currentNode := currentValue.Value.(*node)
+ currentNode.value = value
+ this.Get(key)
+ return
+ }
+ // 如果不存在且缓存满了,需要删除
+ if this.capacity == len(this.nodes) {
+ currentList := this.lists[this.min]
+ backNode := currentList.Back()
+ delete(this.nodes, backNode.Value.(*node).key)
+ currentList.Remove(backNode)
+ }
+ // 新建结点,插入到 2 个 map 中
+ this.min = 1
+ currentNode := &node{
+ key: key,
+ value: value,
+ frequency: 1,
+ }
+ if _, ok := this.lists[1]; !ok {
+ this.lists[1] = list.New()
+ }
+ newList := this.lists[1]
+ newNode := newList.PushFront(currentNode)
+ this.nodes[key] = newNode
+}
+
+```
+
+总结,LFU 是由两个 map 和一个 min 指针组成的数据结构。一个 map 中 key 存的是访问次数,对应的 value 是一个个的双向链表,此处双向链表的作用是在相同频次的情况下,淘汰表尾最旧的那个页面。另一个 map 中 key 对应的 value 是双向链表的结点,结点中比 LRU 多存储了一个访问次数的值,即结点中存储 key-value-frequency 的元组。此处双向链表的作用和 LRU 是类似的,可以根据 map 中的 key 更新双向链表结点中的 value 和 frequency 的值,也可以根据双向链表结点中的 key 和 frequency 反向更新 map 中的对应关系。如下图:
+
+
+
+提交代码以后,成功通过所有测试用例。
+
+
+
+
+
+## 解法二 Get O(capacity) / Put O(capacity)
+
+LFU 的另外一个思路是利用 [Index Priority Queue](https://algs4.cs.princeton.edu/24pq/) 这个数据结构。别被名字吓到,Index Priority Queue = map + Priority Queue,仅此而已。
+
+利用 Priority Queue 维护一个最小堆,堆顶是访问次数最小的元素。map 中的 value 存储的是优先队列中结点。
+
+```go
+import "container/heap"
+
+type LFUCache struct {
+ capacity int
+ pq PriorityQueue
+ hash map[int]*Item
+ counter int
+}
+
+func Constructor(capacity int) LFUCache {
+ lfu := LFUCache{
+ pq: PriorityQueue{},
+ hash: make(map[int]*Item, capacity),
+ capacity: capacity,
+ }
+ return lfu
+}
+
+```
+
+Get 和 Put 操作要尽量的快,有 2 个问题需要解决。当访问次数相同时,如何删除掉最久的元素?当元素的访问次数发生变化时,如何快速调整堆?为了解决这 2 个问题,定义如下的数据结构:
+
+```go
+// An Item is something we manage in a priority queue.
+type Item struct {
+ value int // The value of the item; arbitrary.
+ key int
+ frequency int // The priority of the item in the queue.
+ count int // use for evicting the oldest element
+ // The index is needed by update and is maintained by the heap.Interface methods.
+ index int // The index of the item in the heap.
+}
+
+```
+
+堆中的结点存储这 5 个值。count 值用来决定哪个是最老的元素,类似一个操作时间戳。index 值用来 re-heapify 调整堆的。接下来实现 PriorityQueue 的方法。
+
+```go
+// A PriorityQueue implements heap.Interface and holds Items.
+type PriorityQueue []*Item
+
+func (pq PriorityQueue) Len() int { return len(pq) }
+
+func (pq PriorityQueue) Less(i, j int) bool {
+ // We want Pop to give us the highest, not lowest, priority so we use greater than here.
+ if pq[i].frequency == pq[j].frequency {
+ return pq[i].count < pq[j].count
+ }
+ return pq[i].frequency < pq[j].frequency
+}
+
+func (pq PriorityQueue) Swap(i, j int) {
+ pq[i], pq[j] = pq[j], pq[i]
+ pq[i].index = i
+ pq[j].index = j
+}
+
+func (pq *PriorityQueue) Push(x interface{}) {
+ n := len(*pq)
+ item := x.(*Item)
+ item.index = n
+ *pq = append(*pq, item)
+}
+
+func (pq *PriorityQueue) Pop() interface{} {
+ old := *pq
+ n := len(old)
+ item := old[n-1]
+ old[n-1] = nil // avoid memory leak
+ item.index = -1 // for safety
+ *pq = old[0 : n-1]
+ return item
+}
+
+// update modifies the priority and value of an Item in the queue.
+func (pq *PriorityQueue) update(item *Item, value int, frequency int, count int) {
+ item.value = value
+ item.count = count
+ item.frequency = frequency
+ heap.Fix(pq, item.index)
+}
+```
+
+在 Less() 方法中,frequency 从小到大排序,frequency 相同的,按 count 从小到大排序。按照优先队列建堆规则,可以得到,frequency 最小的在堆顶,相同的 frequency,count 最小的越靠近堆顶。
+
+在 Swap() 方法中,记得要更新 index 值。在 Push() 方法中,插入时队列的长度即是该元素的 index 值,此处也要记得更新 index 值。update() 方法调用 Fix() 函数。Fix() 函数比先 Remove() 再 Push() 一个新的值,花销要小。所以此处调用 Fix() 函数,这个操作的时间复杂度是 O(log n)。
+
+这样就维护了最小 Index Priority Queue。Get 操作非常简单:
+
+```go
+func (this *LFUCache) Get(key int) int {
+ if this.capacity == 0 {
+ return -1
+ }
+ if item, ok := this.hash[key]; ok {
+ this.counter++
+ this.pq.update(item, item.value, item.frequency+1, this.counter)
+ return item.value
+ }
+ return -1
+}
+
+```
+
+在 hashmap 中查询 key,如果存在,counter 时间戳累加,调用 Priority Queue 的 update 方法,调整堆。
+
+```go
+func (this *LFUCache) Put(key int, value int) {
+ if this.capacity == 0 {
+ return
+ }
+ this.counter++
+ // 如果存在,增加 frequency,再调整堆
+ if item, ok := this.hash[key]; ok {
+ this.pq.update(item, value, item.frequency+1, this.counter)
+ return
+ }
+ // 如果不存在且缓存满了,需要删除。在 hashmap 和 pq 中删除。
+ if len(this.pq) == this.capacity {
+ item := heap.Pop(&this.pq).(*Item)
+ delete(this.hash, item.key)
+ }
+ // 新建结点,在 hashmap 和 pq 中添加。
+ item := &Item{
+ value: value,
+ key: key,
+ count: this.counter,
+ }
+ heap.Push(&this.pq, item)
+ this.hash[key] = item
+}
+```
+
+
+用最小堆实现的 LFU,Put 时间复杂度是 O(capacity),Get 时间复杂度是 O(capacity),不及 2 个 map 实现的版本。巧的是最小堆的版本居然打败了 100%。
+
+
+
+
+## 模板
+
+
+```go
+import "container/list"
+
+type LFUCache struct {
+ nodes map[int]*list.Element
+ lists map[int]*list.List
+ capacity int
+ min int
+}
+
+type node struct {
+ key int
+ value int
+ frequency int
+}
+
+func Constructor(capacity int) LFUCache {
+ return LFUCache{nodes: make(map[int]*list.Element),
+ lists: make(map[int]*list.List),
+ capacity: capacity,
+ min: 0,
+ }
+}
+
+func (this *LFUCache) Get(key int) int {
+ value, ok := this.nodes[key]
+ if !ok {
+ return -1
+ }
+ currentNode := value.Value.(*node)
+ this.lists[currentNode.frequency].Remove(value)
+ currentNode.frequency++
+ if _, ok := this.lists[currentNode.frequency]; !ok {
+ this.lists[currentNode.frequency] = list.New()
+ }
+ newList := this.lists[currentNode.frequency]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+ if currentNode.frequency-1 == this.min && this.lists[currentNode.frequency-1].Len() == 0 {
+ this.min++
+ }
+ return currentNode.value
+}
+
+func (this *LFUCache) Put(key int, value int) {
+ if this.capacity == 0 {
+ return
+ }
+ if currentValue, ok := this.nodes[key]; ok {
+ currentNode := currentValue.Value.(*node)
+ currentNode.value = value
+ this.Get(key)
+ return
+ }
+ if this.capacity == len(this.nodes) {
+ currentList := this.lists[this.min]
+ frontNode := currentList.Front()
+ delete(this.nodes, frontNode.Value.(*node).key)
+ currentList.Remove(frontNode)
+ }
+ this.min = 1
+ currentNode := &node{
+ key: key,
+ value: value,
+ frequency: 1,
+ }
+ if _, ok := this.lists[1]; !ok {
+ this.lists[1] = list.New()
+ }
+ newList := this.lists[1]
+ newNode := newList.PushBack(currentNode)
+ this.nodes[key] = newNode
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterThree/LRUCache.md b/website/content/ChapterThree/LRUCache.md
new file mode 100644
index 00000000..e4b3816f
--- /dev/null
+++ b/website/content/ChapterThree/LRUCache.md
@@ -0,0 +1,279 @@
+---
+title: LRUCache
+type: docs
+---
+
+# 最近最少使用 LRUCache
+
+
+
+LRU 是 Least Recently Used 的缩写,即最近最少使用,是一种常用的页面置换算法,选择最近最久未使用的页面予以淘汰。如上图,要插入 F 的时候,此时需要淘汰掉原来的一个页面。
+
+
+
+根据 LRU 的策略,每次都淘汰最近最久未使用的页面,所以先淘汰 A 页面。再插入 C 的时候,发现缓存中有 C 页面,这个时候需要把 C 页面放到首位,因为它被使用了。以此类推,插入 G 页面,G 页面是新页面,不在缓存中,所以淘汰掉 B 页面。插入 H 页面,H 页面是新页面,不在缓存中,所以淘汰掉 D 页面。插入 E 的时候,发现缓存中有 E 页面,这个时候需要把 E 页面放到首位。插入 I 页面,I 页面是新页面,不在缓存中,所以淘汰掉 F 页面。
+
+可以发现,**LRU 更新和插入新页面都发生在链表首,删除页面都发生在链表尾**。
+
+## 解法一 Get O(1) / Put O(1)
+
+LRU 要求查询尽量高效,O(1) 内查询。那肯定选用 map 查询。修改,删除也要尽量 O(1) 完成。搜寻常见的数据结构,链表,栈,队列,树,图。树和图排除,栈和队列无法任意查询中间的元素,也排除。所以选用链表来实现。但是如果选用单链表,删除这个结点,需要 O(n) 遍历一遍找到前驱结点。所以选用双向链表,在删除的时候也能 O(1) 完成。
+
+由于 Go 的 container 包中的 list 底层实现是双向链表,所以可以直接复用这个数据结构。定义 LRUCache 的数据结构如下:
+
+```go
+import "container/list"
+
+type LRUCache struct {
+ Cap int
+ Keys map[int]*list.Element
+ List *list.List
+}
+
+type pair struct {
+ K, V int
+}
+
+func Constructor(capacity int) LRUCache {
+ return LRUCache{
+ Cap: capacity,
+ Keys: make(map[int]*list.Element),
+ List: list.New(),
+ }
+}
+
+```
+
+这里需要解释 2 个问题,list 中的值存的是什么?pair 这个结构体有什么用?
+
+```go
+type Element struct {
+ // Next and previous pointers in the doubly-linked list of elements.
+ // To simplify the implementation, internally a list l is implemented
+ // as a ring, such that &l.root is both the next element of the last
+ // list element (l.Back()) and the previous element of the first list
+ // element (l.Front()).
+ next, prev *Element
+
+ // The list to which this element belongs.
+ list *List
+
+ // The value stored with this element.
+ Value interface{}
+}
+```
+
+在 container/list 中,这个双向链表的每个结点的类型是 Element。Element 中存了 4 个值,前驱和后继结点,双向链表的头结点,value 值。这里的 value 是 interface 类型。笔者在这个 value 里面存了 pair 这个结构体。这就解释了 list 里面存的是什么数据。
+
+为什么要存 pair 呢?单单指存 v 不行么,为什么还要存一份 key ?原因是在 LRUCache 执行删除操作的时候,需要维护 2 个数据结构,一个是 map,一个是双向链表。在双向链表中删除淘汰出去的 value,在 map 中删除淘汰出去 value 对应的 key。如果在双向链表的 value 中不存储 key,那么再删除 map 中的 key 的时候有点麻烦。如果硬要实现,需要先获取到双向链表这个结点 Element 的地址。然后遍历 map,在 map 中找到存有这个 Element 元素地址对应的 key,再删除。这样做时间复杂度是 O(n),做不到 O(1)。所以双向链表中的 Value 需要存储这个 pair。
+
+LRUCache 的 Get 操作很简单,在 map 中直接读取双向链表的结点。如果 map 中存在,将它移动到双向链表的表头,并返回它的 value 值,如果 map 中不存在,返回 -1。
+
+```go
+func (c *LRUCache) Get(key int) int {
+ if el, ok := c.Keys[key]; ok {
+ c.List.MoveToFront(el)
+ return el.Value.(pair).V
+ }
+ return -1
+}
+```
+
+LRUCache 的 Put 操作也不难。先查询 map 中是否存在 key,如果存在,更新它的 value,并且把该结点移到双向链表的表头。如果 map 中不存在,新建这个结点加入到双向链表和 map 中。最后别忘记还需要维护双向链表的 cap,如果超过 cap,需要淘汰最后一个结点,双向链表中删除这个结点,map 中删掉这个结点对应的 key。
+
+```go
+func (c *LRUCache) Put(key int, value int) {
+ if el, ok := c.Keys[key]; ok {
+ el.Value = pair{K: key, V: value}
+ c.List.MoveToFront(el)
+ } else {
+ el := c.List.PushFront(pair{K: key, V: value})
+ c.Keys[key] = el
+ }
+ if c.List.Len() > c.Cap {
+ el := c.List.Back()
+ c.List.Remove(el)
+ delete(c.Keys, el.Value.(pair).K)
+ }
+}
+
+```
+
+总结,LRU 是由一个 map 和一个双向链表组成的数据结构。map 中 key 对应的 value 是双向链表的结点。双向链表中存储 key-value 的 pair。双向链表表首更新缓存,表尾淘汰缓存。如下图:
+
+
+
+提交代码以后,成功通过所有测试用例。
+
+
+
+
+## 解法二 Get O(1) / Put O(1)
+
+数据结构上想不到其他解法了,但从打败的百分比上,看似还有常数的优化空间。笔者反复思考,觉得可能导致运行时间变长的地方是在 interface{} 类型推断,其他地方已无优化的空间。手写一个双向链表提交试试,代码如下:
+
+```go
+
+type LRUCache struct {
+ head, tail *Node
+ keys map[int]*Node
+ capacity int
+}
+
+type Node struct {
+ key, val int
+ prev, next *Node
+}
+
+func ConstructorLRU(capacity int) LRUCache {
+ return LRUCache{keys: make(map[int]*Node), capacity: capacity}
+}
+
+func (this *LRUCache) Get(key int) int {
+ if node, ok := this.keys[key]; ok {
+ this.Remove(node)
+ this.Add(node)
+ return node.val
+ }
+ return -1
+}
+
+func (this *LRUCache) Put(key int, value int) {
+ if node, ok := this.keys[key]; ok {
+ node.val = value
+ this.Remove(node)
+ this.Add(node)
+ return
+ } else {
+ node = &Node{key: key, val: value}
+ this.keys[key] = node
+ this.Add(node)
+ }
+ if len(this.keys) > this.capacity {
+ delete(this.keys, this.tail.key)
+ this.Remove(this.tail)
+ }
+}
+
+func (this *LRUCache) Add(node *Node) {
+ node.prev = nil
+ node.next = this.head
+ if this.head != nil {
+ this.head.prev = node
+ }
+ this.head = node
+ if this.tail == nil {
+ this.tail = node
+ this.tail.next = nil
+ }
+}
+
+func (this *LRUCache) Remove(node *Node) {
+ if node == this.head {
+ this.head = node.next
+ if node.next != nil {
+ node.next.prev = nil
+ }
+ node.next = nil
+ return
+ }
+ if node == this.tail {
+ this.tail = node.prev
+ node.prev.next = nil
+ node.prev = nil
+ return
+ }
+ node.prev.next = node.next
+ node.next.prev = node.prev
+}
+
+```
+
+提交以后还真的 100% 了。
+
+
+
+上述代码实现的 LRU 本质并没有优化,只是换了一个写法,没有用 container 包而已。
+
+
+## 模板
+
+```go
+type LRUCache struct {
+ head, tail *Node
+ Keys map[int]*Node
+ Cap int
+}
+
+type Node struct {
+ Key, Val int
+ Prev, Next *Node
+}
+
+func Constructor(capacity int) LRUCache {
+ return LRUCache{Keys: make(map[int]*Node), Cap: capacity}
+}
+
+func (this *LRUCache) Get(key int) int {
+ if node, ok := this.Keys[key]; ok {
+ this.Remove(node)
+ this.Add(node)
+ return node.Val
+ }
+ return -1
+}
+
+func (this *LRUCache) Put(key int, value int) {
+ if node, ok := this.Keys[key]; ok {
+ node.Val = value
+ this.Remove(node)
+ this.Add(node)
+ return
+ } else {
+ node = &Node{Key: key, Val: value}
+ this.Keys[key] = node
+ this.Add(node)
+ }
+ if len(this.Keys) > this.Cap {
+ delete(this.Keys, this.tail.Key)
+ this.Remove(this.tail)
+ }
+}
+
+func (this *LRUCache) Add(node *Node) {
+ node.Prev = nil
+ node.Next = this.head
+ if this.head != nil {
+ this.head.Prev = node
+ }
+ this.head = node
+ if this.tail == nil {
+ this.tail = node
+ this.tail.Next = nil
+ }
+}
+
+func (this *LRUCache) Remove(node *Node) {
+ if node == this.head {
+ this.head = node.Next
+ node.Next = nil
+ return
+ }
+ if node == this.tail {
+ this.tail = node.Prev
+ node.Prev.Next = nil
+ node.Prev = nil
+ return
+ }
+ node.Prev.Next = node.Next
+ node.Next.Prev = node.Prev
+}
+
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterThree/Segment_Tree.md b/website/content/ChapterThree/Segment_Tree.md
index 96160509..da5cf4c0 100644
--- a/website/content/ChapterThree/Segment_Tree.md
+++ b/website/content/ChapterThree/Segment_Tree.md
@@ -272,4 +272,11 @@ func (st *SegmentCountTree) updateCountInTree(treeIndex, left, right, val int) {
}
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterThree/UnionFind.md b/website/content/ChapterThree/UnionFind.md
index e4910131..33cf76a2 100644
--- a/website/content/ChapterThree/UnionFind.md
+++ b/website/content/ChapterThree/UnionFind.md
@@ -141,4 +141,11 @@ func max(a int, b int) int {
return b
}
-```
\ No newline at end of file
+```
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterThree/_index.md b/website/content/ChapterThree/_index.md
index 30eec94a..02f24845 100644
--- a/website/content/ChapterThree/_index.md
+++ b/website/content/ChapterThree/_index.md
@@ -10,4 +10,11 @@ type: docs
-这一章会罗列一些整理好的模板。一起来看看吧。
\ No newline at end of file
+这一章会罗列一些整理好的模板。一起来看看吧。
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Array.md b/website/content/ChapterTwo/Array.md
index 59dfa8f1..f6ebc077 100644
--- a/website/content/ChapterTwo/Array.md
+++ b/website/content/ChapterTwo/Array.md
@@ -5,58 +5,154 @@ type: docs
# Array
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|1. Two Sum| [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)||
-|11. Container With Most Water| [Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})| Medium | O(n)| O(1)||
-|15. 3Sum | [Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|16. 3Sum Closest | [Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
-|26. Remove Duplicates from Sorted Array | [Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|27. Remove Element | [Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})| Easy | O(n)| O(1)||
-|39. Combination Sum | [Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})| Medium | O(n log n)| O(n)||
-|40. Combination Sum II | [Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})| Medium | O(n log n)| O(n)||
-|41. First Missing Positive | [Go]({{< relref "/ChapterFour/0041.First-Missing-Positive.md" >}})| Hard | O(n)| O(n)||
-|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
-|48. Rotate Image | [Go]({{< relref "/ChapterFour/0048.Rotate-Image.md" >}})| Medium | O(n)| O(1)||
-|53. Maximum Subarray| [Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})| Easy | O(n)| O(n)||
-|54. Spiral Matrix| [Go]({{< relref "/ChapterFour/0054.Spiral-Matrix.md" >}})| Medium | O(n)| O(n^2)||
-|56. Merge Intervals | [Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})| Medium | O(n log n)| O(1)||
-|57. Insert Interval | [Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})| Hard | O(n)| O(1)||
-|59. Spiral Matrix II | [Go]({{< relref "/ChapterFour/0059.Spiral-Matrix-II.md" >}})| Medium | O(n)| O(n^2)||
-|62. Unique Paths | [Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})| Medium | O(n^2)| O(n^2)||
-|63. Unique Paths II | [Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|64. Minimum Path Sum | [Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})| Medium | O(n^2)| O(n^2)||
-|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
-|78. Subsets| [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|79. Word Search | [Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
-|80. Remove Duplicates from Sorted Array II| [Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})| Medium | O(n)| O(1||
-|84. Largest Rectangle in Histogram | [Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})| Medium | O(n)| O(n)|❤️|
-|88. Merge Sorted Array | [Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})| Easy | O(n)| O(1)|❤️|
-|90. Subsets II | [Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|120. Triangle | [Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})| Medium | O(n^2)| O(n)||
-|121. Best Time to Buy and Sell Stock | [Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})| Easy | O(n)| O(1)||
-|122. Best Time to Buy and Sell Stock II | [Go]({{< relref "/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md" >}})| Easy | O(n)| O(1)||
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|152. Maximum Product Subarray | [Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})| Medium | O(n)| O(1)||
-|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
-|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
-|216. Combination Sum III | [Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})| Medium | O(n)| O(1)|❤️|
-|217. Contains Duplicate | [Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})| Easy | O(n)| O(n)||
-|219. Contains Duplicate II | [Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})| Easy | O(n)| O(n)||
-|283. Move Zeroes | [Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})| Easy | O(n)| O(1)||
-|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
-|532. K-diff Pairs in an Array | [Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})| Easy | O(n)| O(n)||
-|566. Reshape the Matrix | [Go]({{< relref "/ChapterFour/0566.Reshape-the-Matrix.md" >}})| Easy | O(n^2)| O(n^2)||
-|628. Maximum Product of Three Numbers | [Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})| Easy | O(n)| O(1)||
-|713. Subarray Product Less Than K | [Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})| Medium | O(n)| O(1)||
-|714. Best Time to Buy and Sell Stock with Transaction Fee| [Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})| Medium | O(n)| O(1)||
-|746. Min Cost Climbing Stairs | [Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})| Easy | O(n)| O(1)||
-|766. Toeplitz Matrix | [Go]({{< relref "/ChapterFour/0766.Toeplitz-Matrix.md" >}})| Easy | O(n)| O(1)||
-|867. Transpose Matrix | [Go]({{< relref "/ChapterFour/0867.Transpose-Matrix.md" >}})| Easy | O(n)| O(1)||
-|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
-|907. Sum of Subarray Minimums | [Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})| Medium | O(n)| O(n)|❤️|
-|922. Sort Array By Parity II | [Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})| Medium | O(n)| O(1)||
-|969. Pancake Sorting | [Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})| Medium | O(n)| O(1)|❤️|
-|977. Squares of a Sorted Array | [Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0001|Two Sum|[Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})|Easy| O(n)| O(n)||46.2%|
+|0004|Median of Two Sorted Arrays|[Go]({{< relref "/ChapterFour/0004.Median-of-Two-Sorted-Arrays.md" >}})|Hard||||30.8%|
+|0011|Container With Most Water|[Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})|Medium| O(n)| O(1)||52.2%|
+|0015|3Sum|[Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})|Medium| O(n^2)| O(n)|❤️|27.8%|
+|0016|3Sum Closest|[Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})|Medium| O(n^2)| O(1)|❤️|46.2%|
+|0018|4Sum|[Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})|Medium| O(n^3)| O(n^2)|❤️|34.6%|
+|0026|Remove Duplicates from Sorted Array|[Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})|Easy| O(n)| O(1)||46.3%|
+|0027|Remove Element|[Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})|Easy| O(n)| O(1)||49.0%|
+|0033|Search in Rotated Sorted Array|[Go]({{< relref "/ChapterFour/0033.Search-in-Rotated-Sorted-Array.md" >}})|Medium||||35.7%|
+|0034|Find First and Last Position of Element in Sorted Array|[Go]({{< relref "/ChapterFour/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array.md" >}})|Medium||||37.1%|
+|0035|Search Insert Position|[Go]({{< relref "/ChapterFour/0035.Search-Insert-Position.md" >}})|Easy||||42.8%|
+|0039|Combination Sum|[Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})|Medium| O(n log n)| O(n)||58.8%|
+|0040|Combination Sum II|[Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})|Medium| O(n log n)| O(n)||49.8%|
+|0041|First Missing Positive|[Go]({{< relref "/ChapterFour/0041.First-Missing-Positive.md" >}})|Hard| O(n)| O(n)||33.4%|
+|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|50.8%|
+|0048|Rotate Image|[Go]({{< relref "/ChapterFour/0048.Rotate-Image.md" >}})|Medium| O(n)| O(1)||59.4%|
+|0053|Maximum Subarray|[Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})|Easy| O(n)| O(n)||47.5%|
+|0054|Spiral Matrix|[Go]({{< relref "/ChapterFour/0054.Spiral-Matrix.md" >}})|Medium| O(n)| O(n^2)||35.5%|
+|0055|Jump Game|[Go]({{< relref "/ChapterFour/0055.Jump-Game.md" >}})|Medium||||35.1%|
+|0056|Merge Intervals|[Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})|Medium| O(n log n)| O(1)||40.7%|
+|0057|Insert Interval|[Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})|Medium| O(n)| O(1)||34.9%|
+|0059|Spiral Matrix II|[Go]({{< relref "/ChapterFour/0059.Spiral-Matrix-II.md" >}})|Medium| O(n)| O(n^2)||57.4%|
+|0062|Unique Paths|[Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})|Medium| O(n^2)| O(n^2)||55.6%|
+|0063|Unique Paths II|[Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})|Medium| O(n^2)| O(n^2)||35.1%|
+|0064|Minimum Path Sum|[Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})|Medium| O(n^2)| O(n^2)||55.9%|
+|0066|Plus One|[Go]({{< relref "/ChapterFour/0066.Plus-One.md" >}})|Easy||||42.5%|
+|0074|Search a 2D Matrix|[Go]({{< relref "/ChapterFour/0074.Search-a-2D-Matrix.md" >}})|Medium||||37.4%|
+|0075|Sort Colors|[Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})|Medium| O(n)| O(1)|❤️|49.0%|
+|0078|Subsets|[Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})|Medium| O(n^2)| O(n)|❤️|64.5%|
+|0079|Word Search|[Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})|Medium| O(n^2)| O(n^2)|❤️|36.6%|
+|0080|Remove Duplicates from Sorted Array II|[Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})|Medium| O(n)| O(1||45.9%|
+|0081|Search in Rotated Sorted Array II|[Go]({{< relref "/ChapterFour/0081.Search-in-Rotated-Sorted-Array-II.md" >}})|Medium||||33.5%|
+|0084|Largest Rectangle in Histogram|[Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})|Hard| O(n)| O(n)|❤️|36.8%|
+|0088|Merge Sorted Array|[Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})|Easy| O(n)| O(1)|❤️|40.6%|
+|0090|Subsets II|[Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})|Medium| O(n^2)| O(n)|❤️|48.5%|
+|0105|Construct Binary Tree from Preorder and Inorder Traversal|[Go]({{< relref "/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md" >}})|Medium||||51.3%|
+|0106|Construct Binary Tree from Inorder and Postorder Traversal|[Go]({{< relref "/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md" >}})|Medium||||49.2%|
+|0118|Pascal's Triangle|[Go]({{< relref "/ChapterFour/0118.Pascals-Triangle.md" >}})|Easy||||54.4%|
+|0120|Triangle|[Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})|Medium| O(n^2)| O(n)||45.5%|
+|0121|Best Time to Buy and Sell Stock|[Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})|Easy| O(n)| O(1)||51.3%|
+|0122|Best Time to Buy and Sell Stock II|[Go]({{< relref "/ChapterFour/0122.Best-Time-to-Buy-and-Sell-Stock-II.md" >}})|Easy| O(n)| O(1)||58.3%|
+|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.4%|
+|0128|Longest Consecutive Sequence|[Go]({{< relref "/ChapterFour/0128.Longest-Consecutive-Sequence.md" >}})|Hard||||46.1%|
+|0152|Maximum Product Subarray|[Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})|Medium| O(n)| O(1)||32.6%|
+|0153|Find Minimum in Rotated Sorted Array|[Go]({{< relref "/ChapterFour/0153.Find-Minimum-in-Rotated-Sorted-Array.md" >}})|Medium||||45.9%|
+|0154|Find Minimum in Rotated Sorted Array II|[Go]({{< relref "/ChapterFour/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md" >}})|Hard||||41.9%|
+|0162|Find Peak Element|[Go]({{< relref "/ChapterFour/0162.Find-Peak-Element.md" >}})|Medium||||43.8%|
+|0167|Two Sum II - Input array is sorted|[Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})|Easy| O(n)| O(1)||55.4%|
+|0169|Majority Element|[Go]({{< relref "/ChapterFour/0169.Majority-Element.md" >}})|Easy||||59.9%|
+|0189|Rotate Array|[Go]({{< relref "/ChapterFour/0189.Rotate-Array.md" >}})|Medium||||36.4%|
+|0209|Minimum Size Subarray Sum|[Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})|Medium| O(n)| O(1)||39.2%|
+|0216|Combination Sum III|[Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})|Medium| O(n)| O(1)|❤️|59.9%|
+|0217|Contains Duplicate|[Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})|Easy| O(n)| O(n)||56.5%|
+|0219|Contains Duplicate II|[Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})|Easy| O(n)| O(n)||38.5%|
+|0228|Summary Ranges|[Go]({{< relref "/ChapterFour/0228.Summary-Ranges.md" >}})|Easy||||42.1%|
+|0229|Majority Element II|[Go]({{< relref "/ChapterFour/0229.Majority-Element-II.md" >}})|Medium||||38.5%|
+|0268|Missing Number|[Go]({{< relref "/ChapterFour/0268.Missing-Number.md" >}})|Easy||||53.4%|
+|0283|Move Zeroes|[Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})|Easy| O(n)| O(1)||58.4%|
+|0287|Find the Duplicate Number|[Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})|Medium| O(n)| O(1)|❤️|57.2%|
+|0414|Third Maximum Number|[Go]({{< relref "/ChapterFour/0414.Third-Maximum-Number.md" >}})|Easy||||30.6%|
+|0448|Find All Numbers Disappeared in an Array|[Go]({{< relref "/ChapterFour/0448.Find-All-Numbers-Disappeared-in-an-Array.md" >}})|Easy||||56.1%|
+|0457|Circular Array Loop|[Go]({{< relref "/ChapterFour/0457.Circular-Array-Loop.md" >}})|Medium||||30.0%|
+|0485|Max Consecutive Ones|[Go]({{< relref "/ChapterFour/0485.Max-Consecutive-Ones.md" >}})|Easy||||53.2%|
+|0509|Fibonacci Number|[Go]({{< relref "/ChapterFour/0509.Fibonacci-Number.md" >}})|Easy||||67.3%|
+|0532|K-diff Pairs in an Array|[Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})|Medium| O(n)| O(n)||34.9%|
+|0561|Array Partition I|[Go]({{< relref "/ChapterFour/0561.Array-Partition-I.md" >}})|Easy||||72.9%|
+|0566|Reshape the Matrix|[Go]({{< relref "/ChapterFour/0566.Reshape-the-Matrix.md" >}})|Easy| O(n^2)| O(n^2)||61.0%|
+|0605|Can Place Flowers|[Go]({{< relref "/ChapterFour/0605.Can-Place-Flowers.md" >}})|Easy||||31.9%|
+|0628|Maximum Product of Three Numbers|[Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})|Easy| O(n)| O(1)||47.0%|
+|0661|Image Smoother|[Go]({{< relref "/ChapterFour/0661.Image-Smoother.md" >}})|Easy||||52.2%|
+|0695|Max Area of Island|[Go]({{< relref "/ChapterFour/0695.Max-Area-of-Island.md" >}})|Medium||||64.4%|
+|0697|Degree of an Array|[Go]({{< relref "/ChapterFour/0697.Degree-of-an-Array.md" >}})|Easy||||54.4%|
+|0713|Subarray Product Less Than K|[Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})|Medium| O(n)| O(1)||40.4%|
+|0714|Best Time to Buy and Sell Stock with Transaction Fee|[Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})|Medium| O(n)| O(1)||55.9%|
+|0717|1-bit and 2-bit Characters|[Go]({{< relref "/ChapterFour/0717.1-bit-and-2-bit-Characters.md" >}})|Easy||||47.6%|
+|0718|Maximum Length of Repeated Subarray|[Go]({{< relref "/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md" >}})|Medium||||50.1%|
+|0719|Find K-th Smallest Pair Distance|[Go]({{< relref "/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md" >}})|Hard||||32.4%|
+|0724|Find Pivot Index|[Go]({{< relref "/ChapterFour/0724.Find-Pivot-Index.md" >}})|Easy||||45.0%|
+|0729|My Calendar I|[Go]({{< relref "/ChapterFour/0729.My-Calendar-I.md" >}})|Medium||||53.1%|
+|0746|Min Cost Climbing Stairs|[Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})|Easy| O(n)| O(1)||50.9%|
+|0766|Toeplitz Matrix|[Go]({{< relref "/ChapterFour/0766.Toeplitz-Matrix.md" >}})|Easy| O(n)| O(1)||65.8%|
+|0830|Positions of Large Groups|[Go]({{< relref "/ChapterFour/0830.Positions-of-Large-Groups.md" >}})|Easy||||50.3%|
+|0832|Flipping an Image|[Go]({{< relref "/ChapterFour/0832.Flipping-an-Image.md" >}})|Easy||||77.9%|
+|0867|Transpose Matrix|[Go]({{< relref "/ChapterFour/0867.Transpose-Matrix.md" >}})|Easy| O(n)| O(1)||62.2%|
+|0888|Fair Candy Swap|[Go]({{< relref "/ChapterFour/0888.Fair-Candy-Swap.md" >}})|Easy||||58.8%|
+|0891|Sum of Subsequence Widths|[Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})|Hard| O(n log n)| O(1)||32.8%|
+|0896|Monotonic Array|[Go]({{< relref "/ChapterFour/0896.Monotonic-Array.md" >}})|Easy||||58.0%|
+|0907|Sum of Subarray Minimums|[Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})|Medium| O(n)| O(n)|❤️|33.2%|
+|0914|X of a Kind in a Deck of Cards|[Go]({{< relref "/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})|Easy||||34.4%|
+|0918|Maximum Sum Circular Subarray|[Go]({{< relref "/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md" >}})|Medium||||34.1%|
+|0922|Sort Array By Parity II|[Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})|Easy| O(n)| O(1)||70.2%|
+|0969|Pancake Sorting|[Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})|Medium| O(n)| O(1)|❤️|68.5%|
+|0977|Squares of a Sorted Array|[Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})|Easy| O(n)| O(1)||72.3%|
+|0978|Longest Turbulent Subarray|[Go]({{< relref "/ChapterFour/0978.Longest-Turbulent-Subarray.md" >}})|Medium||||46.6%|
+|0985|Sum of Even Numbers After Queries|[Go]({{< relref "/ChapterFour/0985.Sum-of-Even-Numbers-After-Queries.md" >}})|Easy||||60.7%|
+|0999|Available Captures for Rook|[Go]({{< relref "/ChapterFour/0999.Available-Captures-for-Rook.md" >}})|Easy||||66.8%|
+|1002|Find Common Characters|[Go]({{< relref "/ChapterFour/1002.Find-Common-Characters.md" >}})|Easy||||68.1%|
+|1011|Capacity To Ship Packages Within D Days|[Go]({{< relref "/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md" >}})|Medium||||59.5%|
+|1018|Binary Prefix Divisible By 5|[Go]({{< relref "/ChapterFour/1018.Binary-Prefix-Divisible-By-5.md" >}})|Easy||||47.9%|
+|1040|Moving Stones Until Consecutive II|[Go]({{< relref "/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md" >}})|Medium||||53.9%|
+|1051|Height Checker|[Go]({{< relref "/ChapterFour/1051.Height-Checker.md" >}})|Easy||||71.9%|
+|1052|Grumpy Bookstore Owner|[Go]({{< relref "/ChapterFour/1052.Grumpy-Bookstore-Owner.md" >}})|Medium||||55.7%|
+|1074|Number of Submatrices That Sum to Target|[Go]({{< relref "/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})|Hard||||61.5%|
+|1089|Duplicate Zeros|[Go]({{< relref "/ChapterFour/1089.Duplicate-Zeros.md" >}})|Easy||||52.0%|
+|1122|Relative Sort Array|[Go]({{< relref "/ChapterFour/1122.Relative-Sort-Array.md" >}})|Easy||||67.7%|
+|1128|Number of Equivalent Domino Pairs|[Go]({{< relref "/ChapterFour/1128.Number-of-Equivalent-Domino-Pairs.md" >}})|Easy||||46.6%|
+|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard||||39.5%|
+|1160|Find Words That Can Be Formed by Characters|[Go]({{< relref "/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md" >}})|Easy||||67.5%|
+|1170|Compare Strings by Frequency of the Smallest Character|[Go]({{< relref "/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md" >}})|Easy||||59.5%|
+|1184|Distance Between Bus Stops|[Go]({{< relref "/ChapterFour/1184.Distance-Between-Bus-Stops.md" >}})|Easy||||54.1%|
+|1185|Day of the Week|[Go]({{< relref "/ChapterFour/1185.Day-of-the-Week.md" >}})|Easy||||61.9%|
+|1200|Minimum Absolute Difference|[Go]({{< relref "/ChapterFour/1200.Minimum-Absolute-Difference.md" >}})|Easy||||66.9%|
+|1202|Smallest String With Swaps|[Go]({{< relref "/ChapterFour/1202.Smallest-String-With-Swaps.md" >}})|Medium||||48.4%|
+|1208|Get Equal Substrings Within Budget|[Go]({{< relref "/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md" >}})|Medium||||43.6%|
+|1217|Minimum Cost to Move Chips to The Same Position|[Go]({{< relref "/ChapterFour/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position.md" >}})|Easy||||71.2%|
+|1232|Check If It Is a Straight Line|[Go]({{< relref "/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md" >}})|Easy||||43.8%|
+|1252|Cells with Odd Values in a Matrix|[Go]({{< relref "/ChapterFour/1252.Cells-with-Odd-Values-in-a-Matrix.md" >}})|Easy||||78.6%|
+|1260|Shift 2D Grid|[Go]({{< relref "/ChapterFour/1260.Shift-2D-Grid.md" >}})|Easy||||61.8%|
+|1266|Minimum Time Visiting All Points|[Go]({{< relref "/ChapterFour/1266.Minimum-Time-Visiting-All-Points.md" >}})|Easy||||79.3%|
+|1275|Find Winner on a Tic Tac Toe Game|[Go]({{< relref "/ChapterFour/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md" >}})|Easy||||52.9%|
+|1287|Element Appearing More Than 25% In Sorted Array|[Go]({{< relref "/ChapterFour/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md" >}})|Easy||||60.2%|
+|1295|Find Numbers with Even Number of Digits|[Go]({{< relref "/ChapterFour/1295.Find-Numbers-with-Even-Number-of-Digits.md" >}})|Easy||||79.3%|
+|1299|Replace Elements with Greatest Element on Right Side|[Go]({{< relref "/ChapterFour/1299.Replace-Elements-with-Greatest-Element-on-Right-Side.md" >}})|Easy||||74.2%|
+|1300|Sum of Mutated Array Closest to Target|[Go]({{< relref "/ChapterFour/1300.Sum-of-Mutated-Array-Closest-to-Target.md" >}})|Medium||||43.3%|
+|1304|Find N Unique Integers Sum up to Zero|[Go]({{< relref "/ChapterFour/1304.Find-N-Unique-Integers-Sum-up-to-Zero.md" >}})|Easy||||76.6%|
+|1313|Decompress Run-Length Encoded List|[Go]({{< relref "/ChapterFour/1313.Decompress-Run-Length-Encoded-List.md" >}})|Easy||||85.3%|
+|1380|Lucky Numbers in a Matrix|[Go]({{< relref "/ChapterFour/1380.Lucky-Numbers-in-a-Matrix.md" >}})|Easy||||70.8%|
+|1385|Find the Distance Value Between Two Arrays|[Go]({{< relref "/ChapterFour/1385.Find-the-Distance-Value-Between-Two-Arrays.md" >}})|Easy||||66.4%|
+|1389|Create Target Array in the Given Order|[Go]({{< relref "/ChapterFour/1389.Create-Target-Array-in-the-Given-Order.md" >}})|Easy||||84.7%|
+|1464|Maximum Product of Two Elements in an Array|[Go]({{< relref "/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md" >}})|Easy||||76.9%|
+|1470|Shuffle the Array|[Go]({{< relref "/ChapterFour/1470.Shuffle-the-Array.md" >}})|Easy||||88.5%|
+|1480|Running Sum of 1d Array|[Go]({{< relref "/ChapterFour/1480.Running-Sum-of-1d-Array.md" >}})|Easy||||89.5%|
+|1512|Number of Good Pairs|[Go]({{< relref "/ChapterFour/1512.Number-of-Good-Pairs.md" >}})|Easy||||87.9%|
+|1539|Kth Missing Positive Number|[Go]({{< relref "/ChapterFour/1539.Kth-Missing-Positive-Number.md" >}})|Easy||||55.3%|
+|1640|Check Array Formation Through Concatenation|[Go]({{< relref "/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md" >}})|Easy||||62.1%|
+|1646|Get Maximum in Generated Array|[Go]({{< relref "/ChapterFour/1646.Get-Maximum-in-Generated-Array.md" >}})|Easy||||53.7%|
+|1652|Defuse the Bomb|[Go]({{< relref "/ChapterFour/1652.Defuse-the-Bomb.md" >}})|Easy||||64.2%|
+|1656|Design an Ordered Stream|[Go]({{< relref "/ChapterFour/1656.Design-an-Ordered-Stream.md" >}})|Easy||||82.4%|
+|1672|Richest Customer Wealth|[Go]({{< relref "/ChapterFour/1672.Richest-Customer-Wealth.md" >}})|Easy||||88.5%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Backtracking.md b/website/content/ChapterTwo/Backtracking.md
index 74f112a0..bb044419 100644
--- a/website/content/ChapterTwo/Backtracking.md
+++ b/website/content/ChapterTwo/Backtracking.md
@@ -97,36 +97,48 @@ func updateMatrix_BFS(matrix [][]int) [][]int {
}
```
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|17. Letter Combinations of a Phone Number | [Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})| Medium | O(log n)| O(1)||
-|22. Generate Parentheses| [Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})| Medium | O(log n)| O(1)||
-|37. Sudoku Solver | [Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
-|39. Combination Sum | [Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})| Medium | O(n log n)| O(n)||
-|40. Combination Sum II | [Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})| Medium | O(n log n)| O(n)||
-|46. Permutations | [Go]({{< relref "/ChapterFour/0046.Permutations.md" >}})| Medium | O(n)| O(n)|❤️|
-|47. Permutations II | [Go]({{< relref "/ChapterFour/0047.Permutations-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|51. N-Queens | [Go]({{< relref "/ChapterFour/0051.N-Queens.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|52. N-Queens II | [Go]({{< relref "/ChapterFour/0052.N-Queens-II.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|60. Permutation Sequence | [Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})| Medium | O(n log n)| O(1)||
-|77. Combinations | [Go]({{< relref "/ChapterFour/0077.Combinations.md" >}})| Medium | O(n)| O(n)|❤️|
-|78. Subsets | [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|79. Word Search | [Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
-|89. Gray Codes | [Go]({{< relref "/ChapterFour/0089.Gray-Code.md" >}})| Medium | O(n)| O(1)||
-|90. Subsets II | [Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|93. Restore IP Addresses | [Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})| Medium | O(n)| O(n)|❤️|
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|131. Palindrome Partitioning | [Go]({{< relref "/ChapterFour/0131.Palindrome-Partitioning.md" >}})| Medium | O(n)| O(n^2)|❤️|
-|211. Add and Search Word - Data structure design | [Go]({{< relref "/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md" >}})| Medium | O(n)| O(n)|❤️|
-|212. Word Search II | [Go]({{< relref "/ChapterFour/0212.Word-Search-II.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
-|216. Combination Sum III | [Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})| Medium | O(n)| O(1)|❤️|
-|306. Additive Number | [Go]({{< relref "/ChapterFour/0306.Additive-Number.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
-|401. Binary Watch | [Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})| Easy | O(1)| O(1)||
-|526. Beautiful Arrangement | [Go]({{< relref "/ChapterFour/0526.Beautiful-Arrangement.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|784. Letter Case Permutation | [Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})| Easy | O(n)| O(n)||
-|842. Split Array into Fibonacci Sequence | [Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|980. Unique Paths III | [Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})| Hard | O(n log n)| O(n)||
-|996. Number of Squareful Arrays | [Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})| Hard | O(n log n)| O(n) ||
-|1079. Letter Tile Possibilities | [Go]({{< relref "/ChapterFour/1079.Letter-Tile-Possibilities.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0017|Letter Combinations of a Phone Number|[Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})|Medium| O(log n)| O(1)||48.7%|
+|0022|Generate Parentheses|[Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})|Medium| O(log n)| O(1)||64.8%|
+|0037|Sudoku Solver|[Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})|Hard| O(n^2)| O(n^2)|❤️|46.0%|
+|0039|Combination Sum|[Go]({{< relref "/ChapterFour/0039.Combination-Sum.md" >}})|Medium| O(n log n)| O(n)||58.8%|
+|0040|Combination Sum II|[Go]({{< relref "/ChapterFour/0040.Combination-Sum-II.md" >}})|Medium| O(n log n)| O(n)||49.8%|
+|0046|Permutations|[Go]({{< relref "/ChapterFour/0046.Permutations.md" >}})|Medium| O(n)| O(n)|❤️|66.1%|
+|0047|Permutations II|[Go]({{< relref "/ChapterFour/0047.Permutations-II.md" >}})|Medium| O(n^2)| O(n)|❤️|49.0%|
+|0051|N-Queens|[Go]({{< relref "/ChapterFour/0051.N-Queens.md" >}})|Hard| O(n^2)| O(n)|❤️|49.1%|
+|0052|N-Queens II|[Go]({{< relref "/ChapterFour/0052.N-Queens-II.md" >}})|Hard| O(n^2)| O(n)|❤️|59.7%|
+|0060|Permutation Sequence|[Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})|Hard| O(n log n)| O(1)||39.2%|
+|0077|Combinations|[Go]({{< relref "/ChapterFour/0077.Combinations.md" >}})|Medium| O(n)| O(n)|❤️|56.9%|
+|0078|Subsets|[Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})|Medium| O(n^2)| O(n)|❤️|64.5%|
+|0079|Word Search|[Go]({{< relref "/ChapterFour/0079.Word-Search.md" >}})|Medium| O(n^2)| O(n^2)|❤️|36.6%|
+|0089|Gray Code|[Go]({{< relref "/ChapterFour/0089.Gray-Code.md" >}})|Medium| O(n)| O(1)||50.1%|
+|0090|Subsets II|[Go]({{< relref "/ChapterFour/0090.Subsets-II.md" >}})|Medium| O(n^2)| O(n)|❤️|48.5%|
+|0093|Restore IP Addresses|[Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})|Medium| O(n)| O(n)|❤️|37.2%|
+|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.4%|
+|0131|Palindrome Partitioning|[Go]({{< relref "/ChapterFour/0131.Palindrome-Partitioning.md" >}})|Medium| O(n)| O(n^2)|❤️|51.4%|
+|0211|Design Add and Search Words Data Structure|[Go]({{< relref "/ChapterFour/0211.Design-Add-and-Search-Words-Data-Structure.md" >}})|Medium| O(n)| O(n)|❤️|39.8%|
+|0212|Word Search II|[Go]({{< relref "/ChapterFour/0212.Word-Search-II.md" >}})|Hard| O(n^2)| O(n^2)|❤️|36.6%|
+|0216|Combination Sum III|[Go]({{< relref "/ChapterFour/0216.Combination-Sum-III.md" >}})|Medium| O(n)| O(1)|❤️|59.9%|
+|0306|Additive Number|[Go]({{< relref "/ChapterFour/0306.Additive-Number.md" >}})|Medium| O(n^2)| O(1)|❤️|29.6%|
+|0357|Count Numbers with Unique Digits|[Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})|Medium| O(1)| O(1)||48.8%|
+|0401|Binary Watch|[Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})|Easy| O(1)| O(1)||48.3%|
+|0526|Beautiful Arrangement|[Go]({{< relref "/ChapterFour/0526.Beautiful-Arrangement.md" >}})|Medium| O(n^2)| O(1)|❤️|61.7%|
+|0784|Letter Case Permutation|[Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})|Medium| O(n)| O(n)||66.2%|
+|0842|Split Array into Fibonacci Sequence|[Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})|Medium| O(n^2)| O(1)|❤️|36.7%|
+|0980|Unique Paths III|[Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})|Hard| O(n log n)| O(n)||77.2%|
+|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})|Hard| O(n log n)| O(n) ||48.0%|
+|1079|Letter Tile Possibilities|[Go]({{< relref "/ChapterFour/1079.Letter-Tile-Possibilities.md" >}})|Medium| O(n^2)| O(1)|❤️|75.8%|
+|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||77.6%|
+|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.5%|
+|1659|Maximize Grid Happiness|[Go]({{< relref "/ChapterFour/1659.Maximize-Grid-Happiness.md" >}})|Hard||||35.1%|
+|1681|Minimum Incompatibility|[Go]({{< relref "/ChapterFour/1681.Minimum-Incompatibility.md" >}})|Hard||||35.0%|
+|1688|Count of Matches in Tournament|[Go]({{< relref "/ChapterFour/1688.Count-of-Matches-in-Tournament.md" >}})|Easy||||83.1%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Binary_Indexed_Tree.md b/website/content/ChapterTwo/Binary_Indexed_Tree.md
index 7fbc2dfc..cd0507ba 100644
--- a/website/content/ChapterTwo/Binary_Indexed_Tree.md
+++ b/website/content/ChapterTwo/Binary_Indexed_Tree.md
@@ -6,3 +6,20 @@ type: docs
# Binary Indexed Tree

+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0218|The Skyline Problem|[Go]({{< relref "/ChapterFour/0218.The-Skyline-Problem.md" >}})|Hard||||36.1%|
+|0307|Range Sum Query - Mutable|[Go]({{< relref "/ChapterFour/0307.Range-Sum-Query---Mutable.md" >}})|Medium||||36.5%|
+|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard||||42.6%|
+|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0327.Count-of-Range-Sum.md" >}})|Hard||||35.9%|
+|0493|Reverse Pairs|[Go]({{< relref "/ChapterFour/0493.Reverse-Pairs.md" >}})|Hard||||26.6%|
+|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||36.1%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Binary_Search.md b/website/content/ChapterTwo/Binary_Search.md
index 2c71c30d..d58a4f4d 100644
--- a/website/content/ChapterTwo/Binary_Search.md
+++ b/website/content/ChapterTwo/Binary_Search.md
@@ -127,19 +127,80 @@ func peakIndexInMountainArray(A []int) int {
- max-min 最大值最小化问题。求在最小满足条件的情况下的最大值。第 410 题,第 875 题,第 1011 题,第 1283 题。
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|50. Pow(x, n) | [Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})| Medium | O(log n)| O(1)||
-|69. Sqrt(x) | [Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})| Easy | O(log n)| O(1)||
-|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
-|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
-|222. Count Complete Tree Nodes | [Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})| Medium | O(n)| O(1)||
-|230. Kth Smallest Element in a BST | [Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})| Medium | O(n)| O(1)||
-|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
-|300. Longest Increasing Subsequence | [Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})| Medium | O(n log n)| O(n)||
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|392. Is Subsequence | [Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})| Medium | O(n)| O(1)||
-|454. 4Sum II | [Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})| Medium | O(n^2)| O(n) ||
-|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
-|-----------------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0004|Median of Two Sorted Arrays|[Go]({{< relref "/ChapterFour/0004.Median-of-Two-Sorted-Arrays.md" >}})|Hard||||30.8%|
+|0029|Divide Two Integers|[Go]({{< relref "/ChapterFour/0029.Divide-Two-Integers.md" >}})|Medium||||16.6%|
+|0033|Search in Rotated Sorted Array|[Go]({{< relref "/ChapterFour/0033.Search-in-Rotated-Sorted-Array.md" >}})|Medium||||35.7%|
+|0034|Find First and Last Position of Element in Sorted Array|[Go]({{< relref "/ChapterFour/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array.md" >}})|Medium||||37.1%|
+|0035|Search Insert Position|[Go]({{< relref "/ChapterFour/0035.Search-Insert-Position.md" >}})|Easy||||42.8%|
+|0050|Pow(x, n)|[Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})|Medium| O(log n)| O(1)||30.8%|
+|0069|Sqrt(x)|[Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})|Easy| O(log n)| O(1)||34.8%|
+|0074|Search a 2D Matrix|[Go]({{< relref "/ChapterFour/0074.Search-a-2D-Matrix.md" >}})|Medium||||37.4%|
+|0081|Search in Rotated Sorted Array II|[Go]({{< relref "/ChapterFour/0081.Search-in-Rotated-Sorted-Array-II.md" >}})|Medium||||33.5%|
+|0153|Find Minimum in Rotated Sorted Array|[Go]({{< relref "/ChapterFour/0153.Find-Minimum-in-Rotated-Sorted-Array.md" >}})|Medium||||45.9%|
+|0154|Find Minimum in Rotated Sorted Array II|[Go]({{< relref "/ChapterFour/0154.Find-Minimum-in-Rotated-Sorted-Array-II.md" >}})|Hard||||41.9%|
+|0162|Find Peak Element|[Go]({{< relref "/ChapterFour/0162.Find-Peak-Element.md" >}})|Medium||||43.8%|
+|0167|Two Sum II - Input array is sorted|[Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})|Easy| O(n)| O(1)||55.4%|
+|0174|Dungeon Game|[Go]({{< relref "/ChapterFour/0174.Dungeon-Game.md" >}})|Hard||||33.2%|
+|0209|Minimum Size Subarray Sum|[Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})|Medium| O(n)| O(1)||39.2%|
+|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||48.8%|
+|0230|Kth Smallest Element in a BST|[Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})|Medium| O(n)| O(1)||62.2%|
+|0240|Search a 2D Matrix II|[Go]({{< relref "/ChapterFour/0240.Search-a-2D-Matrix-II.md" >}})|Medium||||44.2%|
+|0275|H-Index II|[Go]({{< relref "/ChapterFour/0275.H-Index-II.md" >}})|Medium||||36.2%|
+|0287|Find the Duplicate Number|[Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})|Medium| O(n)| O(1)|❤️|57.2%|
+|0300|Longest Increasing Subsequence|[Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})|Medium| O(n log n)| O(n)||43.7%|
+|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard||||42.6%|
+|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0327.Count-of-Range-Sum.md" >}})|Hard||||35.9%|
+|0349|Intersection of Two Arrays|[Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})|Easy| O(n)| O(n) ||64.4%|
+|0350|Intersection of Two Arrays II|[Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})|Easy| O(n)| O(n) ||51.9%|
+|0354|Russian Doll Envelopes|[Go]({{< relref "/ChapterFour/0354.Russian-Doll-Envelopes.md" >}})|Hard||||36.1%|
+|0367|Valid Perfect Square|[Go]({{< relref "/ChapterFour/0367.Valid-Perfect-Square.md" >}})|Easy||||42.0%|
+|0378|Kth Smallest Element in a Sorted Matrix|[Go]({{< relref "/ChapterFour/0378.Kth-Smallest-Element-in-a-Sorted-Matrix.md" >}})|Medium||||55.9%|
+|0392|Is Subsequence|[Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})|Easy| O(n)| O(1)||49.5%|
+|0410|Split Array Largest Sum|[Go]({{< relref "/ChapterFour/0410.Split-Array-Largest-Sum.md" >}})|Hard||||46.1%|
+|0436|Find Right Interval|[Go]({{< relref "/ChapterFour/0436.Find-Right-Interval.md" >}})|Medium||||48.4%|
+|0441|Arranging Coins|[Go]({{< relref "/ChapterFour/0441.Arranging-Coins.md" >}})|Easy||||42.3%|
+|0454|4Sum II|[Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})|Medium| O(n^2)| O(n) ||54.5%|
+|0475|Heaters|[Go]({{< relref "/ChapterFour/0475.Heaters.md" >}})|Medium||||33.5%|
+|0483|Smallest Good Base|[Go]({{< relref "/ChapterFour/0483.Smallest-Good-Base.md" >}})|Hard||||36.2%|
+|0493|Reverse Pairs|[Go]({{< relref "/ChapterFour/0493.Reverse-Pairs.md" >}})|Hard||||26.6%|
+|0497|Random Point in Non-overlapping Rectangles|[Go]({{< relref "/ChapterFour/0497.Random-Point-in-Non-overlapping-Rectangles.md" >}})|Medium||||39.1%|
+|0528|Random Pick with Weight|[Go]({{< relref "/ChapterFour/0528.Random-Pick-with-Weight.md" >}})|Medium||||44.5%|
+|0658|Find K Closest Elements|[Go]({{< relref "/ChapterFour/0658.Find-K-Closest-Elements.md" >}})|Medium||||41.8%|
+|0668|Kth Smallest Number in Multiplication Table|[Go]({{< relref "/ChapterFour/0668.Kth-Smallest-Number-in-Multiplication-Table.md" >}})|Hard||||47.7%|
+|0704|Binary Search|[Go]({{< relref "/ChapterFour/0704.Binary-Search.md" >}})|Easy||||54.0%|
+|0710|Random Pick with Blacklist|[Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})|Hard| O(n)| O(n) ||32.7%|
+|0718|Maximum Length of Repeated Subarray|[Go]({{< relref "/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md" >}})|Medium||||50.1%|
+|0719|Find K-th Smallest Pair Distance|[Go]({{< relref "/ChapterFour/0719.Find-K-th-Smallest-Pair-Distance.md" >}})|Hard||||32.4%|
+|0744|Find Smallest Letter Greater Than Target|[Go]({{< relref "/ChapterFour/0744.Find-Smallest-Letter-Greater-Than-Target.md" >}})|Easy||||45.6%|
+|0778|Swim in Rising Water|[Go]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})|Hard||||54.4%|
+|0786|K-th Smallest Prime Fraction|[Go]({{< relref "/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md" >}})|Hard||||41.8%|
+|0793|Preimage Size of Factorial Zeroes Function|[Go]({{< relref "/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md" >}})|Hard||||40.6%|
+|0852|Peak Index in a Mountain Array|[Go]({{< relref "/ChapterFour/0852.Peak-Index-in-a-Mountain-Array.md" >}})|Easy||||71.8%|
+|0862|Shortest Subarray with Sum at Least K|[Go]({{< relref "/ChapterFour/0862.Shortest-Subarray-with-Sum-at-Least-K.md" >}})|Hard||||25.1%|
+|0875|Koko Eating Bananas|[Go]({{< relref "/ChapterFour/0875.Koko-Eating-Bananas.md" >}})|Medium||||53.4%|
+|0878|Nth Magical Number|[Go]({{< relref "/ChapterFour/0878.Nth-Magical-Number.md" >}})|Hard||||28.9%|
+|0887|Super Egg Drop|[Go]({{< relref "/ChapterFour/0887.Super-Egg-Drop.md" >}})|Hard||||27.0%|
+|0911|Online Election|[Go]({{< relref "/ChapterFour/0911.Online-Election.md" >}})|Medium||||51.2%|
+|0927|Three Equal Parts|[Go]({{< relref "/ChapterFour/0927.Three-Equal-Parts.md" >}})|Hard||||34.5%|
+|0981|Time Based Key-Value Store|[Go]({{< relref "/ChapterFour/0981.Time-Based-Key-Value-Store.md" >}})|Medium||||54.0%|
+|1011|Capacity To Ship Packages Within D Days|[Go]({{< relref "/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md" >}})|Medium||||59.5%|
+|1111|Maximum Nesting Depth of Two Valid Parentheses Strings|[Go]({{< relref "/ChapterFour/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings.md" >}})|Medium||||72.4%|
+|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard||||39.5%|
+|1201|Ugly Number III|[Go]({{< relref "/ChapterFour/1201.Ugly-Number-III.md" >}})|Medium||||26.3%|
+|1235|Maximum Profit in Job Scheduling|[Go]({{< relref "/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md" >}})|Hard||||46.9%|
+|1283|Find the Smallest Divisor Given a Threshold|[Go]({{< relref "/ChapterFour/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md" >}})|Medium||||49.2%|
+|1300|Sum of Mutated Array Closest to Target|[Go]({{< relref "/ChapterFour/1300.Sum-of-Mutated-Array-Closest-to-Target.md" >}})|Medium||||43.3%|
+|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||36.1%|
+|1658|Minimum Operations to Reduce X to Zero|[Go]({{< relref "/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md" >}})|Medium||||33.4%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Bit_Manipulation.md b/website/content/ChapterTwo/Bit_Manipulation.md
index 4dbc8705..029fa3fd 100644
--- a/website/content/ChapterTwo/Bit_Manipulation.md
+++ b/website/content/ChapterTwo/Bit_Manipulation.md
@@ -40,35 +40,44 @@ X & ~X = 0
```
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|78. Subsets | [Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|136. Single Number | [Go]({{< relref "/ChapterFour/0136.Single-Number.md" >}})| Easy | O(n)| O(1)||
-|137. Single Number II | [Go]({{< relref "/ChapterFour/0137.Single-Number-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|169. Majority Element | [Go]({{< relref "/ChapterFour/0169.Majority-Element.md" >}})| Easy | O(n)| O(1)|❤️|
-|187. Repeated DNA Sequences | [Go]({{< relref "/ChapterFour/0187.Repeated-DNA-Sequences.md" >}})| Medium | O(n)| O(1)||
-|190. Reverse Bits | [Go]({{< relref "/ChapterFour/0190.Reverse-Bits.md" >}})| Easy | O(n)| O(1)|❤️|
-|191. Number of 1 Bits | [Go]({{< relref "/ChapterFour/0191.Number-of-1-Bits.md" >}})| Easy | O(n)| O(1)||
-|201. Bitwise AND of Numbers Range | [Go]({{< relref "/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md" >}})| Medium | O(n)| O(1)|❤️|
-|231. Power of Two | [Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})| Easy | O(1)| O(1)||
-|260. Single Number III | [Go]({{< relref "/ChapterFour/0260.Single-Number-III.md" >}})| Medium | O(n)| O(1)|❤️|
-|268. Missing Number | [Go]({{< relref "/ChapterFour/0268.Missing-Number.md" >}})| Easy | O(n)| O(1)||
-|318. Maximum Product of Word Lengths | [Go]({{< relref "/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md" >}})| Medium | O(n)| O(1)||
-|338. Counting Bits | [Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})| Medium | O(n)| O(n)||
-|342. Power of Four | [Go]({{< relref "/ChapterFour/0342.Power-of-Four.md" >}})| Easy | O(n)| O(1)||
-|371. Sum of Two Integers | [Go]({{< relref "/ChapterFour/0371.Sum-of-Two-Integers.md" >}})| Easy | O(n)| O(1)||
-|389. Find the Difference | [Go]({{< relref "/ChapterFour/0389.Find-the-Difference.md" >}})| Easy | O(n)| O(1)||
-|393. UTF-8 Validation | [Go]({{< relref "/ChapterFour/0393.UTF-8-Validation.md" >}})| Medium | O(n)| O(1)||
-|397. Integer Replacement | [Go]({{< relref "/ChapterFour/0397.Integer-Replacement.md" >}})| Medium | O(n)| O(1)||
-|401. Binary Watch | [Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})| Easy | O(1)| O(1)||
-|405. Convert a Number to Hexadecimal | [Go]({{< relref "/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md" >}})| Easy | O(n)| O(1)||
-|421. Maximum XOR of Two Numbers in an Array | [Go]({{< relref "/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md" >}})| Medium | O(n)| O(1)|❤️|
-|461. Hamming Distance | [Go]({{< relref "/ChapterFour/0461.Hamming-Distance.md" >}})| Easy | O(n)| O(1)||
-|476. Number Complement | [Go]({{< relref "/ChapterFour/0476.Number-Complement.md" >}})| Easy | O(n)| O(1)||
-|477. Total Hamming Distance | [Go]({{< relref "/ChapterFour/0477.Total-Hamming-Distance.md" >}})| Medium | O(n)| O(1)||
-|693. Binary Number with Alternating Bits | [Go]({{< relref "/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md" >}})| Easy | O(n)| O(1)|❤️|
-|756. Pyramid Transition Matrix | [Go]({{< relref "/ChapterFour/0756.Pyramid-Transition-Matrix.md" >}})| Medium | O(n log n)| O(n)||
-|762. Prime Number of Set Bits in Binary Representation | [Go]({{< relref "/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md" >}})| Easy | O(n)| O(1)||
-|784. Letter Case Permutation | [Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})| Easy | O(n)| O(1)||
-|898. Bitwise ORs of Subarrays | [Go]({{< relref "/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0078|Subsets|[Go]({{< relref "/ChapterFour/0078.Subsets.md" >}})|Medium| O(n^2)| O(n)|❤️|64.5%|
+|0136|Single Number|[Go]({{< relref "/ChapterFour/0136.Single-Number.md" >}})|Easy| O(n)| O(1)||66.4%|
+|0137|Single Number II|[Go]({{< relref "/ChapterFour/0137.Single-Number-II.md" >}})|Medium| O(n)| O(1)|❤️|53.5%|
+|0169|Majority Element|[Go]({{< relref "/ChapterFour/0169.Majority-Element.md" >}})|Easy| O(n)| O(1)|❤️|59.9%|
+|0187|Repeated DNA Sequences|[Go]({{< relref "/ChapterFour/0187.Repeated-DNA-Sequences.md" >}})|Medium| O(n)| O(1)||41.2%|
+|0190|Reverse Bits|[Go]({{< relref "/ChapterFour/0190.Reverse-Bits.md" >}})|Easy| O(n)| O(1)|❤️|41.7%|
+|0191|Number of 1 Bits|[Go]({{< relref "/ChapterFour/0191.Number-of-1-Bits.md" >}})|Easy| O(n)| O(1)||51.9%|
+|0201|Bitwise AND of Numbers Range|[Go]({{< relref "/ChapterFour/0201.Bitwise-AND-of-Numbers-Range.md" >}})|Medium| O(n)| O(1)|❤️|39.6%|
+|0231|Power of Two|[Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})|Easy| O(1)| O(1)||43.8%|
+|0260|Single Number III|[Go]({{< relref "/ChapterFour/0260.Single-Number-III.md" >}})|Medium| O(n)| O(1)|❤️|65.2%|
+|0268|Missing Number|[Go]({{< relref "/ChapterFour/0268.Missing-Number.md" >}})|Easy| O(n)| O(1)||53.4%|
+|0318|Maximum Product of Word Lengths|[Go]({{< relref "/ChapterFour/0318.Maximum-Product-of-Word-Lengths.md" >}})|Medium| O(n)| O(1)||52.1%|
+|0338|Counting Bits|[Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})|Medium| O(n)| O(n)||70.2%|
+|0342|Power of Four|[Go]({{< relref "/ChapterFour/0342.Power-of-Four.md" >}})|Easy| O(n)| O(1)||41.6%|
+|0371|Sum of Two Integers|[Go]({{< relref "/ChapterFour/0371.Sum-of-Two-Integers.md" >}})|Medium| O(n)| O(1)||50.6%|
+|0389|Find the Difference|[Go]({{< relref "/ChapterFour/0389.Find-the-Difference.md" >}})|Easy| O(n)| O(1)||57.7%|
+|0393|UTF-8 Validation|[Go]({{< relref "/ChapterFour/0393.UTF-8-Validation.md" >}})|Medium| O(n)| O(1)||37.9%|
+|0397|Integer Replacement|[Go]({{< relref "/ChapterFour/0397.Integer-Replacement.md" >}})|Medium| O(n)| O(1)||33.4%|
+|0401|Binary Watch|[Go]({{< relref "/ChapterFour/0401.Binary-Watch.md" >}})|Easy| O(1)| O(1)||48.3%|
+|0405|Convert a Number to Hexadecimal|[Go]({{< relref "/ChapterFour/0405.Convert-a-Number-to-Hexadecimal.md" >}})|Easy| O(n)| O(1)||44.4%|
+|0421|Maximum XOR of Two Numbers in an Array|[Go]({{< relref "/ChapterFour/0421.Maximum-XOR-of-Two-Numbers-in-an-Array.md" >}})|Medium| O(n)| O(1)|❤️|53.9%|
+|0461|Hamming Distance|[Go]({{< relref "/ChapterFour/0461.Hamming-Distance.md" >}})|Easy| O(n)| O(1)||73.1%|
+|0476|Number Complement|[Go]({{< relref "/ChapterFour/0476.Number-Complement.md" >}})|Easy| O(n)| O(1)||65.1%|
+|0477|Total Hamming Distance|[Go]({{< relref "/ChapterFour/0477.Total-Hamming-Distance.md" >}})|Medium| O(n)| O(1)||50.6%|
+|0693|Binary Number with Alternating Bits|[Go]({{< relref "/ChapterFour/0693.Binary-Number-with-Alternating-Bits.md" >}})|Easy| O(n)| O(1)|❤️|59.7%|
+|0756|Pyramid Transition Matrix|[Go]({{< relref "/ChapterFour/0756.Pyramid-Transition-Matrix.md" >}})|Medium| O(n log n)| O(n)||55.5%|
+|0762|Prime Number of Set Bits in Binary Representation|[Go]({{< relref "/ChapterFour/0762.Prime-Number-of-Set-Bits-in-Binary-Representation.md" >}})|Easy| O(n)| O(1)||64.2%|
+|0784|Letter Case Permutation|[Go]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})|Medium| O(n)| O(1)||66.2%|
+|0898|Bitwise ORs of Subarrays|[Go]({{< relref "/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md" >}})|Medium| O(n)| O(1)||34.0%|
+|1290|Convert Binary Number in a Linked List to Integer|[Go]({{< relref "/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md" >}})|Easy||||81.7%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Breadth_First_Search.md b/website/content/ChapterTwo/Breadth_First_Search.md
index f5ff7c73..d9585d60 100644
--- a/website/content/ChapterTwo/Breadth_First_Search.md
+++ b/website/content/ChapterTwo/Breadth_First_Search.md
@@ -5,20 +5,38 @@ type: docs
# Breadth First Search
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
-|102. Binary Tree Level Order Traversal | [Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})| Medium | O(n)| O(1)||
-|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
-|107. Binary Tree Level Order Traversal II | [Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})| Easy | O(n)| O(1)||
-|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|127. Word Ladder | [Go]({{< relref "/ChapterFour/0127.Word-Ladder.md" >}})| Medium | O(n)| O(n)||
-|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
-|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(n^2)| O(n^2)||
-|207. Course Schedule | [Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})| Medium | O(n^2)| O(n^2)||
-|210. Course Schedule II | [Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
-|542. 01 Matrix | [Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})| Medium | O(n)| O(1)||
-|993. Cousins in Binary Tree | [Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0101|Symmetric Tree|[Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})|Easy| O(n)| O(1)||47.9%|
+|0102|Binary Tree Level Order Traversal|[Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})|Medium| O(n)| O(1)||56.2%|
+|0103|Binary Tree Zigzag Level Order Traversal|[Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})|Medium| O(n)| O(n)||49.8%|
+|0107|Binary Tree Level Order Traversal II|[Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})|Easy| O(n)| O(1)||54.9%|
+|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.2%|
+|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.4%|
+|0127|Word Ladder|[Go]({{< relref "/ChapterFour/0127.Word-Ladder.md" >}})|Hard| O(n)| O(n)||31.5%|
+|0130|Surrounded Regions|[Go]({{< relref "/ChapterFour/0130.Surrounded-Regions.md" >}})|Medium||||29.2%|
+|0199|Binary Tree Right Side View|[Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})|Medium| O(n)| O(1)||55.7%|
+|0200|Number of Islands|[Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})|Medium| O(n^2)| O(n^2)||48.6%|
+|0207|Course Schedule|[Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})|Medium| O(n^2)| O(n^2)||44.2%|
+|0210|Course Schedule II|[Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})|Medium| O(n^2)| O(n^2)||42.3%|
+|0513|Find Bottom Left Tree Value|[Go]({{< relref "/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md" >}})|Medium||||62.3%|
+|0515|Find Largest Value in Each Tree Row|[Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})|Medium| O(n)| O(n)||62.0%|
+|0529|Minesweeper|[Go]({{< relref "/ChapterFour/0529.Minesweeper.md" >}})|Medium||||60.7%|
+|0542|01 Matrix|[Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})|Medium| O(n)| O(1)||40.6%|
+|0785|Is Graph Bipartite?|[Go]({{< relref "/ChapterFour/0785.Is-Graph-Bipartite.md" >}})|Medium||||48.2%|
+|0815|Bus Routes|[Go]({{< relref "/ChapterFour/0815.Bus-Routes.md" >}})|Hard||||43.2%|
+|0863|All Nodes Distance K in Binary Tree|[Go]({{< relref "/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md" >}})|Medium||||57.5%|
+|0864|Shortest Path to Get All Keys|[Go]({{< relref "/ChapterFour/0864.Shortest-Path-to-Get-All-Keys.md" >}})|Hard||||41.5%|
+|0993|Cousins in Binary Tree|[Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})|Easy| O(n)| O(1)||52.2%|
+|1306|Jump Game III|[Go]({{< relref "/ChapterFour/1306.Jump-Game-III.md" >}})|Medium||||62.6%|
+|1654|Minimum Jumps to Reach Home|[Go]({{< relref "/ChapterFour/1654.Minimum-Jumps-to-Reach-Home.md" >}})|Medium||||26.2%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Depth_First_Search.md b/website/content/ChapterTwo/Depth_First_Search.md
index 41d8ac37..87126deb 100644
--- a/website/content/ChapterTwo/Depth_First_Search.md
+++ b/website/content/ChapterTwo/Depth_First_Search.md
@@ -5,29 +5,85 @@ type: docs
# Depth First Search
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|98. Validate Binary Search Tree | [Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})| Medium | O(n)| O(1)||
-|99. Recover Binary Search Tree | [Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})| Hard | O(n)| O(1)||
-|100. Same Tree | [Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})| Easy | O(n)| O(1)||
-|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
-|104. Maximum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|108. Convert Sorted Array to Binary Search Tree | [Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
-|109. Convert Sorted List to Binary Search Tree | [Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})| Medium | O(log n)| O(n)||
-|110. Balanced Binary Tree | [Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|112. Path Sum | [Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})| Easy | O(n)| O(1)||
-|113. Path Sum II | [Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})| Medium | O(n)| O(1)||
-|114. Flatten Binary Tree to Linked List | [Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|124. Binary Tree Maximum Path Sum | [Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})| Hard | O(n)| O(1)||
-|129. Sum Root to Leaf Numbers | [Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})| Medium | O(n)| O(1)||
-|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
-|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(n^2)| O(n^2)||
-|207. Course Schedule | [Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})| Medium | O(n^2)| O(n^2)||
-|210. Course Schedule II | [Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|257. Binary Tree Paths | [Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})| Easy | O(n)| O(1)||
-|394. Decode String | [Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})| Medium | O(n)| O(n)||
-|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
-|542. 01 Matrix | [Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})| Medium | O(n)| O(1)||
-|980. Unique Paths III | [Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})| Hard | O(n log n)| O(n)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0017|Letter Combinations of a Phone Number|[Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})|Medium||||48.7%|
+|0098|Validate Binary Search Tree|[Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})|Medium| O(n)| O(1)||28.6%|
+|0099|Recover Binary Search Tree|[Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})|Hard| O(n)| O(1)||42.2%|
+|0100|Same Tree|[Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})|Easy| O(n)| O(1)||54.0%|
+|0101|Symmetric Tree|[Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})|Easy| O(n)| O(1)||47.9%|
+|0104|Maximum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||67.7%|
+|0105|Construct Binary Tree from Preorder and Inorder Traversal|[Go]({{< relref "/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md" >}})|Medium||||51.3%|
+|0106|Construct Binary Tree from Inorder and Postorder Traversal|[Go]({{< relref "/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md" >}})|Medium||||49.2%|
+|0108|Convert Sorted Array to Binary Search Tree|[Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||60.0%|
+|0109|Convert Sorted List to Binary Search Tree|[Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})|Medium| O(log n)| O(n)||49.8%|
+|0110|Balanced Binary Tree|[Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})|Easy| O(n)| O(1)||44.6%|
+|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.2%|
+|0112|Path Sum|[Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})|Easy| O(n)| O(1)||42.1%|
+|0113|Path Sum II|[Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})|Medium| O(n)| O(1)||48.7%|
+|0114|Flatten Binary Tree to Linked List|[Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})|Medium| O(n)| O(1)||51.5%|
+|0124|Binary Tree Maximum Path Sum|[Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})|Hard| O(n)| O(1)||35.3%|
+|0129|Sum Root to Leaf Numbers|[Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})|Medium| O(n)| O(1)||50.6%|
+|0130|Surrounded Regions|[Go]({{< relref "/ChapterFour/0130.Surrounded-Regions.md" >}})|Medium||||29.2%|
+|0131|Palindrome Partitioning|[Go]({{< relref "/ChapterFour/0131.Palindrome-Partitioning.md" >}})|Medium||||51.4%|
+|0199|Binary Tree Right Side View|[Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})|Medium| O(n)| O(1)||55.7%|
+|0200|Number of Islands|[Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})|Medium| O(n^2)| O(n^2)||48.6%|
+|0207|Course Schedule|[Go]({{< relref "/ChapterFour/0207.Course-Schedule.md" >}})|Medium| O(n^2)| O(n^2)||44.2%|
+|0210|Course Schedule II|[Go]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})|Medium| O(n^2)| O(n^2)||42.3%|
+|0211|Design Add and Search Words Data Structure|[Go]({{< relref "/ChapterFour/0211.Design-Add-and-Search-Words-Data-Structure.md" >}})|Medium||||39.8%|
+|0257|Binary Tree Paths|[Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})|Easy| O(n)| O(1)||53.2%|
+|0329|Longest Increasing Path in a Matrix|[Go]({{< relref "/ChapterFour/0329.Longest-Increasing-Path-in-a-Matrix.md" >}})|Hard||||44.5%|
+|0337|House Robber III|[Go]({{< relref "/ChapterFour/0337.House-Robber-III.md" >}})|Medium||||51.7%|
+|0394|Decode String|[Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})|Medium| O(n)| O(n)||52.4%|
+|0491|Increasing Subsequences|[Go]({{< relref "/ChapterFour/0491.Increasing-Subsequences.md" >}})|Medium||||47.3%|
+|0494|Target Sum|[Go]({{< relref "/ChapterFour/0494.Target-Sum.md" >}})|Medium||||45.8%|
+|0513|Find Bottom Left Tree Value|[Go]({{< relref "/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md" >}})|Medium||||62.3%|
+|0515|Find Largest Value in Each Tree Row|[Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})|Medium| O(n)| O(n)||62.0%|
+|0526|Beautiful Arrangement|[Go]({{< relref "/ChapterFour/0526.Beautiful-Arrangement.md" >}})|Medium||||61.7%|
+|0529|Minesweeper|[Go]({{< relref "/ChapterFour/0529.Minesweeper.md" >}})|Medium||||60.7%|
+|0542|01 Matrix|[Go]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})|Medium| O(n)| O(1)||40.6%|
+|0547|Number of Provinces|[Go]({{< relref "/ChapterFour/0547.Number-of-Provinces.md" >}})|Medium||||60.1%|
+|0563|Binary Tree Tilt|[Go]({{< relref "/ChapterFour/0563.Binary-Tree-Tilt.md" >}})|Easy||||52.7%|
+|0638|Shopping Offers|[Go]({{< relref "/ChapterFour/0638.Shopping-Offers.md" >}})|Medium||||52.6%|
+|0685|Redundant Connection II|[Go]({{< relref "/ChapterFour/0685.Redundant-Connection-II.md" >}})|Hard||||32.9%|
+|0695|Max Area of Island|[Go]({{< relref "/ChapterFour/0695.Max-Area-of-Island.md" >}})|Medium||||64.4%|
+|0721|Accounts Merge|[Go]({{< relref "/ChapterFour/0721.Accounts-Merge.md" >}})|Medium||||51.2%|
+|0733|Flood Fill|[Go]({{< relref "/ChapterFour/0733.Flood-Fill.md" >}})|Easy||||55.8%|
+|0753|Cracking the Safe|[Go]({{< relref "/ChapterFour/0753.Cracking-the-Safe.md" >}})|Hard||||52.0%|
+|0756|Pyramid Transition Matrix|[Go]({{< relref "/ChapterFour/0756.Pyramid-Transition-Matrix.md" >}})|Medium||||55.5%|
+|0778|Swim in Rising Water|[Go]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})|Hard||||54.4%|
+|0785|Is Graph Bipartite?|[Go]({{< relref "/ChapterFour/0785.Is-Graph-Bipartite.md" >}})|Medium||||48.2%|
+|0802|Find Eventual Safe States|[Go]({{< relref "/ChapterFour/0802.Find-Eventual-Safe-States.md" >}})|Medium||||49.7%|
+|0834|Sum of Distances in Tree|[Go]({{< relref "/ChapterFour/0834.Sum-of-Distances-in-Tree.md" >}})|Hard||||45.5%|
+|0839|Similar String Groups|[Go]({{< relref "/ChapterFour/0839.Similar-String-Groups.md" >}})|Hard||||40.1%|
+|0841|Keys and Rooms|[Go]({{< relref "/ChapterFour/0841.Keys-and-Rooms.md" >}})|Medium||||65.2%|
+|0851|Loud and Rich|[Go]({{< relref "/ChapterFour/0851.Loud-and-Rich.md" >}})|Medium||||52.4%|
+|0863|All Nodes Distance K in Binary Tree|[Go]({{< relref "/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md" >}})|Medium||||57.5%|
+|0872|Leaf-Similar Trees|[Go]({{< relref "/ChapterFour/0872.Leaf-Similar-Trees.md" >}})|Easy||||64.5%|
+|0897|Increasing Order Search Tree|[Go]({{< relref "/ChapterFour/0897.Increasing-Order-Search-Tree.md" >}})|Easy||||74.3%|
+|0924|Minimize Malware Spread|[Go]({{< relref "/ChapterFour/0924.Minimize-Malware-Spread.md" >}})|Hard||||41.8%|
+|0928|Minimize Malware Spread II|[Go]({{< relref "/ChapterFour/0928.Minimize-Malware-Spread-II.md" >}})|Hard||||41.2%|
+|0947|Most Stones Removed with Same Row or Column|[Go]({{< relref "/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md" >}})|Medium||||55.4%|
+|0959|Regions Cut By Slashes|[Go]({{< relref "/ChapterFour/0959.Regions-Cut-By-Slashes.md" >}})|Medium||||66.9%|
+|0968|Binary Tree Cameras|[Go]({{< relref "/ChapterFour/0968.Binary-Tree-Cameras.md" >}})|Hard||||38.5%|
+|0979|Distribute Coins in Binary Tree|[Go]({{< relref "/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md" >}})|Medium||||69.5%|
+|0980|Unique Paths III|[Go]({{< relref "/ChapterFour/0980.Unique-Paths-III.md" >}})|Hard| O(n log n)| O(n)||77.2%|
+|1020|Number of Enclaves|[Go]({{< relref "/ChapterFour/1020.Number-of-Enclaves.md" >}})|Medium||||58.7%|
+|1026|Maximum Difference Between Node and Ancestor|[Go]({{< relref "/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md" >}})|Medium||||69.2%|
+|1028|Recover a Tree From Preorder Traversal|[Go]({{< relref "/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md" >}})|Hard||||70.7%|
+|1110|Delete Nodes And Return Forest|[Go]({{< relref "/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md" >}})|Medium||||67.6%|
+|1123|Lowest Common Ancestor of Deepest Leaves|[Go]({{< relref "/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md" >}})|Medium||||67.9%|
+|1145|Binary Tree Coloring Game|[Go]({{< relref "/ChapterFour/1145.Binary-Tree-Coloring-Game.md" >}})|Medium||||51.4%|
+|1203|Sort Items by Groups Respecting Dependencies|[Go]({{< relref "/ChapterFour/1203.Sort-Items-by-Groups-Respecting-Dependencies.md" >}})|Hard||||49.1%|
+|1254|Number of Closed Islands|[Go]({{< relref "/ChapterFour/1254.Number-of-Closed-Islands.md" >}})|Medium||||61.5%|
+|1302|Deepest Leaves Sum|[Go]({{< relref "/ChapterFour/1302.Deepest-Leaves-Sum.md" >}})|Medium||||84.1%|
+|1306|Jump Game III|[Go]({{< relref "/ChapterFour/1306.Jump-Game-III.md" >}})|Medium||||62.6%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Dynamic_Programming.md b/website/content/ChapterTwo/Dynamic_Programming.md
index 2baddaa9..b45aa912 100644
--- a/website/content/ChapterTwo/Dynamic_Programming.md
+++ b/website/content/ChapterTwo/Dynamic_Programming.md
@@ -5,32 +5,65 @@ type: docs
# Dynamic Programming
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|53. Maximum Subarray| [Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})| Easy | O(n)| O(n)||
-|62. Unique Paths | [Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})| Medium | O(n^2)| O(n^2)||
-|63. Unique Paths II | [Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})| Medium | O(n^2)| O(n^2)||
-|64. Minimum Path Sum | [Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})| Medium | O(n^2)| O(n^2)||
-|70. Climbing Stairs | [Go]({{< relref "/ChapterFour/0070.Climbing-Stairs.md" >}})| Easy | O(n)| O(n)||
-|91. Decode Ways | [Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})| Medium | O(n)| O(n)||
-|96. Unique Binary Search Trees | [Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})| Medium | O(n)| O(n)||
-|120. Triangle | [Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})| Medium | O(n^2)| O(n)||
-|121. Best Time to Buy and Sell Stock | [Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})| Easy | O(n)| O(1)||
-|152. Maximum Product Subarray | [Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})| Medium | O(n)| O(1)||
-|198. House Robber | [Go]({{< relref "/ChapterFour/0198.House-Robber.md" >}})| Easy | O(n)| O(n)||
-|213. House Robber II | [Go]({{< relref "/ChapterFour/0213.House-Robber-II.md" >}})| Medium | O(n)| O(n)||
-|300. Longest Increasing Subsequence | [Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})| Medium | O(n log n)| O(n)||
-|309. Best Time to Buy and Sell Stock with Cooldown | [Go]({{< relref "/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md" >}})| Medium | O(n)| O(n)||
-|322. Coin Change | [Go]({{< relref "/ChapterFour/0322.Coin-Change.md" >}})| Medium | O(n)| O(n)||
-|338. Counting Bits | [Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})| Medium | O(n)| O(n)||
-|343. Integer Break | [Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})| Medium | O(n^2)| O(n)||
-|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
-|392. Is Subsequence | [Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})| Medium | O(n)| O(1)||
-|416. Partition Equal Subset Sum | [Go]({{< relref "/ChapterFour/0416.Partition-Equal-Subset-Sum.md" >}})| Medium | O(n^2)| O(n)||
-|714. Best Time to Buy and Sell Stock with Transaction Fee | [Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})| Medium | O(n)| O(1)||
-|746. Min Cost Climbing Stairs | [Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})| Easy | O(n)| O(1)||
-|838. Push Dominoes | [Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})| Medium | O(n)| O(n)||
-|1025. Divisor Game | [Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})| Easy | O(1)| O(1)||
-|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
-|942. DI String Match | [Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})|Hard||||50.8%|
+|0053|Maximum Subarray|[Go]({{< relref "/ChapterFour/0053.Maximum-Subarray.md" >}})|Easy| O(n)| O(n)||47.5%|
+|0062|Unique Paths|[Go]({{< relref "/ChapterFour/0062.Unique-Paths.md" >}})|Medium| O(n^2)| O(n^2)||55.6%|
+|0063|Unique Paths II|[Go]({{< relref "/ChapterFour/0063.Unique-Paths-II.md" >}})|Medium| O(n^2)| O(n^2)||35.1%|
+|0064|Minimum Path Sum|[Go]({{< relref "/ChapterFour/0064.Minimum-Path-Sum.md" >}})|Medium| O(n^2)| O(n^2)||55.9%|
+|0070|Climbing Stairs|[Go]({{< relref "/ChapterFour/0070.Climbing-Stairs.md" >}})|Easy| O(n)| O(n)||48.5%|
+|0091|Decode Ways|[Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})|Medium| O(n)| O(n)||26.2%|
+|0095|Unique Binary Search Trees II|[Go]({{< relref "/ChapterFour/0095.Unique-Binary-Search-Trees-II.md" >}})|Medium||||42.1%|
+|0096|Unique Binary Search Trees|[Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})|Medium| O(n)| O(n)||54.2%|
+|0120|Triangle|[Go]({{< relref "/ChapterFour/0120.Triangle.md" >}})|Medium| O(n^2)| O(n)||45.5%|
+|0121|Best Time to Buy and Sell Stock|[Go]({{< relref "/ChapterFour/0121.Best-Time-to-Buy-and-Sell-Stock.md" >}})|Easy| O(n)| O(1)||51.3%|
+|0131|Palindrome Partitioning|[Go]({{< relref "/ChapterFour/0131.Palindrome-Partitioning.md" >}})|Medium||||51.4%|
+|0152|Maximum Product Subarray|[Go]({{< relref "/ChapterFour/0152.Maximum-Product-Subarray.md" >}})|Medium| O(n)| O(1)||32.6%|
+|0174|Dungeon Game|[Go]({{< relref "/ChapterFour/0174.Dungeon-Game.md" >}})|Hard||||33.2%|
+|0198|House Robber|[Go]({{< relref "/ChapterFour/0198.House-Robber.md" >}})|Medium| O(n)| O(n)||42.7%|
+|0213|House Robber II|[Go]({{< relref "/ChapterFour/0213.House-Robber-II.md" >}})|Medium| O(n)| O(n)||37.4%|
+|0300|Longest Increasing Subsequence|[Go]({{< relref "/ChapterFour/0300.Longest-Increasing-Subsequence.md" >}})|Medium| O(n log n)| O(n)||43.7%|
+|0303|Range Sum Query - Immutable|[Go]({{< relref "/ChapterFour/0303.Range-Sum-Query---Immutable.md" >}})|Easy||||47.1%|
+|0309|Best Time to Buy and Sell Stock with Cooldown|[Go]({{< relref "/ChapterFour/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.md" >}})|Medium| O(n)| O(n)||48.0%|
+|0322|Coin Change|[Go]({{< relref "/ChapterFour/0322.Coin-Change.md" >}})|Medium| O(n)| O(n)||36.9%|
+|0337|House Robber III|[Go]({{< relref "/ChapterFour/0337.House-Robber-III.md" >}})|Medium||||51.7%|
+|0338|Counting Bits|[Go]({{< relref "/ChapterFour/0338.Counting-Bits.md" >}})|Medium| O(n)| O(n)||70.2%|
+|0343|Integer Break|[Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})|Medium| O(n^2)| O(n)||51.1%|
+|0354|Russian Doll Envelopes|[Go]({{< relref "/ChapterFour/0354.Russian-Doll-Envelopes.md" >}})|Hard||||36.1%|
+|0357|Count Numbers with Unique Digits|[Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})|Medium| O(1)| O(1)||48.8%|
+|0392|Is Subsequence|[Go]({{< relref "/ChapterFour/0392.Is-Subsequence.md" >}})|Easy| O(n)| O(1)||49.5%|
+|0410|Split Array Largest Sum|[Go]({{< relref "/ChapterFour/0410.Split-Array-Largest-Sum.md" >}})|Hard||||46.1%|
+|0416|Partition Equal Subset Sum|[Go]({{< relref "/ChapterFour/0416.Partition-Equal-Subset-Sum.md" >}})|Medium| O(n^2)| O(n)||44.8%|
+|0474|Ones and Zeroes|[Go]({{< relref "/ChapterFour/0474.Ones-and-Zeroes.md" >}})|Medium||||43.4%|
+|0494|Target Sum|[Go]({{< relref "/ChapterFour/0494.Target-Sum.md" >}})|Medium||||45.8%|
+|0638|Shopping Offers|[Go]({{< relref "/ChapterFour/0638.Shopping-Offers.md" >}})|Medium||||52.6%|
+|0714|Best Time to Buy and Sell Stock with Transaction Fee|[Go]({{< relref "/ChapterFour/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee.md" >}})|Medium| O(n)| O(1)||55.9%|
+|0718|Maximum Length of Repeated Subarray|[Go]({{< relref "/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md" >}})|Medium||||50.1%|
+|0746|Min Cost Climbing Stairs|[Go]({{< relref "/ChapterFour/0746.Min-Cost-Climbing-Stairs.md" >}})|Easy| O(n)| O(1)||50.9%|
+|0838|Push Dominoes|[Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})|Medium| O(n)| O(n)||49.7%|
+|0887|Super Egg Drop|[Go]({{< relref "/ChapterFour/0887.Super-Egg-Drop.md" >}})|Hard||||27.0%|
+|0898|Bitwise ORs of Subarrays|[Go]({{< relref "/ChapterFour/0898.Bitwise-ORs-of-Subarrays.md" >}})|Medium||||34.0%|
+|0920|Number of Music Playlists|[Go]({{< relref "/ChapterFour/0920.Number-of-Music-Playlists.md" >}})|Hard||||47.6%|
+|0968|Binary Tree Cameras|[Go]({{< relref "/ChapterFour/0968.Binary-Tree-Cameras.md" >}})|Hard||||38.5%|
+|0978|Longest Turbulent Subarray|[Go]({{< relref "/ChapterFour/0978.Longest-Turbulent-Subarray.md" >}})|Medium||||46.6%|
+|1025|Divisor Game|[Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})|Easy| O(1)| O(1)||66.1%|
+|1049|Last Stone Weight II|[Go]({{< relref "/ChapterFour/1049.Last-Stone-Weight-II.md" >}})|Medium||||45.0%|
+|1074|Number of Submatrices That Sum to Target|[Go]({{< relref "/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})|Hard||||61.5%|
+|1105|Filling Bookcase Shelves|[Go]({{< relref "/ChapterFour/1105.Filling-Bookcase-Shelves.md" >}})|Medium||||57.7%|
+|1235|Maximum Profit in Job Scheduling|[Go]({{< relref "/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md" >}})|Hard||||46.9%|
+|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||77.6%|
+|1654|Minimum Jumps to Reach Home|[Go]({{< relref "/ChapterFour/1654.Minimum-Jumps-to-Reach-Home.md" >}})|Medium||||26.2%|
+|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.5%|
+|1659|Maximize Grid Happiness|[Go]({{< relref "/ChapterFour/1659.Maximize-Grid-Happiness.md" >}})|Hard||||35.1%|
+|1664|Ways to Make a Fair Array|[Go]({{< relref "/ChapterFour/1664.Ways-to-Make-a-Fair-Array.md" >}})|Medium||||60.6%|
+|1690|Stone Game VII|[Go]({{< relref "/ChapterFour/1690.Stone-Game-VII.md" >}})|Medium||||46.6%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Hash_Table.md b/website/content/ChapterTwo/Hash_Table.md
index ae4d2386..ba8d91c7 100644
--- a/website/content/ChapterTwo/Hash_Table.md
+++ b/website/content/ChapterTwo/Hash_Table.md
@@ -5,39 +5,82 @@ type: docs
# Hash Table
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|1. Two Sum | [Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})| Easy | O(n)| O(n)||
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
-|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
-|36. Valid Sudoku | [Go]({{< relref "/ChapterFour/0036.Valid-Sudoku.md" >}})| Medium | O(n^2)| O(n^2)||
-|37. Sudoku Solver | [Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})| Hard | O(n^2)| O(n^2)|❤️|
-|49. Group Anagrams | [Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})| Medium | O(n log n)| O(n)||
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|138. Copy List with Random Pointer | [Go]()| Medium | O(n)| O(1)||
-|202. Happy Number | [Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})| Easy | O(log n)| O(1)||
-|205. Isomorphic Strings | [Go]({{< relref "/ChapterFour/0205.Isomorphic-Strings.md" >}})| Easy | O(log n)| O(n)||
-|217. Contains Duplicate | [Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})| Easy | O(n)| O(n)||
-|219. Contains Duplicate II | [Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})| Easy | O(n)| O(n)||
-|242. Valid Anagram | [Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})| Easy | O(n)| O(n) ||
-|274. H-Index | [Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})| Medium | O(n)| O(n) ||
-|290. Word Pattern | [Go]({{< relref "/ChapterFour/0290.Word-Pattern.md" >}})| Easy | O(n)| O(n) ||
-|347. Top K Frequent Elements | [Go]({{< relref "/ChapterFour/0347.Top-K-Frequent-Elements.md" >}})| Medium | O(n)| O(n) ||
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|438. Find All Anagrams in a String | [Go]({{< relref "/ChapterFour/0438.Find-All-Anagrams-in-a-String.md" >}})| Easy | O(n)| O(1) ||
-|447. Number of Boomerangs | [Go]({{< relref "/ChapterFour/0447.Number-of-Boomerangs.md" >}})| Easy | O(n)| O(1) ||
-|451. Sort Characters By Frequency | [Go]({{< relref "/ChapterFour/0451.Sort-Characters-By-Frequency.md" >}})| Medium | O(n log n)| O(1) ||
-|454. 4Sum II | [Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})| Medium | O(n^2)| O(n) ||
-|648. Replace Words | [Go]({{< relref "/ChapterFour/0648.Replace-Words.md" >}})| Medium | O(n)| O(n) ||
-|676. Implement Magic Dictionary | [Go]({{< relref "/ChapterFour/0676.Implement-Magic-Dictionary.md" >}})| Medium | O(n)| O(n) ||
-|720. Longest Word in Dictionary | [Go]({{< relref "/ChapterFour/0720.Longest-Word-in-Dictionary.md" >}})| Easy | O(n)| O(n) ||
-|726. Number of Atoms | [Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})| Hard | O(n)| O(n) |❤️|
-|739. Daily Temperatures | [Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})| Medium | O(n)| O(n) ||
-|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
-|895. Maximum Frequency Stack | [Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})| Hard | O(n)| O(n) ||
-|930. Binary Subarrays With Sum | [Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})| Medium | O(n)| O(n) |❤️|
-|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n) |❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0001|Two Sum|[Go]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})|Easy| O(n)| O(n)||46.2%|
+|0003|Longest Substring Without Repeating Characters|[Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})|Medium| O(n)| O(1)|❤️|31.3%|
+|0018|4Sum|[Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})|Medium| O(n^3)| O(n^2)|❤️|34.6%|
+|0030|Substring with Concatenation of All Words|[Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})|Hard| O(n)| O(n)|❤️|26.0%|
+|0036|Valid Sudoku|[Go]({{< relref "/ChapterFour/0036.Valid-Sudoku.md" >}})|Medium| O(n^2)| O(n^2)||50.2%|
+|0037|Sudoku Solver|[Go]({{< relref "/ChapterFour/0037.Sudoku-Solver.md" >}})|Hard| O(n^2)| O(n^2)|❤️|46.0%|
+|0049|Group Anagrams|[Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})|Medium| O(n log n)| O(n)||58.9%|
+|0076|Minimum Window Substring|[Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})|Hard| O(n)| O(n)|❤️|35.7%|
+|0094|Binary Tree Inorder Traversal|[Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})|Medium| O(n)| O(1)||65.4%|
+|0136|Single Number|[Go]({{< relref "/ChapterFour/0136.Single-Number.md" >}})|Easy||||66.4%|
+|0187|Repeated DNA Sequences|[Go]({{< relref "/ChapterFour/0187.Repeated-DNA-Sequences.md" >}})|Medium||||41.2%|
+|0202|Happy Number|[Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})|Easy| O(log n)| O(1)||51.1%|
+|0204|Count Primes|[Go]({{< relref "/ChapterFour/0204.Count-Primes.md" >}})|Easy||||32.1%|
+|0205|Isomorphic Strings|[Go]({{< relref "/ChapterFour/0205.Isomorphic-Strings.md" >}})|Easy| O(log n)| O(n)||40.4%|
+|0217|Contains Duplicate|[Go]({{< relref "/ChapterFour/0217.Contains-Duplicate.md" >}})|Easy| O(n)| O(n)||56.5%|
+|0219|Contains Duplicate II|[Go]({{< relref "/ChapterFour/0219.Contains-Duplicate-II.md" >}})|Easy| O(n)| O(n)||38.5%|
+|0242|Valid Anagram|[Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})|Easy| O(n)| O(n) ||58.0%|
+|0274|H-Index|[Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})|Medium| O(n)| O(n) ||36.3%|
+|0290|Word Pattern|[Go]({{< relref "/ChapterFour/0290.Word-Pattern.md" >}})|Easy| O(n)| O(n) ||38.3%|
+|0347|Top K Frequent Elements|[Go]({{< relref "/ChapterFour/0347.Top-K-Frequent-Elements.md" >}})|Medium| O(n)| O(n) ||62.2%|
+|0349|Intersection of Two Arrays|[Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})|Easy| O(n)| O(n) ||64.4%|
+|0350|Intersection of Two Arrays II|[Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})|Easy| O(n)| O(n) ||51.9%|
+|0387|First Unique Character in a String|[Go]({{< relref "/ChapterFour/0387.First-Unique-Character-in-a-String.md" >}})|Easy||||53.7%|
+|0389|Find the Difference|[Go]({{< relref "/ChapterFour/0389.Find-the-Difference.md" >}})|Easy||||57.7%|
+|0409|Longest Palindrome|[Go]({{< relref "/ChapterFour/0409.Longest-Palindrome.md" >}})|Easy||||52.1%|
+|0438|Find All Anagrams in a String|[Go]({{< relref "/ChapterFour/0438.Find-All-Anagrams-in-a-String.md" >}})|Medium| O(n)| O(1) ||44.7%|
+|0447|Number of Boomerangs|[Go]({{< relref "/ChapterFour/0447.Number-of-Boomerangs.md" >}})|Medium| O(n)| O(1) ||52.3%|
+|0451|Sort Characters By Frequency|[Go]({{< relref "/ChapterFour/0451.Sort-Characters-By-Frequency.md" >}})|Medium| O(n log n)| O(1) ||64.1%|
+|0454|4Sum II|[Go]({{< relref "/ChapterFour/0454.4Sum-II.md" >}})|Medium| O(n^2)| O(n) ||54.5%|
+|0463|Island Perimeter|[Go]({{< relref "/ChapterFour/0463.Island-Perimeter.md" >}})|Easy||||66.5%|
+|0500|Keyboard Row|[Go]({{< relref "/ChapterFour/0500.Keyboard-Row.md" >}})|Easy||||65.5%|
+|0508|Most Frequent Subtree Sum|[Go]({{< relref "/ChapterFour/0508.Most-Frequent-Subtree-Sum.md" >}})|Medium||||58.9%|
+|0575|Distribute Candies|[Go]({{< relref "/ChapterFour/0575.Distribute-Candies.md" >}})|Easy||||61.9%|
+|0594|Longest Harmonious Subsequence|[Go]({{< relref "/ChapterFour/0594.Longest-Harmonious-Subsequence.md" >}})|Easy||||47.7%|
+|0599|Minimum Index Sum of Two Lists|[Go]({{< relref "/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md" >}})|Easy||||51.5%|
+|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||53.9%|
+|0645|Set Mismatch|[Go]({{< relref "/ChapterFour/0645.Set-Mismatch.md" >}})|Easy||||42.4%|
+|0648|Replace Words|[Go]({{< relref "/ChapterFour/0648.Replace-Words.md" >}})|Medium| O(n)| O(n) ||58.2%|
+|0676|Implement Magic Dictionary|[Go]({{< relref "/ChapterFour/0676.Implement-Magic-Dictionary.md" >}})|Medium| O(n)| O(n) ||55.2%|
+|0705|Design HashSet|[Go]({{< relref "/ChapterFour/0705.Design-HashSet.md" >}})|Easy||||64.6%|
+|0706|Design HashMap|[Go]({{< relref "/ChapterFour/0706.Design-HashMap.md" >}})|Easy||||62.6%|
+|0710|Random Pick with Blacklist|[Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})|Hard| O(n)| O(n) ||32.7%|
+|0718|Maximum Length of Repeated Subarray|[Go]({{< relref "/ChapterFour/0718.Maximum-Length-of-Repeated-Subarray.md" >}})|Medium||||50.1%|
+|0720|Longest Word in Dictionary|[Go]({{< relref "/ChapterFour/0720.Longest-Word-in-Dictionary.md" >}})|Easy| O(n)| O(n) ||49.1%|
+|0726|Number of Atoms|[Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})|Hard| O(n)| O(n) |❤️|51.0%|
+|0739|Daily Temperatures|[Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})|Medium| O(n)| O(n) ||64.3%|
+|0748|Shortest Completing Word|[Go]({{< relref "/ChapterFour/0748.Shortest-Completing-Word.md" >}})|Easy||||57.4%|
+|0771|Jewels and Stones|[Go]({{< relref "/ChapterFour/0771.Jewels-and-Stones.md" >}})|Easy||||86.8%|
+|0781|Rabbits in Forest|[Go]({{< relref "/ChapterFour/0781.Rabbits-in-Forest.md" >}})|Medium||||55.4%|
+|0811|Subdomain Visit Count|[Go]({{< relref "/ChapterFour/0811.Subdomain-Visit-Count.md" >}})|Easy||||71.2%|
+|0884|Uncommon Words from Two Sentences|[Go]({{< relref "/ChapterFour/0884.Uncommon-Words-from-Two-Sentences.md" >}})|Easy||||64.0%|
+|0895|Maximum Frequency Stack|[Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})|Hard| O(n)| O(n) ||62.2%|
+|0930|Binary Subarrays With Sum|[Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})|Medium| O(n)| O(n) |❤️|44.3%|
+|0953|Verifying an Alien Dictionary|[Go]({{< relref "/ChapterFour/0953.Verifying-an-Alien-Dictionary.md" >}})|Easy||||52.5%|
+|0961|N-Repeated Element in Size 2N Array|[Go]({{< relref "/ChapterFour/0961.N-Repeated-Element-in-Size-2N-Array.md" >}})|Easy||||74.4%|
+|0970|Powerful Integers|[Go]({{< relref "/ChapterFour/0970.Powerful-Integers.md" >}})|Easy||||39.9%|
+|0981|Time Based Key-Value Store|[Go]({{< relref "/ChapterFour/0981.Time-Based-Key-Value-Store.md" >}})|Medium||||54.0%|
+|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard| O(n)| O(n) |❤️|50.5%|
+|1002|Find Common Characters|[Go]({{< relref "/ChapterFour/1002.Find-Common-Characters.md" >}})|Easy||||68.1%|
+|1078|Occurrences After Bigram|[Go]({{< relref "/ChapterFour/1078.Occurrences-After-Bigram.md" >}})|Easy||||64.8%|
+|1160|Find Words That Can Be Formed by Characters|[Go]({{< relref "/ChapterFour/1160.Find-Words-That-Can-Be-Formed-by-Characters.md" >}})|Easy||||67.5%|
+|1189|Maximum Number of Balloons|[Go]({{< relref "/ChapterFour/1189.Maximum-Number-of-Balloons.md" >}})|Easy||||61.8%|
+|1207|Unique Number of Occurrences|[Go]({{< relref "/ChapterFour/1207.Unique-Number-of-Occurrences.md" >}})|Easy||||71.6%|
+|1512|Number of Good Pairs|[Go]({{< relref "/ChapterFour/1512.Number-of-Good-Pairs.md" >}})|Easy||||87.9%|
+|1539|Kth Missing Positive Number|[Go]({{< relref "/ChapterFour/1539.Kth-Missing-Positive-Number.md" >}})|Easy||||55.3%|
+|1640|Check Array Formation Through Concatenation|[Go]({{< relref "/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md" >}})|Easy||||62.1%|
+|1679|Max Number of K-Sum Pairs|[Go]({{< relref "/ChapterFour/1679.Max-Number-of-K-Sum-Pairs.md" >}})|Medium||||54.9%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Linked_List.md b/website/content/ChapterTwo/Linked_List.md
index d786f466..787e9ea0 100644
--- a/website/content/ChapterTwo/Linked_List.md
+++ b/website/content/ChapterTwo/Linked_List.md
@@ -19,35 +19,47 @@ type: docs
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|2. Add Two Numbers | [Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})| Medium | O(n)| O(1)||
-|19. Remove Nth Node From End of List | [Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})| Medium | O(n)| O(1)||
-|21. Merge Two Sorted Lists | [Go]({{< relref "/ChapterFour/0021.Merge-Two-Sorted-Lists.md" >}})| Easy | O(log n)| O(1)||
-|23. Merge k Sorted Lists| [Go]({{< relref "/ChapterFour/0023.Merge-k-Sorted-Lists.md" >}})| Hard | O(log n)| O(1)|❤️|
-|24. Swap Nodes in Pairs | [Go]({{< relref "/ChapterFour/0024.Swap-Nodes-in-Pairs.md" >}})| Medium | O(n)| O(1)||
-|25. Reverse Nodes in k-Group | [Go]({{< relref "/ChapterFour/0025.Reverse-Nodes-in-k-Group.md" >}})| Hard | O(log n)| O(1)|❤️|
-|61. Rotate List | [Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})| Medium | O(n)| O(1)||
-|82. Remove Duplicates from Sorted List II | [Go]({{< relref "/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md" >}})| Medium | O(n)| O(1)||
-|83. Remove Duplicates from Sorted List | [Go]({{< relref "/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md" >}})| Easy | O(n)| O(1)||
-|86. Partition List | [Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|92. Reverse Linked List II | [Go]({{< relref "/ChapterFour/0092.Reverse-Linked-List-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|109. Convert Sorted List to Binary Search Tree | [Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})| Medium | O(log n)| O(n)||
-|141. Linked List Cycle | [Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})| Easy | O(n)| O(1)|❤️|
-|142. Linked List Cycle II | [Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|143. Reorder List | [Go]({{< relref "/ChapterFour/0143.Reorder-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|147. Insertion Sort List | [Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|148. Sort List | [Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})| Medium | O(n log n)| O(n)|❤️|
-|160. Intersection of Two Linked Lists | [Go]({{< relref "/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md" >}})| Easy | O(n)| O(1)|❤️|
-|203. Remove Linked List Elements | [Go]({{< relref "/ChapterFour/0203.Remove-Linked-List-Elements.md" >}})| Easy | O(n)| O(1)||
-|206. Reverse Linked List | [Go]({{< relref "/ChapterFour/0206.Reverse-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|234. Palindrome Linked List | [Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|237. Delete Node in a Linked List | [Go]({{< relref "/ChapterFour/0237.Delete-Node-in-a-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|328. Odd Even Linked List | [Go]({{< relref "/ChapterFour/0328.Odd-Even-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|445. Add Two Numbers II | [Go]({{< relref "/ChapterFour/0445.Add-Two-Numbers-II.md" >}})| Medium | O(n)| O(n)||
-|725. Split Linked List in Parts | [Go]({{< relref "/ChapterFour/0725.Split-Linked-List-in-Parts.md" >}})| Medium | O(n)| O(1)||
-|817. Linked List Components | [Go]({{< relref "/ChapterFour/0817.Linked-List-Components.md" >}})| Medium | O(n)| O(1)||
-|707. Design Linked List | [Go]({{< relref "/ChapterFour/0707.Design-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|876. Middle of the Linked List | [Go]({{< relref "/ChapterFour/0876.Middle-of-the-Linked-List.md" >}})| Easy | O(n)| O(1)|❤️|
-|1019. Next Greater Node In Linked List | [Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0002|Add Two Numbers|[Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})|Medium| O(n)| O(1)||35.2%|
+|0019|Remove Nth Node From End of List|[Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})|Medium| O(n)| O(1)||35.6%|
+|0021|Merge Two Sorted Lists|[Go]({{< relref "/ChapterFour/0021.Merge-Two-Sorted-Lists.md" >}})|Easy| O(log n)| O(1)||55.7%|
+|0023|Merge k Sorted Lists|[Go]({{< relref "/ChapterFour/0023.Merge-k-Sorted-Lists.md" >}})|Hard| O(log n)| O(1)|❤️|42.0%|
+|0024|Swap Nodes in Pairs|[Go]({{< relref "/ChapterFour/0024.Swap-Nodes-in-Pairs.md" >}})|Medium| O(n)| O(1)||52.7%|
+|0025|Reverse Nodes in k-Group|[Go]({{< relref "/ChapterFour/0025.Reverse-Nodes-in-k-Group.md" >}})|Hard| O(log n)| O(1)|❤️|44.3%|
+|0061|Rotate List|[Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})|Medium| O(n)| O(1)||31.6%|
+|0082|Remove Duplicates from Sorted List II|[Go]({{< relref "/ChapterFour/0082.Remove-Duplicates-from-Sorted-List-II.md" >}})|Medium| O(n)| O(1)||39.0%|
+|0083|Remove Duplicates from Sorted List|[Go]({{< relref "/ChapterFour/0083.Remove-Duplicates-from-Sorted-List.md" >}})|Easy| O(n)| O(1)||46.3%|
+|0086|Partition List|[Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})|Medium| O(n)| O(1)|❤️|43.0%|
+|0092|Reverse Linked List II|[Go]({{< relref "/ChapterFour/0092.Reverse-Linked-List-II.md" >}})|Medium| O(n)| O(1)|❤️|40.3%|
+|0109|Convert Sorted List to Binary Search Tree|[Go]({{< relref "/ChapterFour/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})|Medium| O(log n)| O(n)||49.8%|
+|0141|Linked List Cycle|[Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})|Easy| O(n)| O(1)|❤️|42.2%|
+|0142|Linked List Cycle II|[Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})|Medium| O(n)| O(1)|❤️|39.3%|
+|0143|Reorder List|[Go]({{< relref "/ChapterFour/0143.Reorder-List.md" >}})|Medium| O(n)| O(1)|❤️|40.3%|
+|0147|Insertion Sort List|[Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})|Medium| O(n)| O(1)|❤️|44.1%|
+|0148|Sort List|[Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})|Medium| O(n log n)| O(n)|❤️|45.8%|
+|0160|Intersection of Two Linked Lists|[Go]({{< relref "/ChapterFour/0160.Intersection-of-Two-Linked-Lists.md" >}})|Easy| O(n)| O(1)|❤️|42.7%|
+|0203|Remove Linked List Elements|[Go]({{< relref "/ChapterFour/0203.Remove-Linked-List-Elements.md" >}})|Easy| O(n)| O(1)||39.0%|
+|0206|Reverse Linked List|[Go]({{< relref "/ChapterFour/0206.Reverse-Linked-List.md" >}})|Easy| O(n)| O(1)||64.8%|
+|0234|Palindrome Linked List|[Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})|Easy| O(n)| O(1)||40.2%|
+|0237|Delete Node in a Linked List|[Go]({{< relref "/ChapterFour/0237.Delete-Node-in-a-Linked-List.md" >}})|Easy| O(n)| O(1)||66.3%|
+|0328|Odd Even Linked List|[Go]({{< relref "/ChapterFour/0328.Odd-Even-Linked-List.md" >}})|Medium| O(n)| O(1)||56.9%|
+|0445|Add Two Numbers II|[Go]({{< relref "/ChapterFour/0445.Add-Two-Numbers-II.md" >}})|Medium| O(n)| O(n)||56.0%|
+|0707|Design Linked List|[Go]({{< relref "/ChapterFour/0707.Design-Linked-List.md" >}})|Medium| O(n)| O(1)||25.7%|
+|0725|Split Linked List in Parts|[Go]({{< relref "/ChapterFour/0725.Split-Linked-List-in-Parts.md" >}})|Medium| O(n)| O(1)||52.8%|
+|0817|Linked List Components|[Go]({{< relref "/ChapterFour/0817.Linked-List-Components.md" >}})|Medium| O(n)| O(1)||57.6%|
+|0876|Middle of the Linked List|[Go]({{< relref "/ChapterFour/0876.Middle-of-the-Linked-List.md" >}})|Easy| O(n)| O(1)|❤️|68.9%|
+|1019|Next Greater Node In Linked List|[Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})|Medium| O(n)| O(1)||58.2%|
+|1171|Remove Zero Sum Consecutive Nodes from Linked List|[Go]({{< relref "/ChapterFour/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md" >}})|Medium||||41.4%|
+|1290|Convert Binary Number in a Linked List to Integer|[Go]({{< relref "/ChapterFour/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md" >}})|Easy||||81.7%|
+|1669|Merge In Between Linked Lists|[Go]({{< relref "/ChapterFour/1669.Merge-In-Between-Linked-Lists.md" >}})|Medium||||78.2%|
+|1670|Design Front Middle Back Queue|[Go]({{< relref "/ChapterFour/1670.Design-Front-Middle-Back-Queue.md" >}})|Medium||||54.7%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Math.md b/website/content/ChapterTwo/Math.md
index b20da7a3..071d24d0 100644
--- a/website/content/ChapterTwo/Math.md
+++ b/website/content/ChapterTwo/Math.md
@@ -5,24 +5,85 @@ type: docs
# Math
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|2. Add Two Numbers | [Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})| Medium | O(n)| O(1)||
-|50. Pow(x, n) | [Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})| Medium | O(log n)| O(1)||
-|60. Permutation Sequence | [Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})| Medium | O(n log n)| O(1)||
-|69. Sqrt(x) | [Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})| Easy | O(log n)| O(1)||
-|202. Happy Number | [Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})| Easy | O(log n)| O(1)||
-|224. Basic Calculator | [Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})| Hard | O(n)| O(n)||
-|231. Power of Two | [Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})| Easy | O(1)| O(1)||
-|263. Ugly Number | [Go]({{< relref "/ChapterFour/0263.Ugly-Number.md" >}})| Easy | O(log n)| O(1)||
-|326. Power of Three | [Go]({{< relref "/ChapterFour/0326.Power-of-Three.md" >}})| Easy | O(1)| O(1)||
-|343. Integer Break | [Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})| Medium | O(n^2)| O(n)||
-|357. Count Numbers with Unique Digits | [Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})| Medium | O(1)| O(1)||
-|628. Maximum Product of Three Numbers | [Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})| Easy | O(n)| O(1)||
-|885. Spiral Matrix III | [Go]({{< relref "/ChapterFour/0885.Spiral-Matrix-III.md" >}})| Medium | O(n^2)| O(1)||
-|891. Sum of Subsequence Widths | [Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})| Hard | O(n log n)| O(1)||
-|942. DI String Match | [Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})| Easy | O(n)| O(1)||
-|976. Largest Perimeter Triangle | [Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})| Easy | O(n log n)| O(log n) ||
-|996. Number of Squareful Arrays | [Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})| Hard | O(n log n)| O(n) ||
-|1025. Divisor Game | [Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})| Easy | O(1)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0002|Add Two Numbers|[Go]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})|Medium| O(n)| O(1)||35.2%|
+|0007|Reverse Integer|[Go]({{< relref "/ChapterFour/0007.Reverse-Integer.md" >}})|Easy||||25.9%|
+|0009|Palindrome Number|[Go]({{< relref "/ChapterFour/0009.Palindrome-Number.md" >}})|Easy||||49.5%|
+|0013|Roman to Integer|[Go]({{< relref "/ChapterFour/0013.Roman-to-Integer.md" >}})|Easy||||56.4%|
+|0029|Divide Two Integers|[Go]({{< relref "/ChapterFour/0029.Divide-Two-Integers.md" >}})|Medium||||16.6%|
+|0050|Pow(x, n)|[Go]({{< relref "/ChapterFour/0050.Powx-n.md" >}})|Medium| O(log n)| O(1)||30.8%|
+|0060|Permutation Sequence|[Go]({{< relref "/ChapterFour/0060.Permutation-Sequence.md" >}})|Hard| O(n log n)| O(1)||39.2%|
+|0067|Add Binary|[Go]({{< relref "/ChapterFour/0067.Add-Binary.md" >}})|Easy||||46.6%|
+|0069|Sqrt(x)|[Go]({{< relref "/ChapterFour/0069.Sqrtx.md" >}})|Easy| O(log n)| O(1)||34.8%|
+|0168|Excel Sheet Column Title|[Go]({{< relref "/ChapterFour/0168.Excel-Sheet-Column-Title.md" >}})|Easy||||31.6%|
+|0171|Excel Sheet Column Number|[Go]({{< relref "/ChapterFour/0171.Excel-Sheet-Column-Number.md" >}})|Easy||||56.7%|
+|0172|Factorial Trailing Zeroes|[Go]({{< relref "/ChapterFour/0172.Factorial-Trailing-Zeroes.md" >}})|Easy||||38.4%|
+|0202|Happy Number|[Go]({{< relref "/ChapterFour/0202.Happy-Number.md" >}})|Easy| O(log n)| O(1)||51.1%|
+|0204|Count Primes|[Go]({{< relref "/ChapterFour/0204.Count-Primes.md" >}})|Easy||||32.1%|
+|0223|Rectangle Area|[Go]({{< relref "/ChapterFour/0223.Rectangle-Area.md" >}})|Medium||||38.1%|
+|0224|Basic Calculator|[Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})|Hard| O(n)| O(n)||38.0%|
+|0231|Power of Two|[Go]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})|Easy| O(1)| O(1)||43.8%|
+|0258|Add Digits|[Go]({{< relref "/ChapterFour/0258.Add-Digits.md" >}})|Easy||||58.4%|
+|0263|Ugly Number|[Go]({{< relref "/ChapterFour/0263.Ugly-Number.md" >}})|Easy| O(log n)| O(1)||41.7%|
+|0268|Missing Number|[Go]({{< relref "/ChapterFour/0268.Missing-Number.md" >}})|Easy||||53.4%|
+|0326|Power of Three|[Go]({{< relref "/ChapterFour/0326.Power-of-Three.md" >}})|Easy| O(1)| O(1)||42.1%|
+|0343|Integer Break|[Go]({{< relref "/ChapterFour/0343.Integer-Break.md" >}})|Medium| O(n^2)| O(n)||51.1%|
+|0357|Count Numbers with Unique Digits|[Go]({{< relref "/ChapterFour/0357.Count-Numbers-with-Unique-Digits.md" >}})|Medium| O(1)| O(1)||48.8%|
+|0367|Valid Perfect Square|[Go]({{< relref "/ChapterFour/0367.Valid-Perfect-Square.md" >}})|Easy||||42.0%|
+|0372|Super Pow|[Go]({{< relref "/ChapterFour/0372.Super-Pow.md" >}})|Medium||||36.6%|
+|0397|Integer Replacement|[Go]({{< relref "/ChapterFour/0397.Integer-Replacement.md" >}})|Medium||||33.4%|
+|0441|Arranging Coins|[Go]({{< relref "/ChapterFour/0441.Arranging-Coins.md" >}})|Easy||||42.3%|
+|0447|Number of Boomerangs|[Go]({{< relref "/ChapterFour/0447.Number-of-Boomerangs.md" >}})|Medium||||52.3%|
+|0453|Minimum Moves to Equal Array Elements|[Go]({{< relref "/ChapterFour/0453.Minimum-Moves-to-Equal-Array-Elements.md" >}})|Easy||||50.7%|
+|0483|Smallest Good Base|[Go]({{< relref "/ChapterFour/0483.Smallest-Good-Base.md" >}})|Hard||||36.2%|
+|0507|Perfect Number|[Go]({{< relref "/ChapterFour/0507.Perfect-Number.md" >}})|Easy||||36.0%|
+|0537|Complex Number Multiplication|[Go]({{< relref "/ChapterFour/0537.Complex-Number-Multiplication.md" >}})|Medium||||68.3%|
+|0598|Range Addition II|[Go]({{< relref "/ChapterFour/0598.Range-Addition-II.md" >}})|Easy||||50.0%|
+|0628|Maximum Product of Three Numbers|[Go]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})|Easy| O(n)| O(1)||47.0%|
+|0633|Sum of Square Numbers|[Go]({{< relref "/ChapterFour/0633.Sum-of-Square-Numbers.md" >}})|Medium||||32.4%|
+|0645|Set Mismatch|[Go]({{< relref "/ChapterFour/0645.Set-Mismatch.md" >}})|Easy||||42.4%|
+|0753|Cracking the Safe|[Go]({{< relref "/ChapterFour/0753.Cracking-the-Safe.md" >}})|Hard||||52.0%|
+|0781|Rabbits in Forest|[Go]({{< relref "/ChapterFour/0781.Rabbits-in-Forest.md" >}})|Medium||||55.4%|
+|0812|Largest Triangle Area|[Go]({{< relref "/ChapterFour/0812.Largest-Triangle-Area.md" >}})|Easy||||58.8%|
+|0836|Rectangle Overlap|[Go]({{< relref "/ChapterFour/0836.Rectangle-Overlap.md" >}})|Easy||||45.1%|
+|0878|Nth Magical Number|[Go]({{< relref "/ChapterFour/0878.Nth-Magical-Number.md" >}})|Hard||||28.9%|
+|0885|Spiral Matrix III|[Go]({{< relref "/ChapterFour/0885.Spiral-Matrix-III.md" >}})|Medium| O(n^2)| O(1)||70.5%|
+|0887|Super Egg Drop|[Go]({{< relref "/ChapterFour/0887.Super-Egg-Drop.md" >}})|Hard||||27.0%|
+|0891|Sum of Subsequence Widths|[Go]({{< relref "/ChapterFour/0891.Sum-of-Subsequence-Widths.md" >}})|Hard| O(n log n)| O(1)||32.8%|
+|0892|Surface Area of 3D Shapes|[Go]({{< relref "/ChapterFour/0892.Surface-Area-of-3D-Shapes.md" >}})|Easy||||59.6%|
+|0910|Smallest Range II|[Go]({{< relref "/ChapterFour/0910.Smallest-Range-II.md" >}})|Medium||||31.2%|
+|0914|X of a Kind in a Deck of Cards|[Go]({{< relref "/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})|Easy||||34.4%|
+|0927|Three Equal Parts|[Go]({{< relref "/ChapterFour/0927.Three-Equal-Parts.md" >}})|Hard||||34.5%|
+|0942|DI String Match|[Go]({{< relref "/ChapterFour/0942.DI-String-Match.md" >}})|Easy| O(n)| O(1)||73.4%|
+|0949|Largest Time for Given Digits|[Go]({{< relref "/ChapterFour/0949.Largest-Time-for-Given-Digits.md" >}})|Medium||||36.2%|
+|0952|Largest Component Size by Common Factor|[Go]({{< relref "/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md" >}})|Hard||||36.1%|
+|0970|Powerful Integers|[Go]({{< relref "/ChapterFour/0970.Powerful-Integers.md" >}})|Easy||||39.9%|
+|0976|Largest Perimeter Triangle|[Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})|Easy| O(n log n)| O(log n) ||58.5%|
+|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0996.Number-of-Squareful-Arrays.md" >}})|Hard| O(n log n)| O(n) ||48.0%|
+|1017|Convert to Base -2|[Go]({{< relref "/ChapterFour/1017.Convert-to-Base--2.md" >}})|Medium||||59.6%|
+|1025|Divisor Game|[Go]({{< relref "/ChapterFour/1025.Divisor-Game.md" >}})|Easy| O(1)| O(1)||66.1%|
+|1037|Valid Boomerang|[Go]({{< relref "/ChapterFour/1037.Valid-Boomerang.md" >}})|Easy||||37.9%|
+|1073|Adding Two Negabinary Numbers|[Go]({{< relref "/ChapterFour/1073.Adding-Two-Negabinary-Numbers.md" >}})|Medium||||34.7%|
+|1093|Statistics from a Large Sample|[Go]({{< relref "/ChapterFour/1093.Statistics-from-a-Large-Sample.md" >}})|Medium||||49.3%|
+|1154|Day of the Year|[Go]({{< relref "/ChapterFour/1154.Day-of-the-Year.md" >}})|Easy||||49.3%|
+|1175|Prime Arrangements|[Go]({{< relref "/ChapterFour/1175.Prime-Arrangements.md" >}})|Easy||||51.8%|
+|1201|Ugly Number III|[Go]({{< relref "/ChapterFour/1201.Ugly-Number-III.md" >}})|Medium||||26.3%|
+|1217|Minimum Cost to Move Chips to The Same Position|[Go]({{< relref "/ChapterFour/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position.md" >}})|Easy||||71.2%|
+|1232|Check If It Is a Straight Line|[Go]({{< relref "/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md" >}})|Easy||||43.8%|
+|1281|Subtract the Product and Sum of Digits of an Integer|[Go]({{< relref "/ChapterFour/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer.md" >}})|Easy||||85.6%|
+|1317|Convert Integer to the Sum of Two No-Zero Integers|[Go]({{< relref "/ChapterFour/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers.md" >}})|Easy||||56.8%|
+|1512|Number of Good Pairs|[Go]({{< relref "/ChapterFour/1512.Number-of-Good-Pairs.md" >}})|Easy||||87.9%|
+|1641|Count Sorted Vowel Strings|[Go]({{< relref "/ChapterFour/1641.Count-Sorted-Vowel-Strings.md" >}})|Medium||||77.6%|
+|1648|Sell Diminishing-Valued Colored Balls|[Go]({{< relref "/ChapterFour/1648.Sell-Diminishing-Valued-Colored-Balls.md" >}})|Medium||||30.9%|
+|1680|Concatenation of Consecutive Binary Numbers|[Go]({{< relref "/ChapterFour/1680.Concatenation-of-Consecutive-Binary-Numbers.md" >}})|Medium||||45.1%|
+|1685|Sum of Absolute Differences in a Sorted Array|[Go]({{< relref "/ChapterFour/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md" >}})|Medium||||61.8%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Segment_Tree.md b/website/content/ChapterTwo/Segment_Tree.md
index d083d921..8de002b0 100644
--- a/website/content/ChapterTwo/Segment_Tree.md
+++ b/website/content/ChapterTwo/Segment_Tree.md
@@ -7,7 +7,7 @@ type: docs

-- 线段数的经典数组实现写法。将合并两个节点 pushUp 逻辑抽象出来了,可以实现任意操作(常见的操作有:加法,取 max,min 等等)。第 218 题,第 303 题,第 307 题,第 699 题。
+- 线段树的经典数组实现写法。将合并两个节点 pushUp 逻辑抽象出来了,可以实现任意操作(常见的操作有:加法,取 max,min 等等)。第 218 题,第 303 题,第 307 题,第 699 题。
- 计数线段树的经典写法。第 315 题,第 327 题,第 493 题。
- 线段树的树的实现写法。第 715 题,第 732 题。
- 区间懒惰更新。第 218 题,第 699 题。
@@ -33,16 +33,25 @@ type: docs
[HDU 1542 Atlantis](http://acm.hdu.edu.cn/showproblem.php?pid=1542) update:区间增减 query:直接取根节点的值
[HDU 1828 Picture](http://acm.hdu.edu.cn/showproblem.php?pid=1828) update:区间增减 query:直接取根节点的值
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|218. The Skyline Problem | [Go]({{< relref "/ChapterFour/0218.The-Skyline-Problem.md" >}})| Hard | O(n log n)| O(n)|❤️|
-|307. Range Sum Query - Mutable | [Go]({{< relref "/ChapterFour/0307.Range-Sum-Query---Mutable.md" >}})| Hard | O(1)| O(n)||
-|315. Count of Smaller Numbers After Self | [Go]({{< relref "/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md" >}})| Hard | O(n log n)| O(n)||
-|327. Count of Range Sum | [Go]({{< relref "/ChapterFour/0327.Count-of-Range-Sum.md" >}})| Hard | O(n log n)| O(n)|❤️|
-|493. Reverse Pairs | [Go]({{< relref "/ChapterFour/0493.Reverse-Pairs.md" >}})| Hard | O(n log n)| O(n)||
-|699. Falling Squares | [Go]({{< relref "/ChapterFour/0699.Falling-Squares.md" >}})| Hard | O(n log n)| O(n)|❤️|
-|715. Range Module | [Go]({{< relref "/ChapterFour/0715.Range-Module.md" >}})| Hard | O(log n)| O(n)|❤️|
-|732. My Calendar III | [Go]({{< relref "/ChapterFour/0732.My-Calendar-III.md" >}})| Hard | O(log n)| O(n)|❤️|
-|850. Rectangle Area II | [Go]({{< relref "/ChapterFour/0850.Rectangle-Area-II.md" >}})| Hard | O(n log n)| O(n)|❤️|
-|1157. Online Majority Element In Subarray | [Go]({{< relref "/ChapterFour/1157.Online-Majority-Element-In-Subarray.md" >}})| Hard | O(log n)| O(n)|❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0218|The Skyline Problem|[Go]({{< relref "/ChapterFour/0218.The-Skyline-Problem.md" >}})|Hard| O(n log n)| O(n)|❤️|36.1%|
+|0307|Range Sum Query - Mutable|[Go]({{< relref "/ChapterFour/0307.Range-Sum-Query---Mutable.md" >}})|Medium| O(1)| O(n)||36.5%|
+|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard| O(n log n)| O(n)||42.6%|
+|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0327.Count-of-Range-Sum.md" >}})|Hard| O(n log n)| O(n)|❤️|35.9%|
+|0493|Reverse Pairs|[Go]({{< relref "/ChapterFour/0493.Reverse-Pairs.md" >}})|Hard| O(n log n)| O(n)||26.6%|
+|0699|Falling Squares|[Go]({{< relref "/ChapterFour/0699.Falling-Squares.md" >}})|Hard| O(n log n)| O(n)|❤️|42.4%|
+|0715|Range Module|[Go]({{< relref "/ChapterFour/0715.Range-Module.md" >}})|Hard| O(log n)| O(n)|❤️|40.0%|
+|0732|My Calendar III|[Go]({{< relref "/ChapterFour/0732.My-Calendar-III.md" >}})|Hard| O(log n)| O(n)|❤️|61.4%|
+|0850|Rectangle Area II|[Go]({{< relref "/ChapterFour/0850.Rectangle-Area-II.md" >}})|Hard| O(n log n)| O(n)|❤️|48.3%|
+|1157|Online Majority Element In Subarray|[Go]({{< relref "/ChapterFour/1157.Online-Majority-Element-In-Subarray.md" >}})|Hard| O(log n)| O(n)|❤️|39.5%|
+|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||36.1%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Sliding_Window.md b/website/content/ChapterTwo/Sliding_Window.md
index 2ffd90d7..c6b98e76 100644
--- a/website/content/ChapterTwo/Sliding_Window.md
+++ b/website/content/ChapterTwo/Sliding_Window.md
@@ -25,19 +25,29 @@ type: docs
```
- 滑动窗口经典题。第 239 题,第 480 题。
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|239. Sliding Window Maximum | [Go]({{< relref "/ChapterFour/0239.Sliding-Window-Maximum.md" >}})| Hard | O(n * k)| O(n)|❤️|
-|424. Longest Repeating Character Replacement | [Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})| Medium | O(n)| O(1) ||
-|480. Sliding Window Median | [Go]({{< relref "/ChapterFour/0480.Sliding-Window-Median.md" >}})| Hard | O(n * log k)| O(k)|❤️|
-|567. Permutation in String | [Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})| Medium | O(n)| O(1)|❤️|
-|978. Longest Turbulent Subarray | [Go]({{< relref "/ChapterFour/0978.Longest-Turbulent-Subarray.md" >}})| Medium | O(n)| O(1)|❤️|
-|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n)|❤️|
-|995. Minimum Number of K Consecutive Bit Flips | [Go]({{< relref "/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md" >}})| Hard | O(n)| O(1)|❤️|
-|1004. Max Consecutive Ones III | [Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})| Medium | O(n)| O(1) ||
-|1040. Moving Stones Until Consecutive II | [Go]({{< relref "/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md" >}})| Medium | O(n log n)| O(1) |❤️|
-|1052. Grumpy Bookstore Owner | [Go]({{< relref "/ChapterFour/1052.Grumpy-Bookstore-Owner.md" >}})| Medium | O(n log n)| O(1) ||
-|1074. Number of Submatrices That Sum to Target | [Go]({{< relref "/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})| Hard | O(n^3)| O(n) |❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0003|Longest Substring Without Repeating Characters|[Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})|Medium| O(n)| O(1)|❤️|31.3%|
+|0076|Minimum Window Substring|[Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})|Hard| O(n)| O(n)|❤️|35.7%|
+|0239|Sliding Window Maximum|[Go]({{< relref "/ChapterFour/0239.Sliding-Window-Maximum.md" >}})|Hard| O(n * k)| O(n)|❤️|44.5%|
+|0424|Longest Repeating Character Replacement|[Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})|Medium| O(n)| O(1) ||48.0%|
+|0480|Sliding Window Median|[Go]({{< relref "/ChapterFour/0480.Sliding-Window-Median.md" >}})|Hard| O(n * log k)| O(k)|❤️|38.4%|
+|0567|Permutation in String|[Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})|Medium| O(n)| O(1)|❤️|44.6%|
+|0978|Longest Turbulent Subarray|[Go]({{< relref "/ChapterFour/0978.Longest-Turbulent-Subarray.md" >}})|Medium| O(n)| O(1)|❤️|46.6%|
+|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard| O(n)| O(n)|❤️|50.5%|
+|0995|Minimum Number of K Consecutive Bit Flips|[Go]({{< relref "/ChapterFour/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md" >}})|Hard| O(n)| O(1)|❤️|49.6%|
+|1004|Max Consecutive Ones III|[Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})|Medium| O(n)| O(1) ||60.5%|
+|1040|Moving Stones Until Consecutive II|[Go]({{< relref "/ChapterFour/1040.Moving-Stones-Until-Consecutive-II.md" >}})|Medium| O(n log n)| O(1) |❤️|53.9%|
+|1052|Grumpy Bookstore Owner|[Go]({{< relref "/ChapterFour/1052.Grumpy-Bookstore-Owner.md" >}})|Medium| O(n log n)| O(1) ||55.7%|
+|1074|Number of Submatrices That Sum to Target|[Go]({{< relref "/ChapterFour/1074.Number-of-Submatrices-That-Sum-to-Target.md" >}})|Hard| O(n^3)| O(n) |❤️|61.5%|
+|1208|Get Equal Substrings Within Budget|[Go]({{< relref "/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md" >}})|Medium||||43.6%|
+|1658|Minimum Operations to Reduce X to Zero|[Go]({{< relref "/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md" >}})|Medium||||33.4%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Sort.md b/website/content/ChapterTwo/Sort.md
index f759edf8..82f00572 100644
--- a/website/content/ChapterTwo/Sort.md
+++ b/website/content/ChapterTwo/Sort.md
@@ -14,29 +14,46 @@ type: docs
- 两两不相邻的排序。第 767 题,第 1054 题。
- "饼子排序"。第 969 题。
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|56. Merge Intervals | [Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})| Medium | O(n log n)| O(log n)||
-|57. Insert Interval | [Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})| Hard | O(n)| O(1)||
-|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
-|147. Insertion Sort List | [Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})| Medium | O(n)| O(1) |❤️|
-|148. Sort List | [Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})| Medium |O(n log n)| O(log n)|❤️|
-|164. Maximum Gap | [Go]({{< relref "/ChapterFour/0164.Maximum-Gap.md" >}})| Hard | O(n log n)| O(log n) |❤️|
-|179. Largest Number | [Go]({{< relref "/ChapterFour/0179.Largest-Number.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|220. Contains Duplicate III | [Go]({{< relref "/ChapterFour/0220.Contains-Duplicate-III.md" >}})| Medium | O(n log n)| O(1) |❤️|
-|242. Valid Anagram | [Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})| Easy | O(n)| O(n) ||
-|274. H-Index | [Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})| Medium | O(n)| O(n) ||
-|324. Wiggle Sort II | [Go]({{< relref "/ChapterFour/0324.Wiggle-Sort-II.md" >}})| Medium| O(n)| O(n)|❤️|
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|524. Longest Word in Dictionary through Deleting | [Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})| Medium | O(n)| O(1) ||
-|767. Reorganize String | [Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|853. Car Fleet | [Go]({{< relref "/ChapterFour/0853.Car-Fleet.md" >}})| Medium | O(n log n)| O(log n) ||
-|710. Random Pick with Blacklist | [Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})| Hard | O(n)| O(n) ||
-|922. Sort Array By Parity II | [Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})| Easy | O(n)| O(1) ||
-|969. Pancake Sorting | [Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|973. K Closest Points to Origin | [Go]({{< relref "/ChapterFour/0973.K-Closest-Points-to-Origin.md" >}})| Medium | O(n log n)| O(log n) ||
-|976. Largest Perimeter Triangle | [Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})| Easy | O(n log n)| O(log n) ||
-|1030. Matrix Cells in Distance Order | [Go]({{< relref "/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md" >}})| Easy | O(n^2)| O(1) ||
-|1054. Distant Barcodes | [Go]({{< relref "/ChapterFour/1054.Distant-Barcodes.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0056|Merge Intervals|[Go]({{< relref "/ChapterFour/0056.Merge-Intervals.md" >}})|Medium| O(n log n)| O(log n)||40.7%|
+|0057|Insert Interval|[Go]({{< relref "/ChapterFour/0057.Insert-Interval.md" >}})|Medium| O(n)| O(1)||34.9%|
+|0075|Sort Colors|[Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})|Medium| O(n)| O(1)|❤️|49.0%|
+|0147|Insertion Sort List|[Go]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})|Medium| O(n)| O(1) |❤️|44.1%|
+|0148|Sort List|[Go]({{< relref "/ChapterFour/0148.Sort-List.md" >}})|Medium|O(n log n)| O(log n)|❤️|45.8%|
+|0164|Maximum Gap|[Go]({{< relref "/ChapterFour/0164.Maximum-Gap.md" >}})|Hard| O(n log n)| O(log n) |❤️|36.6%|
+|0179|Largest Number|[Go]({{< relref "/ChapterFour/0179.Largest-Number.md" >}})|Medium| O(n log n)| O(log n) |❤️|30.4%|
+|0220|Contains Duplicate III|[Go]({{< relref "/ChapterFour/0220.Contains-Duplicate-III.md" >}})|Medium| O(n log n)| O(1) |❤️|21.3%|
+|0242|Valid Anagram|[Go]({{< relref "/ChapterFour/0242.Valid-Anagram.md" >}})|Easy| O(n)| O(n) ||58.0%|
+|0274|H-Index|[Go]({{< relref "/ChapterFour/0274.H-Index.md" >}})|Medium| O(n)| O(n) ||36.3%|
+|0315|Count of Smaller Numbers After Self|[Go]({{< relref "/ChapterFour/0315.Count-of-Smaller-Numbers-After-Self.md" >}})|Hard||||42.6%|
+|0324|Wiggle Sort II|[Go]({{< relref "/ChapterFour/0324.Wiggle-Sort-II.md" >}})|Medium| O(n)| O(n)|❤️|30.6%|
+|0327|Count of Range Sum|[Go]({{< relref "/ChapterFour/0327.Count-of-Range-Sum.md" >}})|Hard||||35.9%|
+|0349|Intersection of Two Arrays|[Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})|Easy| O(n)| O(n) ||64.4%|
+|0350|Intersection of Two Arrays II|[Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})|Easy| O(n)| O(n) ||51.9%|
+|0493|Reverse Pairs|[Go]({{< relref "/ChapterFour/0493.Reverse-Pairs.md" >}})|Hard||||26.6%|
+|0524|Longest Word in Dictionary through Deleting|[Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})|Medium| O(n)| O(1) ||48.9%|
+|0710|Random Pick with Blacklist|[Go]({{< relref "/ChapterFour/0710.Random-Pick-with-Blacklist.md" >}})|Hard| O(n)| O(n) ||32.7%|
+|0767|Reorganize String|[Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})|Medium| O(n log n)| O(log n) |❤️|49.9%|
+|0853|Car Fleet|[Go]({{< relref "/ChapterFour/0853.Car-Fleet.md" >}})|Medium| O(n log n)| O(log n) ||43.6%|
+|0922|Sort Array By Parity II|[Go]({{< relref "/ChapterFour/0922.Sort-Array-By-Parity-II.md" >}})|Easy| O(n)| O(1) ||70.2%|
+|0969|Pancake Sorting|[Go]({{< relref "/ChapterFour/0969.Pancake-Sorting.md" >}})|Medium| O(n log n)| O(log n) |❤️|68.5%|
+|0973|K Closest Points to Origin|[Go]({{< relref "/ChapterFour/0973.K-Closest-Points-to-Origin.md" >}})|Medium| O(n log n)| O(log n) ||64.5%|
+|0976|Largest Perimeter Triangle|[Go]({{< relref "/ChapterFour/0976.Largest-Perimeter-Triangle.md" >}})|Easy| O(n log n)| O(log n) ||58.5%|
+|1030|Matrix Cells in Distance Order|[Go]({{< relref "/ChapterFour/1030.Matrix-Cells-in-Distance-Order.md" >}})|Easy| O(n^2)| O(1) ||66.9%|
+|1054|Distant Barcodes|[Go]({{< relref "/ChapterFour/1054.Distant-Barcodes.md" >}})|Medium| O(n log n)| O(log n) |❤️|44.2%|
+|1122|Relative Sort Array|[Go]({{< relref "/ChapterFour/1122.Relative-Sort-Array.md" >}})|Easy||||67.7%|
+|1235|Maximum Profit in Job Scheduling|[Go]({{< relref "/ChapterFour/1235.Maximum-Profit-in-Job-Scheduling.md" >}})|Hard||||46.9%|
+|1305|All Elements in Two Binary Search Trees|[Go]({{< relref "/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md" >}})|Medium||||77.8%|
+|1640|Check Array Formation Through Concatenation|[Go]({{< relref "/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md" >}})|Easy||||62.1%|
+|1647|Minimum Deletions to Make Character Frequencies Unique|[Go]({{< relref "/ChapterFour/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique.md" >}})|Medium||||53.8%|
+|1648|Sell Diminishing-Valued Colored Balls|[Go]({{< relref "/ChapterFour/1648.Sell-Diminishing-Valued-Colored-Balls.md" >}})|Medium||||30.9%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Stack.md b/website/content/ChapterTwo/Stack.md
index cae1b29c..72e845a8 100644
--- a/website/content/ChapterTwo/Stack.md
+++ b/website/content/ChapterTwo/Stack.md
@@ -12,43 +12,54 @@ type: docs
- 利用栈进行编码问题。第 394 题,第 682 题,第 856 题,第 880 题。
- **单调栈**。**利用栈维护一个单调递增或者递减的下标数组**。第 84 题,第 456 题,第 496 题,第 503 题,第 739 题,第 901 题,第 907 题,第 1019 题。
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|20. Valid Parentheses | [Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})| Easy | O(log n)| O(1)||
-|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
-|71. Simplify Path | [Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})| Medium | O(n)| O(n)|❤️|
-|84. Largest Rectangle in Histogram | [Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})| Medium | O(n)| O(n)|❤️|
-|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
-|144. Binary Tree Preorder Traversal | [Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|145. Binary Tree Postorder Traversal | [Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})| Hard | O(n)| O(1)||
-|150. Evaluate Reverse Polish Notation | [Go]({{< relref "/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md" >}})| Medium | O(n)| O(1)||
-|155. Min Stack | [Go]({{< relref "/ChapterFour/0155.Min-Stack.md" >}})| Easy | O(n)| O(n)||
-|173. Binary Search Tree Iterator | [Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})| Medium | O(n)| O(1)||
-|224. Basic Calculator | [Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})| Hard | O(n)| O(n)||
-|225. Implement Stack using Queues | [Go]({{< relref "/ChapterFour/0225.Implement-Stack-using-Queues.md" >}})| Easy | O(n)| O(n)||
-|232. Implement Queue using Stacks | [Go]({{< relref "/ChapterFour/0232.Implement-Queue-using-Stacks.md" >}})| Easy | O(n)| O(n)||
-|331. Verify Preorder Serialization of a Binary Tree | [Go]({{< relref "/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md" >}})| Medium | O(n)| O(1)||
-|394. Decode String | [Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})| Medium | O(n)| O(n)||
-|402. Remove K Digits | [Go]({{< relref "/ChapterFour/0402.Remove-K-Digits.md" >}})| Medium | O(n)| O(1)||
-|456. 132 Pattern | [Go]({{< relref "/ChapterFour/0456.132-Pattern.md" >}})| Medium | O(n)| O(n)||
-|496. Next Greater Element I | [Go]({{< relref "/ChapterFour/0496.Next-Greater-Element-I.md" >}})| Easy | O(n)| O(n)||
-|503. Next Greater Element II | [Go]({{< relref "/ChapterFour/0503.Next-Greater-Element-II.md" >}})| Medium | O(n)| O(n)||
-|636. Exclusive Time of Functions | [Go]({{< relref "/ChapterFour/0636.Exclusive-Time-of-Functions.md" >}})| Medium | O(n)| O(n)||
-|682. Baseball Game | [Go]({{< relref "/ChapterFour/0682.Baseball-Game.md" >}})| Easy | O(n)| O(n)||
-|726. Number of Atoms | [Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})| Hard | O(n)| O(n) |❤️|
-|735. Asteroid Collision | [Go]({{< relref "/ChapterFour/0735.Asteroid-Collision.md" >}})| Medium | O(n)| O(n) ||
-|739. Daily Temperatures | [Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})| Medium | O(n)| O(n) ||
-|844. Backspace String Compare | [Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})| Easy | O(n)| O(n) ||
-|856. Score of Parentheses | [Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})| Medium | O(n)| O(n)||
-|880. Decoded String at Index | [Go]({{< relref "/ChapterFour/0880.Decoded-String-at-Index.md" >}})| Medium | O(n)| O(n)||
-|895. Maximum Frequency Stack | [Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})| Hard | O(n)| O(n) ||
-|901. Online Stock Span | [Go]({{< relref "/ChapterFour/0901.Online-Stock-Span.md" >}})| Medium | O(n)| O(n) ||
-|907. Sum of Subarray Minimums | [Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})| Medium | O(n)| O(n)|❤️|
-|921. Minimum Add to Make Parentheses Valid | [Go]({{< relref "/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md" >}})| Medium | O(n)| O(n)||
-|946. Validate Stack Sequences | [Go]({{< relref "/ChapterFour/0946.Validate-Stack-Sequences.md" >}})| Medium | O(n)| O(n)||
-|1003. Check If Word Is Valid After Substitutions | [Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})| Medium | O(n)| O(1)||
-|1019. Next Greater Node In Linked List | [Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|1021. Remove Outermost Parentheses | [Go]({{< relref "/ChapterFour/1021.Remove-Outermost-Parentheses.md" >}})| Medium | O(n)| O(1)||
-|1047. Remove All Adjacent Duplicates In String | [Go]({{< relref "/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------|-----------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0020|Valid Parentheses|[Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})|Easy| O(log n)| O(1)||39.5%|
+|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|50.8%|
+|0071|Simplify Path|[Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})|Medium| O(n)| O(n)|❤️|33.6%|
+|0084|Largest Rectangle in Histogram|[Go]({{< relref "/ChapterFour/0084.Largest-Rectangle-in-Histogram.md" >}})|Hard| O(n)| O(n)|❤️|36.8%|
+|0094|Binary Tree Inorder Traversal|[Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})|Medium| O(n)| O(1)||65.4%|
+|0103|Binary Tree Zigzag Level Order Traversal|[Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})|Medium| O(n)| O(n)||49.8%|
+|0144|Binary Tree Preorder Traversal|[Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.1%|
+|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.1%|
+|0150|Evaluate Reverse Polish Notation|[Go]({{< relref "/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md" >}})|Medium| O(n)| O(1)||37.6%|
+|0155|Min Stack|[Go]({{< relref "/ChapterFour/0155.Min-Stack.md" >}})|Easy| O(n)| O(n)||46.0%|
+|0173|Binary Search Tree Iterator|[Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})|Medium| O(n)| O(1)||59.6%|
+|0224|Basic Calculator|[Go]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})|Hard| O(n)| O(n)||38.0%|
+|0225|Implement Stack using Queues|[Go]({{< relref "/ChapterFour/0225.Implement-Stack-using-Queues.md" >}})|Easy| O(n)| O(n)||46.9%|
+|0232|Implement Queue using Stacks|[Go]({{< relref "/ChapterFour/0232.Implement-Queue-using-Stacks.md" >}})|Easy| O(n)| O(n)||51.6%|
+|0331|Verify Preorder Serialization of a Binary Tree|[Go]({{< relref "/ChapterFour/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md" >}})|Medium| O(n)| O(1)||40.9%|
+|0385|Mini Parser|[Go]({{< relref "/ChapterFour/0385.Mini-Parser.md" >}})|Medium||||34.3%|
+|0394|Decode String|[Go]({{< relref "/ChapterFour/0394.Decode-String.md" >}})|Medium| O(n)| O(n)||52.4%|
+|0402|Remove K Digits|[Go]({{< relref "/ChapterFour/0402.Remove-K-Digits.md" >}})|Medium| O(n)| O(1)||28.6%|
+|0456|132 Pattern|[Go]({{< relref "/ChapterFour/0456.132-Pattern.md" >}})|Medium| O(n)| O(n)||30.6%|
+|0496|Next Greater Element I|[Go]({{< relref "/ChapterFour/0496.Next-Greater-Element-I.md" >}})|Easy| O(n)| O(n)||65.2%|
+|0503|Next Greater Element II|[Go]({{< relref "/ChapterFour/0503.Next-Greater-Element-II.md" >}})|Medium| O(n)| O(n)||58.2%|
+|0636|Exclusive Time of Functions|[Go]({{< relref "/ChapterFour/0636.Exclusive-Time-of-Functions.md" >}})|Medium| O(n)| O(n)||54.0%|
+|0682|Baseball Game|[Go]({{< relref "/ChapterFour/0682.Baseball-Game.md" >}})|Easy| O(n)| O(n)||66.1%|
+|0726|Number of Atoms|[Go]({{< relref "/ChapterFour/0726.Number-of-Atoms.md" >}})|Hard| O(n)| O(n) |❤️|51.0%|
+|0735|Asteroid Collision|[Go]({{< relref "/ChapterFour/0735.Asteroid-Collision.md" >}})|Medium| O(n)| O(n) ||43.2%|
+|0739|Daily Temperatures|[Go]({{< relref "/ChapterFour/0739.Daily-Temperatures.md" >}})|Medium| O(n)| O(n) ||64.3%|
+|0844|Backspace String Compare|[Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})|Easy| O(n)| O(n) ||46.8%|
+|0856|Score of Parentheses|[Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})|Medium| O(n)| O(n)||62.2%|
+|0880|Decoded String at Index|[Go]({{< relref "/ChapterFour/0880.Decoded-String-at-Index.md" >}})|Medium| O(n)| O(n)||28.3%|
+|0895|Maximum Frequency Stack|[Go]({{< relref "/ChapterFour/0895.Maximum-Frequency-Stack.md" >}})|Hard| O(n)| O(n) ||62.2%|
+|0901|Online Stock Span|[Go]({{< relref "/ChapterFour/0901.Online-Stock-Span.md" >}})|Medium| O(n)| O(n) ||61.2%|
+|0907|Sum of Subarray Minimums|[Go]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})|Medium| O(n)| O(n)|❤️|33.2%|
+|0921|Minimum Add to Make Parentheses Valid|[Go]({{< relref "/ChapterFour/0921.Minimum-Add-to-Make-Parentheses-Valid.md" >}})|Medium| O(n)| O(n)||74.6%|
+|0946|Validate Stack Sequences|[Go]({{< relref "/ChapterFour/0946.Validate-Stack-Sequences.md" >}})|Medium| O(n)| O(n)||63.4%|
+|1003|Check If Word Is Valid After Substitutions|[Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})|Medium| O(n)| O(1)||56.1%|
+|1019|Next Greater Node In Linked List|[Go]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})|Medium| O(n)| O(1)||58.2%|
+|1021|Remove Outermost Parentheses|[Go]({{< relref "/ChapterFour/1021.Remove-Outermost-Parentheses.md" >}})|Easy| O(n)| O(1)||78.7%|
+|1047|Remove All Adjacent Duplicates In String|[Go]({{< relref "/ChapterFour/1047.Remove-All-Adjacent-Duplicates-In-String.md" >}})|Easy| O(n)| O(1)||70.3%|
+|1673|Find the Most Competitive Subsequence|[Go]({{< relref "/ChapterFour/1673.Find-the-Most-Competitive-Subsequence.md" >}})|Medium||||38.3%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/String.md b/website/content/ChapterTwo/String.md
index 1ea29de5..39a6d755 100644
--- a/website/content/ChapterTwo/String.md
+++ b/website/content/ChapterTwo/String.md
@@ -5,26 +5,57 @@ type: docs
# String
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|17. Letter Combinations of a Phone Number | [Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})| Medium | O(log n)| O(1)||
-|20. Valid Parentheses | [Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})| Easy | O(log n)| O(1)||
-|22. Generate Parentheses | [Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})| Medium | O(log n)| O(1)||
-|28. Implement strStr() | [Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})| Easy | O(n)| O(1)||
-|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
-|49. Group Anagrams | [Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})| Medium | O(n log n)| O(n)||
-|71. Simplify Path | [Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})| Medium | O(n)| O(n)||
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|91. Decode Ways | [Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})| Medium | O(n)| O(n)||
-|93. Restore IP Addresses | [Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})| Medium | O(n)| O(n)|❤️|
-|125. Valid Palindrome | [Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})| Easy | O(n)| O(1)||
-|126. Word Ladder II | [Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})| Hard | O(n)| O(n^2)|❤️|
-|344. Reverse String | [Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})| Easy | O(n)| O(1)||
-|345. Reverse Vowels of a String | [Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})| Easy | O(n)| O(1)||
-|767. Reorganize String | [Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})| Medium | O(n log n)| O(log n) |❤️|
-|842. Split Array into Fibonacci Sequence | [Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|856. Score of Parentheses | [Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})| Medium | O(n)| O(n)||
-|925. Long Pressed Name | [Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})| Easy | O(n)| O(1)||
-|1003. Check If Word Is Valid After Substitutions | [Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})| Medium | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0003|Longest Substring Without Repeating Characters|[Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})|Medium| O(n)| O(1)|❤️|31.3%|
+|0013|Roman to Integer|[Go]({{< relref "/ChapterFour/0013.Roman-to-Integer.md" >}})|Easy||||56.4%|
+|0017|Letter Combinations of a Phone Number|[Go]({{< relref "/ChapterFour/0017.Letter-Combinations-of-a-Phone-Number.md" >}})|Medium| O(log n)| O(1)||48.7%|
+|0020|Valid Parentheses|[Go]({{< relref "/ChapterFour/0020.Valid-Parentheses.md" >}})|Easy| O(log n)| O(1)||39.5%|
+|0022|Generate Parentheses|[Go]({{< relref "/ChapterFour/0022.Generate-Parentheses.md" >}})|Medium| O(log n)| O(1)||64.8%|
+|0028|Implement strStr()|[Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})|Easy| O(n)| O(1)||35.1%|
+|0030|Substring with Concatenation of All Words|[Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})|Hard| O(n)| O(n)|❤️|26.0%|
+|0049|Group Anagrams|[Go]({{< relref "/ChapterFour/0049.Group-Anagrams.md" >}})|Medium| O(n log n)| O(n)||58.9%|
+|0067|Add Binary|[Go]({{< relref "/ChapterFour/0067.Add-Binary.md" >}})|Easy||||46.6%|
+|0071|Simplify Path|[Go]({{< relref "/ChapterFour/0071.Simplify-Path.md" >}})|Medium| O(n)| O(n)||33.6%|
+|0076|Minimum Window Substring|[Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})|Hard| O(n)| O(n)|❤️|35.7%|
+|0091|Decode Ways|[Go]({{< relref "/ChapterFour/0091.Decode-Ways.md" >}})|Medium| O(n)| O(n)||26.2%|
+|0093|Restore IP Addresses|[Go]({{< relref "/ChapterFour/0093.Restore-IP-Addresses.md" >}})|Medium| O(n)| O(n)|❤️|37.2%|
+|0125|Valid Palindrome|[Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})|Easy| O(n)| O(1)||37.9%|
+|0126|Word Ladder II|[Go]({{< relref "/ChapterFour/0126.Word-Ladder-II.md" >}})|Hard| O(n)| O(n^2)|❤️|23.4%|
+|0151|Reverse Words in a String|[Go]({{< relref "/ChapterFour/0151.Reverse-Words-in-a-String.md" >}})|Medium||||23.3%|
+|0344|Reverse String|[Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})|Easy| O(n)| O(1)||70.0%|
+|0345|Reverse Vowels of a String|[Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})|Easy| O(n)| O(1)||44.9%|
+|0385|Mini Parser|[Go]({{< relref "/ChapterFour/0385.Mini-Parser.md" >}})|Medium||||34.3%|
+|0387|First Unique Character in a String|[Go]({{< relref "/ChapterFour/0387.First-Unique-Character-in-a-String.md" >}})|Easy||||53.7%|
+|0537|Complex Number Multiplication|[Go]({{< relref "/ChapterFour/0537.Complex-Number-Multiplication.md" >}})|Medium||||68.3%|
+|0541|Reverse String II|[Go]({{< relref "/ChapterFour/0541.Reverse-String-II.md" >}})|Easy||||49.0%|
+|0557|Reverse Words in a String III|[Go]({{< relref "/ChapterFour/0557.Reverse-Words-in-a-String-III.md" >}})|Easy||||71.6%|
+|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||53.9%|
+|0767|Reorganize String|[Go]({{< relref "/ChapterFour/0767.Reorganize-String.md" >}})|Medium| O(n log n)| O(log n) |❤️|49.9%|
+|0819|Most Common Word|[Go]({{< relref "/ChapterFour/0819.Most-Common-Word.md" >}})|Easy||||45.4%|
+|0842|Split Array into Fibonacci Sequence|[Go]({{< relref "/ChapterFour/0842.Split-Array-into-Fibonacci-Sequence.md" >}})|Medium| O(n^2)| O(1)|❤️|36.7%|
+|0856|Score of Parentheses|[Go]({{< relref "/ChapterFour/0856.Score-of-Parentheses.md" >}})|Medium| O(n)| O(n)||62.2%|
+|0925|Long Pressed Name|[Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})|Easy| O(n)| O(1)||38.4%|
+|1003|Check If Word Is Valid After Substitutions|[Go]({{< relref "/ChapterFour/1003.Check-If-Word-Is-Valid-After-Substitutions.md" >}})|Medium| O(n)| O(1)||56.1%|
+|1108|Defanging an IP Address|[Go]({{< relref "/ChapterFour/1108.Defanging-an-IP-Address.md" >}})|Easy||||88.5%|
+|1170|Compare Strings by Frequency of the Smallest Character|[Go]({{< relref "/ChapterFour/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character.md" >}})|Easy||||59.5%|
+|1189|Maximum Number of Balloons|[Go]({{< relref "/ChapterFour/1189.Maximum-Number-of-Balloons.md" >}})|Easy||||61.8%|
+|1221|Split a String in Balanced Strings|[Go]({{< relref "/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md" >}})|Easy||||84.0%|
+|1234|Replace the Substring for Balanced String|[Go]({{< relref "/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md" >}})|Medium||||34.4%|
+|1455|Check If a Word Occurs As a Prefix of Any Word in a Sentence|[Go]({{< relref "/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md" >}})|Easy||||64.7%|
+|1573|Number of Ways to Split a String|[Go]({{< relref "/ChapterFour/1573.Number-of-Ways-to-Split-a-String.md" >}})|Medium||||30.9%|
+|1653|Minimum Deletions to Make String Balanced|[Go]({{< relref "/ChapterFour/1653.Minimum-Deletions-to-Make-String-Balanced.md" >}})|Medium||||49.9%|
+|1662|Check If Two String Arrays are Equivalent|[Go]({{< relref "/ChapterFour/1662.Check-If-Two-String-Arrays-are-Equivalent.md" >}})|Easy||||83.6%|
+|1668|Maximum Repeating Substring|[Go]({{< relref "/ChapterFour/1668.Maximum-Repeating-Substring.md" >}})|Easy||||38.8%|
+|1678|Goal Parser Interpretation|[Go]({{< relref "/ChapterFour/1678.Goal-Parser-Interpretation.md" >}})|Easy||||86.6%|
+|1684|Count the Number of Consistent Strings|[Go]({{< relref "/ChapterFour/1684.Count-the-Number-of-Consistent-Strings.md" >}})|Easy||||84.1%|
+|1694|Reformat Phone Number|[Go]({{< relref "/ChapterFour/1694.Reformat-Phone-Number.md" >}})|Easy||||67.0%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Tree.md b/website/content/ChapterTwo/Tree.md
index d8a1267e..0f1f1bfb 100644
--- a/website/content/ChapterTwo/Tree.md
+++ b/website/content/ChapterTwo/Tree.md
@@ -5,39 +5,72 @@ type: docs
# Tree
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|94. Binary Tree Inorder Traversal | [Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|96. Unique Binary Search Trees | [Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})| Medium | O(n^2)| O(n)||
-|98. Validate Binary Search Tree | [Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})| Medium | O(n)| O(1)||
-|99. Recover Binary Search Tree | [Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})| Hard | O(n)| O(1)||
-|100. Same Tree | [Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})| Easy | O(n)| O(1)||
-|101. Symmetric Tree | [Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})| Easy | O(n)| O(1)||
-|102. Binary Tree Level Order Traversal | [Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})| Medium | O(n)| O(1)||
-|103. Binary Tree Zigzag Level Order Traversal | [Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})| Medium | O(n)| O(n)||
-|104. Maximum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|107. Binary Tree Level Order Traversal II | [Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})| Easy | O(n)| O(1)||
-|108. Convert Sorted Array to Binary Search Tree | [Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
-|110. Balanced Binary Tree | [Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|111. Minimum Depth of Binary Tree | [Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|112. Path Sum | [Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})| Easy | O(n)| O(1)||
-|113. Path Sum II | [Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})| Medium | O(n)| O(1)||
-|114. Flatten Binary Tree to Linked List | [Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})| Medium | O(n)| O(1)||
-|124. Binary Tree Maximum Path Sum | [Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})| Hard | O(n)| O(1)||
-|129. Sum Root to Leaf Numbers | [Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})| Medium | O(n)| O(1)||
-|144. Binary Tree Preorder Traversal | [Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})| Medium | O(n)| O(1)||
-|145. Binary Tree Postorder Traversal | [Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})| Hard | O(n)| O(1)||
-|173. Binary Search Tree Iterator | [Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})| Medium | O(n)| O(1)||
-|199. Binary Tree Right Side View | [Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})| Medium | O(n)| O(1)||
-|222. Count Complete Tree Nodes | [Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})| Medium | O(n)| O(1)||
-|226. Invert Binary Tree | [Go]({{< relref "/ChapterFour/0226.Invert-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|230. Kth Smallest Element in a BST | [Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})| Medium | O(n)| O(1)||
-|235. Lowest Common Ancestor of a Binary Search Tree | [Go]({{< relref "/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md" >}})| Easy | O(n)| O(1)||
-|236. Lowest Common Ancestor of a Binary Tree | [Go]({{< relref "/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md" >}})| Medium | O(n)| O(1)||
-|257. Binary Tree Paths | [Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})| Easy | O(n)| O(1)||
-|404. Sum of Left Leaves | [Go]({{< relref "/ChapterFour/0404.Sum-of-Left-Leaves.md" >}})| Easy | O(n)| O(1)||
-|437. Path Sum III | [Go]({{< relref "/ChapterFour/0437.Path-Sum-III.md" >}})| Easy | O(n)| O(1)||
-|515. Find Largest Value in Each Tree Row | [Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})| Medium | O(n)| O(n)||
-|637. Average of Levels in Binary Tree | [Go]({{< relref "/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md" >}})| Easy | O(n)| O(n)||
-|993. Cousins in Binary Tree | [Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})| Easy | O(n)| O(1)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0094|Binary Tree Inorder Traversal|[Go]({{< relref "/ChapterFour/0094.Binary-Tree-Inorder-Traversal.md" >}})|Medium| O(n)| O(1)||65.4%|
+|0095|Unique Binary Search Trees II|[Go]({{< relref "/ChapterFour/0095.Unique-Binary-Search-Trees-II.md" >}})|Medium||||42.1%|
+|0096|Unique Binary Search Trees|[Go]({{< relref "/ChapterFour/0096.Unique-Binary-Search-Trees.md" >}})|Medium| O(n^2)| O(n)||54.2%|
+|0098|Validate Binary Search Tree|[Go]({{< relref "/ChapterFour/0098.Validate-Binary-Search-Tree.md" >}})|Medium| O(n)| O(1)||28.6%|
+|0099|Recover Binary Search Tree|[Go]({{< relref "/ChapterFour/0099.Recover-Binary-Search-Tree.md" >}})|Hard| O(n)| O(1)||42.2%|
+|0100|Same Tree|[Go]({{< relref "/ChapterFour/0100.Same-Tree.md" >}})|Easy| O(n)| O(1)||54.0%|
+|0101|Symmetric Tree|[Go]({{< relref "/ChapterFour/0101.Symmetric-Tree.md" >}})|Easy| O(n)| O(1)||47.9%|
+|0102|Binary Tree Level Order Traversal|[Go]({{< relref "/ChapterFour/0102.Binary-Tree-Level-Order-Traversal.md" >}})|Medium| O(n)| O(1)||56.2%|
+|0103|Binary Tree Zigzag Level Order Traversal|[Go]({{< relref "/ChapterFour/0103.Binary-Tree-Zigzag-Level-Order-Traversal.md" >}})|Medium| O(n)| O(n)||49.8%|
+|0104|Maximum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0104.Maximum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||67.7%|
+|0105|Construct Binary Tree from Preorder and Inorder Traversal|[Go]({{< relref "/ChapterFour/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md" >}})|Medium||||51.3%|
+|0106|Construct Binary Tree from Inorder and Postorder Traversal|[Go]({{< relref "/ChapterFour/0106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.md" >}})|Medium||||49.2%|
+|0107|Binary Tree Level Order Traversal II|[Go]({{< relref "/ChapterFour/0107.Binary-Tree-Level-Order-Traversal-II.md" >}})|Easy| O(n)| O(1)||54.9%|
+|0108|Convert Sorted Array to Binary Search Tree|[Go]({{< relref "/ChapterFour/0108.Convert-Sorted-Array-to-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||60.0%|
+|0110|Balanced Binary Tree|[Go]({{< relref "/ChapterFour/0110.Balanced-Binary-Tree.md" >}})|Easy| O(n)| O(1)||44.6%|
+|0111|Minimum Depth of Binary Tree|[Go]({{< relref "/ChapterFour/0111.Minimum-Depth-of-Binary-Tree.md" >}})|Easy| O(n)| O(1)||39.2%|
+|0112|Path Sum|[Go]({{< relref "/ChapterFour/0112.Path-Sum.md" >}})|Easy| O(n)| O(1)||42.1%|
+|0113|Path Sum II|[Go]({{< relref "/ChapterFour/0113.Path-Sum-II.md" >}})|Medium| O(n)| O(1)||48.7%|
+|0114|Flatten Binary Tree to Linked List|[Go]({{< relref "/ChapterFour/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})|Medium| O(n)| O(1)||51.5%|
+|0124|Binary Tree Maximum Path Sum|[Go]({{< relref "/ChapterFour/0124.Binary-Tree-Maximum-Path-Sum.md" >}})|Hard| O(n)| O(1)||35.3%|
+|0129|Sum Root to Leaf Numbers|[Go]({{< relref "/ChapterFour/0129.Sum-Root-to-Leaf-Numbers.md" >}})|Medium| O(n)| O(1)||50.6%|
+|0144|Binary Tree Preorder Traversal|[Go]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.1%|
+|0145|Binary Tree Postorder Traversal|[Go]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})|Medium| O(n)| O(1)||57.1%|
+|0173|Binary Search Tree Iterator|[Go]({{< relref "/ChapterFour/0173.Binary-Search-Tree-Iterator.md" >}})|Medium| O(n)| O(1)||59.6%|
+|0199|Binary Tree Right Side View|[Go]({{< relref "/ChapterFour/0199.Binary-Tree-Right-Side-View.md" >}})|Medium| O(n)| O(1)||55.7%|
+|0222|Count Complete Tree Nodes|[Go]({{< relref "/ChapterFour/0222.Count-Complete-Tree-Nodes.md" >}})|Medium| O(n)| O(1)||48.8%|
+|0226|Invert Binary Tree|[Go]({{< relref "/ChapterFour/0226.Invert-Binary-Tree.md" >}})|Easy| O(n)| O(1)||66.6%|
+|0230|Kth Smallest Element in a BST|[Go]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})|Medium| O(n)| O(1)||62.2%|
+|0235|Lowest Common Ancestor of a Binary Search Tree|[Go]({{< relref "/ChapterFour/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree.md" >}})|Easy| O(n)| O(1)||51.4%|
+|0236|Lowest Common Ancestor of a Binary Tree|[Go]({{< relref "/ChapterFour/0236.Lowest-Common-Ancestor-of-a-Binary-Tree.md" >}})|Medium| O(n)| O(1)||48.2%|
+|0257|Binary Tree Paths|[Go]({{< relref "/ChapterFour/0257.Binary-Tree-Paths.md" >}})|Easy| O(n)| O(1)||53.2%|
+|0337|House Robber III|[Go]({{< relref "/ChapterFour/0337.House-Robber-III.md" >}})|Medium||||51.7%|
+|0404|Sum of Left Leaves|[Go]({{< relref "/ChapterFour/0404.Sum-of-Left-Leaves.md" >}})|Easy| O(n)| O(1)||52.2%|
+|0437|Path Sum III|[Go]({{< relref "/ChapterFour/0437.Path-Sum-III.md" >}})|Medium| O(n)| O(1)||48.0%|
+|0508|Most Frequent Subtree Sum|[Go]({{< relref "/ChapterFour/0508.Most-Frequent-Subtree-Sum.md" >}})|Medium||||58.9%|
+|0513|Find Bottom Left Tree Value|[Go]({{< relref "/ChapterFour/0513.Find-Bottom-Left-Tree-Value.md" >}})|Medium||||62.3%|
+|0515|Find Largest Value in Each Tree Row|[Go]({{< relref "/ChapterFour/0515.Find-Largest-Value-in-Each-Tree-Row.md" >}})|Medium| O(n)| O(n)||62.0%|
+|0563|Binary Tree Tilt|[Go]({{< relref "/ChapterFour/0563.Binary-Tree-Tilt.md" >}})|Easy||||52.7%|
+|0572|Subtree of Another Tree|[Go]({{< relref "/ChapterFour/0572.Subtree-of-Another-Tree.md" >}})|Easy||||44.4%|
+|0637|Average of Levels in Binary Tree|[Go]({{< relref "/ChapterFour/0637.Average-of-Levels-in-Binary-Tree.md" >}})|Easy| O(n)| O(n)||64.5%|
+|0653|Two Sum IV - Input is a BST|[Go]({{< relref "/ChapterFour/0653.Two-Sum-IV---Input-is-a-BST.md" >}})|Easy||||56.1%|
+|0662|Maximum Width of Binary Tree|[Go]({{< relref "/ChapterFour/0662.Maximum-Width-of-Binary-Tree.md" >}})|Medium||||40.0%|
+|0684|Redundant Connection|[Go]({{< relref "/ChapterFour/0684.Redundant-Connection.md" >}})|Medium||||58.8%|
+|0685|Redundant Connection II|[Go]({{< relref "/ChapterFour/0685.Redundant-Connection-II.md" >}})|Hard||||32.9%|
+|0834|Sum of Distances in Tree|[Go]({{< relref "/ChapterFour/0834.Sum-of-Distances-in-Tree.md" >}})|Hard||||45.5%|
+|0863|All Nodes Distance K in Binary Tree|[Go]({{< relref "/ChapterFour/0863.All-Nodes-Distance-K-in-Binary-Tree.md" >}})|Medium||||57.5%|
+|0872|Leaf-Similar Trees|[Go]({{< relref "/ChapterFour/0872.Leaf-Similar-Trees.md" >}})|Easy||||64.5%|
+|0897|Increasing Order Search Tree|[Go]({{< relref "/ChapterFour/0897.Increasing-Order-Search-Tree.md" >}})|Easy||||74.3%|
+|0968|Binary Tree Cameras|[Go]({{< relref "/ChapterFour/0968.Binary-Tree-Cameras.md" >}})|Hard||||38.5%|
+|0979|Distribute Coins in Binary Tree|[Go]({{< relref "/ChapterFour/0979.Distribute-Coins-in-Binary-Tree.md" >}})|Medium||||69.5%|
+|0993|Cousins in Binary Tree|[Go]({{< relref "/ChapterFour/0993.Cousins-in-Binary-Tree.md" >}})|Easy| O(n)| O(1)||52.2%|
+|1026|Maximum Difference Between Node and Ancestor|[Go]({{< relref "/ChapterFour/1026.Maximum-Difference-Between-Node-and-Ancestor.md" >}})|Medium||||69.2%|
+|1028|Recover a Tree From Preorder Traversal|[Go]({{< relref "/ChapterFour/1028.Recover-a-Tree-From-Preorder-Traversal.md" >}})|Hard||||70.7%|
+|1110|Delete Nodes And Return Forest|[Go]({{< relref "/ChapterFour/1110.Delete-Nodes-And-Return-Forest.md" >}})|Medium||||67.6%|
+|1123|Lowest Common Ancestor of Deepest Leaves|[Go]({{< relref "/ChapterFour/1123.Lowest-Common-Ancestor-of-Deepest-Leaves.md" >}})|Medium||||67.9%|
+|1145|Binary Tree Coloring Game|[Go]({{< relref "/ChapterFour/1145.Binary-Tree-Coloring-Game.md" >}})|Medium||||51.4%|
+|1302|Deepest Leaves Sum|[Go]({{< relref "/ChapterFour/1302.Deepest-Leaves-Sum.md" >}})|Medium||||84.1%|
+|1305|All Elements in Two Binary Search Trees|[Go]({{< relref "/ChapterFour/1305.All-Elements-in-Two-Binary-Search-Trees.md" >}})|Medium||||77.8%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Two_Pointers.md b/website/content/ChapterTwo/Two_Pointers.md
index ece49e88..6b4a797c 100644
--- a/website/content/ChapterTwo/Two_Pointers.md
+++ b/website/content/ChapterTwo/Two_Pointers.md
@@ -28,56 +28,70 @@ type: docs
- 替换字母以后,相同字母能出现连续最长的长度。第 424 题。
- SUM 问题集。第 1 题,第 15 题,第 16 题,第 18 题,第 167 题,第 923 题,第 1074 题。
-| Title | Solution | Difficulty | Time | Space |收藏|
-| ----- | :--------: | :----------: | :----: | :-----: | :-----: |
-|3. Longest Substring Without Repeating Characters | [Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})| Medium | O(n)| O(1)|❤️|
-|11. Container With Most Water | [Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})| Medium | O(n)| O(1)||
-|15. 3Sum | [Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})| Medium | O(n^2)| O(n)|❤️|
-|16. 3Sum Closest | [Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})| Medium | O(n^2)| O(1)|❤️|
-|18. 4Sum | [Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})| Medium | O(n^3)| O(n^2)|❤️|
-|19. Remove Nth Node From End of List | [Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})| Medium | O(n)| O(1)||
-|26. Remove Duplicates from Sorted Array | [Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|27. Remove Element | [Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})| Easy | O(n)| O(1)||
-|28. Implement strStr() | [Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})| Easy | O(n)| O(1)||
-|30. Substring with Concatenation of All Words | [Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})| Hard | O(n)| O(n)|❤️|
-|42. Trapping Rain Water | [Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})| Hard | O(n)| O(1)|❤️|
-|61. Rotate List | [Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})| Medium | O(n)| O(1)||
-|75. Sort Colors | [Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})| Medium| O(n)| O(1)|❤️|
-|76. Minimum Window Substring | [Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})| Hard | O(n)| O(n)|❤️|
-|80. Remove Duplicates from Sorted Array II | [Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})| Medium | O(n)| O(1||
-|86. Partition List | [Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})| Medium | O(n)| O(1)|❤️|
-|88. Merge Sorted Array | [Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})| Easy | O(n)| O(1)|❤️|
-|125. Valid Palindrome | [Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})| Easy | O(n)| O(1)||
-|141. Linked List Cycle | [Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})| Easy | O(n)| O(1)|❤️|
-|142. Linked List Cycle II | [Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})| Medium | O(n)| O(1)|❤️|
-|167. Two Sum II - Input array is sorted | [Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})| Easy | O(n)| O(1)||
-|209. Minimum Size Subarray Sum | [Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})| Medium | O(n)| O(1)||
-|234. Palindrome Linked List | [Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})| Easy | O(n)| O(1)||
-|283. Move Zeroes | [Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})| Easy | O(n)| O(1)||
-|287. Find the Duplicate Number | [Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})| Easy | O(n)| O(1)|❤️|
-|344. Reverse String | [Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})| Easy | O(n)| O(1)||
-|345. Reverse Vowels of a String | [Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})| Easy | O(n)| O(1)||
-|349. Intersection of Two Arrays | [Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})| Easy | O(n)| O(n) ||
-|350. Intersection of Two Arrays II | [Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})| Easy | O(n)| O(n) ||
-|424. Longest Repeating Character Replacement | [Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})| Medium | O(n)| O(1) ||
-|524. Longest Word in Dictionary through Deleting | [Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})| Medium | O(n)| O(1) ||
-|532. K-diff Pairs in an Array | [Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})| Easy | O(n)| O(n)||
-|567. Permutation in String | [Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})| Medium | O(n)| O(1)|❤️|
-|713. Subarray Product Less Than K | [Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})| Medium | O(n)| O(1)||
-|763. Partition Labels | [Go]({{< relref "/ChapterFour/0763.Partition-Labels.md" >}})| Medium | O(n)| O(1)|❤️|
-|826. Most Profit Assigning Work | [Go]({{< relref "/ChapterFour/0826.Most-Profit-Assigning-Work.md" >}})| Medium | O(n log n)| O(n)||
-|828. Unique Letter String | [Go]({{< relref "/ChapterFour/0828.COPYRIGHT-PROBLEM-XXX.md" >}})| Hard | O(n)| O(1)|❤️|
-|838. Push Dominoes | [Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})| Medium | O(n)| O(n)||
-|844. Backspace String Compare | [Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})| Easy | O(n)| O(n) ||
-|845. Longest Mountain in Array | [Go]({{< relref "/ChapterFour/0845.Longest-Mountain-in-Array.md" >}})| Medium | O(n)| O(1) ||
-|881. Boats to Save People | [Go]({{< relref "/ChapterFour/0881.Boats-to-Save-People.md" >}})| Medium | O(n log n)| O(1) ||
-|904. Fruit Into Baskets | [Go]({{< relref "/ChapterFour/0904.Fruit-Into-Baskets.md" >}})| Medium | O(n log n)| O(1) ||
-|923. 3Sum With Multiplicity | [Go]({{< relref "/ChapterFour/0923.3Sum-With-Multiplicity.md" >}})| Medium | O(n^2)| O(n) ||
-|925. Long Pressed Name | [Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})| Easy | O(n)| O(1)||
-|930. Binary Subarrays With Sum | [Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})| Medium | O(n)| O(n) |❤️|
-|977. Squares of a Sorted Array | [Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})| Easy | O(n)| O(1)||
-|986. Interval List Intersections | [Go]({{< relref "/ChapterFour/0986.Interval-List-Intersections.md" >}})| Medium | O(n)| O(1)||
-|992. Subarrays with K Different Integers | [Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})| Hard | O(n)| O(n)|❤️|
-|1004. Max Consecutive Ones III | [Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})| Medium | O(n)| O(1) ||
-|1093. Statistics from a Large Sample | [Go]({{< relref "/ChapterFour/1093.Statistics-from-a-Large-Sample.md" >}})| Medium | O(n)| O(1) ||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0003|Longest Substring Without Repeating Characters|[Go]({{< relref "/ChapterFour/0003.Longest-Substring-Without-Repeating-Characters.md" >}})|Medium| O(n)| O(1)|❤️|31.3%|
+|0011|Container With Most Water|[Go]({{< relref "/ChapterFour/0011.Container-With-Most-Water.md" >}})|Medium| O(n)| O(1)||52.2%|
+|0015|3Sum|[Go]({{< relref "/ChapterFour/0015.3Sum.md" >}})|Medium| O(n^2)| O(n)|❤️|27.8%|
+|0016|3Sum Closest|[Go]({{< relref "/ChapterFour/0016.3Sum-Closest.md" >}})|Medium| O(n^2)| O(1)|❤️|46.2%|
+|0018|4Sum|[Go]({{< relref "/ChapterFour/0018.4Sum.md" >}})|Medium| O(n^3)| O(n^2)|❤️|34.6%|
+|0019|Remove Nth Node From End of List|[Go]({{< relref "/ChapterFour/0019.Remove-Nth-Node-From-End-of-List.md" >}})|Medium| O(n)| O(1)||35.6%|
+|0026|Remove Duplicates from Sorted Array|[Go]({{< relref "/ChapterFour/0026.Remove-Duplicates-from-Sorted-Array.md" >}})|Easy| O(n)| O(1)||46.3%|
+|0027|Remove Element|[Go]({{< relref "/ChapterFour/0027.Remove-Element.md" >}})|Easy| O(n)| O(1)||49.0%|
+|0028|Implement strStr()|[Go]({{< relref "/ChapterFour/0028.Implement-strStr.md" >}})|Easy| O(n)| O(1)||35.1%|
+|0030|Substring with Concatenation of All Words|[Go]({{< relref "/ChapterFour/0030.Substring-with-Concatenation-of-All-Words.md" >}})|Hard| O(n)| O(n)|❤️|26.0%|
+|0042|Trapping Rain Water|[Go]({{< relref "/ChapterFour/0042.Trapping-Rain-Water.md" >}})|Hard| O(n)| O(1)|❤️|50.8%|
+|0061|Rotate List|[Go]({{< relref "/ChapterFour/0061.Rotate-List.md" >}})|Medium| O(n)| O(1)||31.6%|
+|0075|Sort Colors|[Go]({{< relref "/ChapterFour/0075.Sort-Colors.md" >}})|Medium| O(n)| O(1)|❤️|49.0%|
+|0076|Minimum Window Substring|[Go]({{< relref "/ChapterFour/0076.Minimum-Window-Substring.md" >}})|Hard| O(n)| O(n)|❤️|35.7%|
+|0080|Remove Duplicates from Sorted Array II|[Go]({{< relref "/ChapterFour/0080.Remove-Duplicates-from-Sorted-Array-II.md" >}})|Medium| O(n)| O(1||45.9%|
+|0086|Partition List|[Go]({{< relref "/ChapterFour/0086.Partition-List.md" >}})|Medium| O(n)| O(1)|❤️|43.0%|
+|0088|Merge Sorted Array|[Go]({{< relref "/ChapterFour/0088.Merge-Sorted-Array.md" >}})|Easy| O(n)| O(1)|❤️|40.6%|
+|0125|Valid Palindrome|[Go]({{< relref "/ChapterFour/0125.Valid-Palindrome.md" >}})|Easy| O(n)| O(1)||37.9%|
+|0141|Linked List Cycle|[Go]({{< relref "/ChapterFour/0141.Linked-List-Cycle.md" >}})|Easy| O(n)| O(1)|❤️|42.2%|
+|0142|Linked List Cycle II|[Go]({{< relref "/ChapterFour/0142.Linked-List-Cycle-II.md" >}})|Medium| O(n)| O(1)|❤️|39.3%|
+|0167|Two Sum II - Input array is sorted|[Go]({{< relref "/ChapterFour/0167.Two-Sum-II---Input-array-is-sorted.md" >}})|Easy| O(n)| O(1)||55.4%|
+|0209|Minimum Size Subarray Sum|[Go]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})|Medium| O(n)| O(1)||39.2%|
+|0234|Palindrome Linked List|[Go]({{< relref "/ChapterFour/0234.Palindrome-Linked-List.md" >}})|Easy| O(n)| O(1)||40.2%|
+|0283|Move Zeroes|[Go]({{< relref "/ChapterFour/0283.Move-Zeroes.md" >}})|Easy| O(n)| O(1)||58.4%|
+|0287|Find the Duplicate Number|[Go]({{< relref "/ChapterFour/0287.Find-the-Duplicate-Number.md" >}})|Medium| O(n)| O(1)|❤️|57.2%|
+|0344|Reverse String|[Go]({{< relref "/ChapterFour/0344.Reverse-String.md" >}})|Easy| O(n)| O(1)||70.0%|
+|0345|Reverse Vowels of a String|[Go]({{< relref "/ChapterFour/0345.Reverse-Vowels-of-a-String.md" >}})|Easy| O(n)| O(1)||44.9%|
+|0349|Intersection of Two Arrays|[Go]({{< relref "/ChapterFour/0349.Intersection-of-Two-Arrays.md" >}})|Easy| O(n)| O(n) ||64.4%|
+|0350|Intersection of Two Arrays II|[Go]({{< relref "/ChapterFour/0350.Intersection-of-Two-Arrays-II.md" >}})|Easy| O(n)| O(n) ||51.9%|
+|0424|Longest Repeating Character Replacement|[Go]({{< relref "/ChapterFour/0424.Longest-Repeating-Character-Replacement.md" >}})|Medium| O(n)| O(1) ||48.0%|
+|0457|Circular Array Loop|[Go]({{< relref "/ChapterFour/0457.Circular-Array-Loop.md" >}})|Medium||||30.0%|
+|0524|Longest Word in Dictionary through Deleting|[Go]({{< relref "/ChapterFour/0524.Longest-Word-in-Dictionary-through-Deleting.md" >}})|Medium| O(n)| O(1) ||48.9%|
+|0532|K-diff Pairs in an Array|[Go]({{< relref "/ChapterFour/0532.K-diff-Pairs-in-an-Array.md" >}})|Medium| O(n)| O(n)||34.9%|
+|0567|Permutation in String|[Go]({{< relref "/ChapterFour/0567.Permutation-in-String.md" >}})|Medium| O(n)| O(1)|❤️|44.6%|
+|0632|Smallest Range Covering Elements from K Lists|[Go]({{< relref "/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})|Hard||||53.9%|
+|0713|Subarray Product Less Than K|[Go]({{< relref "/ChapterFour/0713.Subarray-Product-Less-Than-K.md" >}})|Medium| O(n)| O(1)||40.4%|
+|0763|Partition Labels|[Go]({{< relref "/ChapterFour/0763.Partition-Labels.md" >}})|Medium| O(n)| O(1)|❤️|77.9%|
+|0826|Most Profit Assigning Work|[Go]({{< relref "/ChapterFour/0826.Most-Profit-Assigning-Work.md" >}})|Medium| O(n log n)| O(n)||38.9%|
+|0828|Count Unique Characters of All Substrings of a Given String|[Go]({{< relref "/ChapterFour/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.md" >}})|Hard| O(n)| O(1)|❤️|46.8%|
+|0838|Push Dominoes|[Go]({{< relref "/ChapterFour/0838.Push-Dominoes.md" >}})|Medium| O(n)| O(n)||49.7%|
+|0844|Backspace String Compare|[Go]({{< relref "/ChapterFour/0844.Backspace-String-Compare.md" >}})|Easy| O(n)| O(n) ||46.8%|
+|0845|Longest Mountain in Array|[Go]({{< relref "/ChapterFour/0845.Longest-Mountain-in-Array.md" >}})|Medium| O(n)| O(1) ||38.5%|
+|0881|Boats to Save People|[Go]({{< relref "/ChapterFour/0881.Boats-to-Save-People.md" >}})|Medium| O(n log n)| O(1) ||48.7%|
+|0904|Fruit Into Baskets|[Go]({{< relref "/ChapterFour/0904.Fruit-Into-Baskets.md" >}})|Medium| O(n log n)| O(1) ||42.9%|
+|0923|3Sum With Multiplicity|[Go]({{< relref "/ChapterFour/0923.3Sum-With-Multiplicity.md" >}})|Medium| O(n^2)| O(n) ||36.0%|
+|0925|Long Pressed Name|[Go]({{< relref "/ChapterFour/0925.Long-Pressed-Name.md" >}})|Easy| O(n)| O(1)||38.4%|
+|0930|Binary Subarrays With Sum|[Go]({{< relref "/ChapterFour/0930.Binary-Subarrays-With-Sum.md" >}})|Medium| O(n)| O(n) |❤️|44.3%|
+|0977|Squares of a Sorted Array|[Go]({{< relref "/ChapterFour/0977.Squares-of-a-Sorted-Array.md" >}})|Easy| O(n)| O(1)||72.3%|
+|0986|Interval List Intersections|[Go]({{< relref "/ChapterFour/0986.Interval-List-Intersections.md" >}})|Medium| O(n)| O(1)||68.1%|
+|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard| O(n)| O(n)|❤️|50.5%|
+|1004|Max Consecutive Ones III|[Go]({{< relref "/ChapterFour/1004.Max-Consecutive-Ones-III.md" >}})|Medium| O(n)| O(1) ||60.5%|
+|1093|Statistics from a Large Sample|[Go]({{< relref "/ChapterFour/1093.Statistics-from-a-Large-Sample.md" >}})|Medium| O(n)| O(1) ||49.3%|
+|1234|Replace the Substring for Balanced String|[Go]({{< relref "/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md" >}})|Medium||||34.4%|
+|1658|Minimum Operations to Reduce X to Zero|[Go]({{< relref "/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md" >}})|Medium||||33.4%|
+|1695|Maximum Erasure Value|[Go]({{< relref "/ChapterFour/1695.Maximum-Erasure-Value.md" >}})|Medium||||49.5%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/Union_Find.md b/website/content/ChapterTwo/Union_Find.md
index 79b693d5..db9fd736 100644
--- a/website/content/ChapterTwo/Union_Find.md
+++ b/website/content/ChapterTwo/Union_Find.md
@@ -15,24 +15,33 @@ type: docs
- 能用并查集的题目,一般也可以用 DFS 和 BFS 解答,只不过时间复杂度会高一点。
-| Title | Solution | Difficulty | Time | Space | 收藏 |
-| ----- | :--------: | :----------: | :----: | :-----: |:-----: |
-|128. Longest Consecutive Sequence | [Go]({{< relref "/ChapterFour/0128.Longest-Consecutive-Sequence.md" >}})| Hard | O(n)| O(n)|❤️|
-|130. Surrounded Regions | [Go]({{< relref "/ChapterFour/0130.Surrounded-Regions.md" >}})| Medium | O(m\*n)| O(m\*n)||
-|200. Number of Islands | [Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})| Medium | O(m\*n)| O(m\*n)||
-|399. Evaluate Division | [Go]({{< relref "/ChapterFour/0399.Evaluate-Division.md" >}})| Medium | O(n)| O(n)||
-|547. Friend Circles | [Go]({{< relref "/ChapterFour/0547.Friend-Circles.md" >}})| Medium | O(n^2)| O(n)||
-|684. Redundant Connection | [Go]({{< relref "/ChapterFour/0684.Redundant-Connection.md" >}})| Medium | O(n)| O(n)||
-|685. Redundant Connection II | [Go]({{< relref "/ChapterFour/0685.Redundant-Connection-II.md" >}})| Hard | O(n)| O(n)||
-|721. Accounts Merge | [Go]({{< relref "/ChapterFour/0721.Accounts-Merge.md" >}})| Medium | O(n)| O(n)|❤️|
-|765. Couples Holding Hands | [Go]({{< relref "/ChapterFour/0765.Couples-Holding-Hands.md" >}})| Hard | O(n)| O(n)|❤️|
-|778. Swim in Rising Water | [Go]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|803. Bricks Falling When Hit | [Go]({{< relref "/ChapterFour/0803.Bricks-Falling-When-Hit.md" >}})| Hard | O(n^2)| O(n)|❤️|
-|839. Similar String Groups | [Go]({{< relref "/ChapterFour/0839.Similar-String-Groups.md" >}})| Hard | O(n^2)| O(n)||
-|924. Minimize Malware Spread | [Go]({{< relref "/ChapterFour/0924.Minimize-Malware-Spread.md" >}})| Hard | O(m\*n)| O(n)||
-|928. Minimize Malware Spread II | [Go]({{< relref "/ChapterFour/0928.Minimize-Malware-Spread-II.md" >}})| Hard | O(m\*n)| O(n)|❤️|
-|947. Most Stones Removed with Same Row or Column | [Go]({{< relref "/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md" >}})| Medium | O(n)| O(n)||
-|952. Largest Component Size by Common Factor | [Go]({{< relref "/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md" >}})| Hard | O(n)| O(n)|❤️|
-|959. Regions Cut By Slashes | [Go]({{< relref "/ChapterFour/0959.Regions-Cut-By-Slashes.md" >}})| Medium | O(n^2)| O(n^2)|❤️|
-|990. Satisfiability of Equality Equations | [Go]({{< relref "/ChapterFour/0990.Satisfiability-of-Equality-Equations.md" >}})| Medium | O(n)| O(n)||
-|---------------------------------------|---------------------------------|--------------------------|-----------------------|-----------|--------|
\ No newline at end of file
+
+| No. | Title | Solution | Difficulty | TimeComplexity | SpaceComplexity |Favorite| Acceptance |
+|:--------:|:------- | :--------: | :----------: | :----: | :-----: | :-----: |:-----: |
+|0128|Longest Consecutive Sequence|[Go]({{< relref "/ChapterFour/0128.Longest-Consecutive-Sequence.md" >}})|Hard| O(n)| O(n)|❤️|46.1%|
+|0130|Surrounded Regions|[Go]({{< relref "/ChapterFour/0130.Surrounded-Regions.md" >}})|Medium| O(m\*n)| O(m\*n)||29.2%|
+|0200|Number of Islands|[Go]({{< relref "/ChapterFour/0200.Number-of-Islands.md" >}})|Medium| O(m\*n)| O(m\*n)||48.6%|
+|0399|Evaluate Division|[Go]({{< relref "/ChapterFour/0399.Evaluate-Division.md" >}})|Medium| O(n)| O(n)||54.0%|
+|0547|Number of Provinces|[Go]({{< relref "/ChapterFour/0547.Number-of-Provinces.md" >}})|Medium| O(n^2)| O(n)||60.1%|
+|0684|Redundant Connection|[Go]({{< relref "/ChapterFour/0684.Redundant-Connection.md" >}})|Medium| O(n)| O(n)||58.8%|
+|0685|Redundant Connection II|[Go]({{< relref "/ChapterFour/0685.Redundant-Connection-II.md" >}})|Hard| O(n)| O(n)||32.9%|
+|0721|Accounts Merge|[Go]({{< relref "/ChapterFour/0721.Accounts-Merge.md" >}})|Medium| O(n)| O(n)|❤️|51.2%|
+|0765|Couples Holding Hands|[Go]({{< relref "/ChapterFour/0765.Couples-Holding-Hands.md" >}})|Hard| O(n)| O(n)|❤️|55.3%|
+|0778|Swim in Rising Water|[Go]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})|Hard| O(n^2)| O(n)|❤️|54.4%|
+|0803|Bricks Falling When Hit|[Go]({{< relref "/ChapterFour/0803.Bricks-Falling-When-Hit.md" >}})|Hard| O(n^2)| O(n)|❤️|31.3%|
+|0839|Similar String Groups|[Go]({{< relref "/ChapterFour/0839.Similar-String-Groups.md" >}})|Hard| O(n^2)| O(n)||40.1%|
+|0924|Minimize Malware Spread|[Go]({{< relref "/ChapterFour/0924.Minimize-Malware-Spread.md" >}})|Hard| O(m\*n)| O(n)||41.8%|
+|0928|Minimize Malware Spread II|[Go]({{< relref "/ChapterFour/0928.Minimize-Malware-Spread-II.md" >}})|Hard| O(m\*n)| O(n)|❤️|41.2%|
+|0947|Most Stones Removed with Same Row or Column|[Go]({{< relref "/ChapterFour/0947.Most-Stones-Removed-with-Same-Row-or-Column.md" >}})|Medium| O(n)| O(n)||55.4%|
+|0952|Largest Component Size by Common Factor|[Go]({{< relref "/ChapterFour/0952.Largest-Component-Size-by-Common-Factor.md" >}})|Hard| O(n)| O(n)|❤️|36.1%|
+|0959|Regions Cut By Slashes|[Go]({{< relref "/ChapterFour/0959.Regions-Cut-By-Slashes.md" >}})|Medium| O(n^2)| O(n^2)|❤️|66.9%|
+|0990|Satisfiability of Equality Equations|[Go]({{< relref "/ChapterFour/0990.Satisfiability-of-Equality-Equations.md" >}})|Medium| O(n)| O(n)||46.5%|
+|1202|Smallest String With Swaps|[Go]({{< relref "/ChapterFour/1202.Smallest-String-With-Swaps.md" >}})|Medium||||48.4%|
+|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|-------------|-------------|
+
+
+----------------------------------------------
+
diff --git a/website/content/ChapterTwo/_index.md b/website/content/ChapterTwo/_index.md
index c28b73c5..4699e8ca 100644
--- a/website/content/ChapterTwo/_index.md
+++ b/website/content/ChapterTwo/_index.md
@@ -19,3 +19,10 @@ type: docs
做到目前为止,笔者认为动态规划是最灵活的类型,这类题目没有一个模板可以给你套用,它也是算法之优雅的地方。笔者认为称它为算法的艺术不为过。动态规划这类型,笔者也还没有刷完,只刷了一部分,还在学习中。
那么就分享一下笔者目前刷过的题,和有相似点的题目吧。
+
+
+----------------------------------------------
+
diff --git a/website/content/menu/index.md b/website/content/menu/index.md
index e9832e08..b15fe806 100644
--- a/website/content/menu/index.md
+++ b/website/content/menu/index.md
@@ -31,6 +31,8 @@ headless: true
- [第三章 一些模板]({{< relref "/ChapterThree/_index.md" >}})
- [3.1 Segment Tree]({{< relref "/ChapterThree/Segment_Tree.md" >}})
- [3.2 UnionFind]({{< relref "/ChapterThree/UnionFind.md" >}})
+ - [3.3 LRUCache]({{< relref "/ChapterThree/LRUCache.md" >}})
+ - [3.4 LFUCache]({{< relref "/ChapterThree/LFUCache.md" >}})
- [第四章 Leetcode 题解]({{< relref "/ChapterFour/_index.md" >}})
- [0001.Two-Sum]({{< relref "/ChapterFour/0001.Two-Sum.md" >}})
- [0002.Add-Two-Numbers]({{< relref "/ChapterFour/0002.Add-Two-Numbers.md" >}})
@@ -145,6 +147,7 @@ headless: true
- [0143.Reorder-List]({{< relref "/ChapterFour/0143.Reorder-List.md" >}})
- [0144.Binary-Tree-Preorder-Traversal]({{< relref "/ChapterFour/0144.Binary-Tree-Preorder-Traversal.md" >}})
- [0145.Binary-Tree-Postorder-Traversal]({{< relref "/ChapterFour/0145.Binary-Tree-Postorder-Traversal.md" >}})
+ - [0146.LRU-Cache]({{< relref "/ChapterFour/0146.LRU-Cache.md" >}})
- [0147.Insertion-Sort-List]({{< relref "/ChapterFour/0147.Insertion-Sort-List.md" >}})
- [0148.Sort-List]({{< relref "/ChapterFour/0148.Sort-List.md" >}})
- [0150.Evaluate-Reverse-Polish-Notation]({{< relref "/ChapterFour/0150.Evaluate-Reverse-Polish-Notation.md" >}})
@@ -165,6 +168,7 @@ headless: true
- [0174.Dungeon-Game]({{< relref "/ChapterFour/0174.Dungeon-Game.md" >}})
- [0179.Largest-Number]({{< relref "/ChapterFour/0179.Largest-Number.md" >}})
- [0187.Repeated-DNA-Sequences]({{< relref "/ChapterFour/0187.Repeated-DNA-Sequences.md" >}})
+ - [0189.Rotate-Array]({{< relref "/ChapterFour/0189.Rotate-Array.md" >}})
- [0190.Reverse-Bits]({{< relref "/ChapterFour/0190.Reverse-Bits.md" >}})
- [0191.Number-of-1-Bits]({{< relref "/ChapterFour/0191.Number-of-1-Bits.md" >}})
- [0198.House-Robber]({{< relref "/ChapterFour/0198.House-Robber.md" >}})
@@ -180,7 +184,7 @@ headless: true
- [0208.Implement-Trie-Prefix-Tree]({{< relref "/ChapterFour/0208.Implement-Trie-Prefix-Tree.md" >}})
- [0209.Minimum-Size-Subarray-Sum]({{< relref "/ChapterFour/0209.Minimum-Size-Subarray-Sum.md" >}})
- [0210.Course-Schedule-II]({{< relref "/ChapterFour/0210.Course-Schedule-II.md" >}})
- - [0211.Add-and-Search-Word---Data-structure-design]({{< relref "/ChapterFour/0211.Add-and-Search-Word---Data-structure-design.md" >}})
+ - [0211.Design-Add-and-Search-Words-Data-Structure]({{< relref "/ChapterFour/0211.Design-Add-and-Search-Words-Data-Structure.md" >}})
- [0212.Word-Search-II]({{< relref "/ChapterFour/0212.Word-Search-II.md" >}})
- [0213.House-Robber-II]({{< relref "/ChapterFour/0213.House-Robber-II.md" >}})
- [0215.Kth-Largest-Element-in-an-Array]({{< relref "/ChapterFour/0215.Kth-Largest-Element-in-an-Array.md" >}})
@@ -194,6 +198,7 @@ headless: true
- [0224.Basic-Calculator]({{< relref "/ChapterFour/0224.Basic-Calculator.md" >}})
- [0225.Implement-Stack-using-Queues]({{< relref "/ChapterFour/0225.Implement-Stack-using-Queues.md" >}})
- [0226.Invert-Binary-Tree]({{< relref "/ChapterFour/0226.Invert-Binary-Tree.md" >}})
+ - [0228.Summary-Ranges]({{< relref "/ChapterFour/0228.Summary-Ranges.md" >}})
- [0229.Majority-Element-II]({{< relref "/ChapterFour/0229.Majority-Element-II.md" >}})
- [0230.Kth-Smallest-Element-in-a-BST]({{< relref "/ChapterFour/0230.Kth-Smallest-Element-in-a-BST.md" >}})
- [0231.Power-of-Two]({{< relref "/ChapterFour/0231.Power-of-Two.md" >}})
@@ -280,6 +285,7 @@ headless: true
- [0455.Assign-Cookies]({{< relref "/ChapterFour/0455.Assign-Cookies.md" >}})
- [0456.132-Pattern]({{< relref "/ChapterFour/0456.132-Pattern.md" >}})
- [0457.Circular-Array-Loop]({{< relref "/ChapterFour/0457.Circular-Array-Loop.md" >}})
+ - [0460.LFU-Cache]({{< relref "/ChapterFour/0460.LFU-Cache.md" >}})
- [0461.Hamming-Distance]({{< relref "/ChapterFour/0461.Hamming-Distance.md" >}})
- [0463.Island-Perimeter]({{< relref "/ChapterFour/0463.Island-Perimeter.md" >}})
- [0470.Implement-Rand10-Using-Rand7]({{< relref "/ChapterFour/0470.Implement-Rand10-Using-Rand7.md" >}})
@@ -311,7 +317,7 @@ headless: true
- [0537.Complex-Number-Multiplication]({{< relref "/ChapterFour/0537.Complex-Number-Multiplication.md" >}})
- [0541.Reverse-String-II]({{< relref "/ChapterFour/0541.Reverse-String-II.md" >}})
- [0542.01-Matrix]({{< relref "/ChapterFour/0542.01-Matrix.md" >}})
- - [0547.Friend-Circles]({{< relref "/ChapterFour/0547.Friend-Circles.md" >}})
+ - [0547.Number-of-Provinces]({{< relref "/ChapterFour/0547.Number-of-Provinces.md" >}})
- [0557.Reverse-Words-in-a-String-III]({{< relref "/ChapterFour/0557.Reverse-Words-in-a-String-III.md" >}})
- [0561.Array-Partition-I]({{< relref "/ChapterFour/0561.Array-Partition-I.md" >}})
- [0563.Binary-Tree-Tilt]({{< relref "/ChapterFour/0563.Binary-Tree-Tilt.md" >}})
@@ -322,6 +328,7 @@ headless: true
- [0594.Longest-Harmonious-Subsequence]({{< relref "/ChapterFour/0594.Longest-Harmonious-Subsequence.md" >}})
- [0598.Range-Addition-II]({{< relref "/ChapterFour/0598.Range-Addition-II.md" >}})
- [0599.Minimum-Index-Sum-of-Two-Lists]({{< relref "/ChapterFour/0599.Minimum-Index-Sum-of-Two-Lists.md" >}})
+ - [0605.Can-Place-Flowers]({{< relref "/ChapterFour/0605.Can-Place-Flowers.md" >}})
- [0628.Maximum-Product-of-Three-Numbers]({{< relref "/ChapterFour/0628.Maximum-Product-of-Three-Numbers.md" >}})
- [0632.Smallest-Range-Covering-Elements-from-K-Lists]({{< relref "/ChapterFour/0632.Smallest-Range-Covering-Elements-from-K-Lists.md" >}})
- [0633.Sum-of-Square-Numbers]({{< relref "/ChapterFour/0633.Sum-of-Square-Numbers.md" >}})
@@ -379,6 +386,7 @@ headless: true
- [0778.Swim-in-Rising-Water]({{< relref "/ChapterFour/0778.Swim-in-Rising-Water.md" >}})
- [0781.Rabbits-in-Forest]({{< relref "/ChapterFour/0781.Rabbits-in-Forest.md" >}})
- [0784.Letter-Case-Permutation]({{< relref "/ChapterFour/0784.Letter-Case-Permutation.md" >}})
+ - [0785.Is-Graph-Bipartite]({{< relref "/ChapterFour/0785.Is-Graph-Bipartite.md" >}})
- [0786.K-th-Smallest-Prime-Fraction]({{< relref "/ChapterFour/0786.K-th-Smallest-Prime-Fraction.md" >}})
- [0793.Preimage-Size-of-Factorial-Zeroes-Function]({{< relref "/ChapterFour/0793.Preimage-Size-of-Factorial-Zeroes-Function.md" >}})
- [0802.Find-Eventual-Safe-States]({{< relref "/ChapterFour/0802.Find-Eventual-Safe-States.md" >}})
@@ -389,7 +397,8 @@ headless: true
- [0817.Linked-List-Components]({{< relref "/ChapterFour/0817.Linked-List-Components.md" >}})
- [0819.Most-Common-Word]({{< relref "/ChapterFour/0819.Most-Common-Word.md" >}})
- [0826.Most-Profit-Assigning-Work]({{< relref "/ChapterFour/0826.Most-Profit-Assigning-Work.md" >}})
- - [0828.COPYRIGHT-PROBLEM-XXX]({{< relref "/ChapterFour/0828.COPYRIGHT-PROBLEM-XXX.md" >}})
+ - [0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String]({{< relref "/ChapterFour/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String.md" >}})
+ - [0830.Positions-of-Large-Groups]({{< relref "/ChapterFour/0830.Positions-of-Large-Groups.md" >}})
- [0832.Flipping-an-Image]({{< relref "/ChapterFour/0832.Flipping-an-Image.md" >}})
- [0834.Sum-of-Distances-in-Tree]({{< relref "/ChapterFour/0834.Sum-of-Distances-in-Tree.md" >}})
- [0836.Rectangle-Overlap]({{< relref "/ChapterFour/0836.Rectangle-Overlap.md" >}})
@@ -427,6 +436,7 @@ headless: true
- [0901.Online-Stock-Span]({{< relref "/ChapterFour/0901.Online-Stock-Span.md" >}})
- [0904.Fruit-Into-Baskets]({{< relref "/ChapterFour/0904.Fruit-Into-Baskets.md" >}})
- [0907.Sum-of-Subarray-Minimums]({{< relref "/ChapterFour/0907.Sum-of-Subarray-Minimums.md" >}})
+ - [0910.Smallest-Range-II]({{< relref "/ChapterFour/0910.Smallest-Range-II.md" >}})
- [0911.Online-Election]({{< relref "/ChapterFour/0911.Online-Election.md" >}})
- [0914.X-of-a-Kind-in-a-Deck-of-Cards]({{< relref "/ChapterFour/0914.X-of-a-Kind-in-a-Deck-of-Cards.md" >}})
- [0918.Maximum-Sum-Circular-Subarray]({{< relref "/ChapterFour/0918.Maximum-Sum-Circular-Subarray.md" >}})
@@ -473,6 +483,7 @@ headless: true
- [1005.Maximize-Sum-Of-Array-After-K-Negations]({{< relref "/ChapterFour/1005.Maximize-Sum-Of-Array-After-K-Negations.md" >}})
- [1011.Capacity-To-Ship-Packages-Within-D-Days]({{< relref "/ChapterFour/1011.Capacity-To-Ship-Packages-Within-D-Days.md" >}})
- [1017.Convert-to-Base--2]({{< relref "/ChapterFour/1017.Convert-to-Base--2.md" >}})
+ - [1018.Binary-Prefix-Divisible-By-5]({{< relref "/ChapterFour/1018.Binary-Prefix-Divisible-By-5.md" >}})
- [1019.Next-Greater-Node-In-Linked-List]({{< relref "/ChapterFour/1019.Next-Greater-Node-In-Linked-List.md" >}})
- [1020.Number-of-Enclaves]({{< relref "/ChapterFour/1020.Number-of-Enclaves.md" >}})
- [1021.Remove-Outermost-Parentheses]({{< relref "/ChapterFour/1021.Remove-Outermost-Parentheses.md" >}})
@@ -514,9 +525,10 @@ headless: true
- [1200.Minimum-Absolute-Difference]({{< relref "/ChapterFour/1200.Minimum-Absolute-Difference.md" >}})
- [1201.Ugly-Number-III]({{< relref "/ChapterFour/1201.Ugly-Number-III.md" >}})
- [1202.Smallest-String-With-Swaps]({{< relref "/ChapterFour/1202.Smallest-String-With-Swaps.md" >}})
+ - [1203.Sort-Items-by-Groups-Respecting-Dependencies]({{< relref "/ChapterFour/1203.Sort-Items-by-Groups-Respecting-Dependencies.md" >}})
- [1207.Unique-Number-of-Occurrences]({{< relref "/ChapterFour/1207.Unique-Number-of-Occurrences.md" >}})
- [1208.Get-Equal-Substrings-Within-Budget]({{< relref "/ChapterFour/1208.Get-Equal-Substrings-Within-Budget.md" >}})
- - [1217.Play-with-Chips]({{< relref "/ChapterFour/1217.Play-with-Chips.md" >}})
+ - [1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position]({{< relref "/ChapterFour/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position.md" >}})
- [1221.Split-a-String-in-Balanced-Strings]({{< relref "/ChapterFour/1221.Split-a-String-in-Balanced-Strings.md" >}})
- [1232.Check-If-It-Is-a-Straight-Line]({{< relref "/ChapterFour/1232.Check-If-It-Is-a-Straight-Line.md" >}})
- [1234.Replace-the-Substring-for-Balanced-String]({{< relref "/ChapterFour/1234.Replace-the-Substring-for-Balanced-String.md" >}})
@@ -545,4 +557,46 @@ headless: true
- [1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence]({{< relref "/ChapterFour/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md" >}})
- [1464.Maximum-Product-of-Two-Elements-in-an-Array]({{< relref "/ChapterFour/1464.Maximum-Product-of-Two-Elements-in-an-Array.md" >}})
- [1470.Shuffle-the-Array]({{< relref "/ChapterFour/1470.Shuffle-the-Array.md" >}})
+ - [1480.Running-Sum-of-1d-Array]({{< relref "/ChapterFour/1480.Running-Sum-of-1d-Array.md" >}})
+ - [1512.Number-of-Good-Pairs]({{< relref "/ChapterFour/1512.Number-of-Good-Pairs.md" >}})
+ - [1539.Kth-Missing-Positive-Number]({{< relref "/ChapterFour/1539.Kth-Missing-Positive-Number.md" >}})
+ - [1573.Number-of-Ways-to-Split-a-String]({{< relref "/ChapterFour/1573.Number-of-Ways-to-Split-a-String.md" >}})
+ - [1640.Check-Array-Formation-Through-Concatenation]({{< relref "/ChapterFour/1640.Check-Array-Formation-Through-Concatenation.md" >}})
+ - [1641.Count-Sorted-Vowel-Strings]({{< relref "/ChapterFour/1641.Count-Sorted-Vowel-Strings.md" >}})
+ - [1646.Get-Maximum-in-Generated-Array]({{< relref "/ChapterFour/1646.Get-Maximum-in-Generated-Array.md" >}})
+ - [1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique]({{< relref "/ChapterFour/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique.md" >}})
+ - [1648.Sell-Diminishing-Valued-Colored-Balls]({{< relref "/ChapterFour/1648.Sell-Diminishing-Valued-Colored-Balls.md" >}})
+ - [1649.Create-Sorted-Array-through-Instructions]({{< relref "/ChapterFour/1649.Create-Sorted-Array-through-Instructions.md" >}})
+ - [1652.Defuse-the-Bomb]({{< relref "/ChapterFour/1652.Defuse-the-Bomb.md" >}})
+ - [1653.Minimum-Deletions-to-Make-String-Balanced]({{< relref "/ChapterFour/1653.Minimum-Deletions-to-Make-String-Balanced.md" >}})
+ - [1654.Minimum-Jumps-to-Reach-Home]({{< relref "/ChapterFour/1654.Minimum-Jumps-to-Reach-Home.md" >}})
+ - [1655.Distribute-Repeating-Integers]({{< relref "/ChapterFour/1655.Distribute-Repeating-Integers.md" >}})
+ - [1656.Design-an-Ordered-Stream]({{< relref "/ChapterFour/1656.Design-an-Ordered-Stream.md" >}})
+ - [1657.Determine-if-Two-Strings-Are-Close]({{< relref "/ChapterFour/1657.Determine-if-Two-Strings-Are-Close.md" >}})
+ - [1658.Minimum-Operations-to-Reduce-X-to-Zero]({{< relref "/ChapterFour/1658.Minimum-Operations-to-Reduce-X-to-Zero.md" >}})
+ - [1659.Maximize-Grid-Happiness]({{< relref "/ChapterFour/1659.Maximize-Grid-Happiness.md" >}})
+ - [1662.Check-If-Two-String-Arrays-are-Equivalent]({{< relref "/ChapterFour/1662.Check-If-Two-String-Arrays-are-Equivalent.md" >}})
+ - [1663.Smallest-String-With-A-Given-Numeric-Value]({{< relref "/ChapterFour/1663.Smallest-String-With-A-Given-Numeric-Value.md" >}})
+ - [1664.Ways-to-Make-a-Fair-Array]({{< relref "/ChapterFour/1664.Ways-to-Make-a-Fair-Array.md" >}})
+ - [1665.Minimum-Initial-Energy-to-Finish-Tasks]({{< relref "/ChapterFour/1665.Minimum-Initial-Energy-to-Finish-Tasks.md" >}})
+ - [1668.Maximum-Repeating-Substring]({{< relref "/ChapterFour/1668.Maximum-Repeating-Substring.md" >}})
+ - [1669.Merge-In-Between-Linked-Lists]({{< relref "/ChapterFour/1669.Merge-In-Between-Linked-Lists.md" >}})
+ - [1670.Design-Front-Middle-Back-Queue]({{< relref "/ChapterFour/1670.Design-Front-Middle-Back-Queue.md" >}})
+ - [1672.Richest-Customer-Wealth]({{< relref "/ChapterFour/1672.Richest-Customer-Wealth.md" >}})
+ - [1673.Find-the-Most-Competitive-Subsequence]({{< relref "/ChapterFour/1673.Find-the-Most-Competitive-Subsequence.md" >}})
+ - [1674.Minimum-Moves-to-Make-Array-Complementary]({{< relref "/ChapterFour/1674.Minimum-Moves-to-Make-Array-Complementary.md" >}})
+ - [1678.Goal-Parser-Interpretation]({{< relref "/ChapterFour/1678.Goal-Parser-Interpretation.md" >}})
+ - [1679.Max-Number-of-K-Sum-Pairs]({{< relref "/ChapterFour/1679.Max-Number-of-K-Sum-Pairs.md" >}})
+ - [1680.Concatenation-of-Consecutive-Binary-Numbers]({{< relref "/ChapterFour/1680.Concatenation-of-Consecutive-Binary-Numbers.md" >}})
+ - [1681.Minimum-Incompatibility]({{< relref "/ChapterFour/1681.Minimum-Incompatibility.md" >}})
+ - [1684.Count-the-Number-of-Consistent-Strings]({{< relref "/ChapterFour/1684.Count-the-Number-of-Consistent-Strings.md" >}})
+ - [1685.Sum-of-Absolute-Differences-in-a-Sorted-Array]({{< relref "/ChapterFour/1685.Sum-of-Absolute-Differences-in-a-Sorted-Array.md" >}})
+ - [1688.Count-of-Matches-in-Tournament]({{< relref "/ChapterFour/1688.Count-of-Matches-in-Tournament.md" >}})
+ - [1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers]({{< relref "/ChapterFour/1689.Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers.md" >}})
+ - [1690.Stone-Game-VII]({{< relref "/ChapterFour/1690.Stone-Game-VII.md" >}})
+ - [1694.Reformat-Phone-Number]({{< relref "/ChapterFour/1694.Reformat-Phone-Number.md" >}})
+ - [1695.Maximum-Erasure-Value]({{< relref "/ChapterFour/1695.Maximum-Erasure-Value.md" >}})
+ - [1696.Jump-Game-VI]({{< relref "/ChapterFour/1696.Jump-Game-VI.md" >}})
+
+
diff --git a/website/static/wechat-qr-code.png b/website/static/wechat-qr-code.png
new file mode 100644
index 00000000..c604e733
Binary files /dev/null and b/website/static/wechat-qr-code.png differ
diff --git a/website/themes/book/assets/serviceworker-v1.js b/website/themes/book/assets/serviceworker-v1.js
new file mode 100644
index 00000000..dd7ef660
--- /dev/null
+++ b/website/themes/book/assets/serviceworker-v1.js
@@ -0,0 +1,86 @@
+'use strict';
+(function () {
+ 'use strict';
+ /**
+ * Service Worker Toolbox caching
+ */
+ var cacheVersion = '-toolbox-v1';
+ var dynamicVendorCacheName = 'dynamic-vendor' + cacheVersion;
+ var staticVendorCacheName = 'static-vendor' + cacheVersion;
+ var staticAssetsCacheName = 'static-assets' + cacheVersion;
+ var contentCacheName = 'content' + cacheVersion;
+ var maxEntries = 50;
+ self.importScripts("/leetcode/js/sw-toolbox.js");
+ self.toolbox.options.debug = false;
+
+ // Cache own static assets
+ self.toolbox.router.get('/(.*)', self.toolbox.cacheFirst, {
+ cache: {
+ name: staticAssetsCacheName,
+ maxEntries: maxEntries
+ }
+ });
+ // cache dynamic vendor assets, things which have no other update mechanism like filename change/version hash
+ self.toolbox.router.get('/css', self.toolbox.fastest, {
+ origin: /fonts\.googleapis\.com/,
+ cache: {
+ name: dynamicVendorCacheName,
+ maxEntries: maxEntries
+ }
+ });
+ // Do not cache disqus
+ self.toolbox.router.get('/(.*)', self.toolbox.networkOnly, {
+ origin: /disqus\.com/
+ });
+ self.toolbox.router.get('/(.*)', self.toolbox.networkOnly, {
+ origin: /disquscdn\.com/
+ });
+ // Cache all static vendor assets, e.g. fonts whose version is bind to the according url
+ self.toolbox.router.get('/(.*)', self.toolbox.cacheFirst, {
+ origin: /(fonts\.gstatic\.com|www\.google-analytics\.com|www\.googletagmanager\.com|cdnjs\.cloudflare\.com)/,
+ cache: {
+ name: staticVendorCacheName,
+ maxEntries: maxEntries
+ }
+ });
+ self.toolbox.router.get('/(.*)', self.toolbox.cacheFirst, {
+ origin: /(img\.halfrost\.com)/,
+ cache: {
+ name: staticAssetsCacheName,
+ maxEntries: maxEntries
+ }
+ });
+ self.toolbox.router.get('/content/(.*)', self.toolbox.fastest, {
+ cache: {
+ name: contentCacheName,
+ maxEntries: maxEntries
+ }
+ });
+ self.toolbox.router.get('/*', function (request, values, options) {
+ if (!request.url.match(/(\/ghost\/|\/page\/)/) && request.headers.get('accept').includes('text/html')) {
+ return self.toolbox.fastest(request, values, options);
+ } else {
+ // DevTools opening will trigger these o-i-c requests, which this SW can't handle.
+ // There's probaly more going on here, but I'd rather just ignore this problem. :)
+ // https://github.com/paulirish/caltrainschedule.io/issues/49
+ if (request.cache === 'only-if-cached' && request.mode !== 'same-origin'){
+ return;
+ } else {
+ return self.toolbox.networkOnly(request, values, options);
+ }
+ }
+ }, {
+ cache: {
+ name: contentCacheName,
+ maxEntries: maxEntries
+ }
+ });
+ // immediately activate this serviceworker
+ self.addEventListener('install', function (event) {
+ return event.waitUntil(self.skipWaiting());
+ });
+ self.addEventListener('activate', function (event) {
+ return event.waitUntil(self.clients.claim());
+ });
+})();
+//# sourceMappingURL=serviceworker-v1.js.map
diff --git a/website/themes/book/layouts/partials/docs/footer.html b/website/themes/book/layouts/partials/docs/footer.html
index 048e2bba..afffc249 100644
--- a/website/themes/book/layouts/partials/docs/footer.html
+++ b/website/themes/book/layouts/partials/docs/footer.html
@@ -22,6 +22,6 @@
{{ end }}
{{ partial "docs/gitalk.html" . }}
-本站总访问量: 次
-您是本站第 位访问者
+本站总访问量: 次
+您是本站第 位访问者
diff --git a/website/themes/book/layouts/partials/docs/html-head.html b/website/themes/book/layouts/partials/docs/html-head.html
index bc6a9d51..cc915d0e 100644
--- a/website/themes/book/layouts/partials/docs/html-head.html
+++ b/website/themes/book/layouts/partials/docs/html-head.html
@@ -26,8 +26,24 @@
{{ end -}}
{{- if .Site.Params.BookServiceWorker }}
-{{- $swJS := resources.Get "sw-register.js" | resources.ExecuteAsTemplate "sw.js" . | resources.Minify | resources.Fingerprint }}
-
+
+{{- $swJS := resources.Get "serviceworker-v1.js" | resources.Minify | resources.Fingerprint }}
+
{{ end -}}
diff --git a/website/themes/book/layouts/partials/docs/inject/head.html b/website/themes/book/layouts/partials/docs/inject/head.html
index edca74ec..83617b7f 100644
--- a/website/themes/book/layouts/partials/docs/inject/head.html
+++ b/website/themes/book/layouts/partials/docs/inject/head.html
@@ -1,9 +1,11 @@
-
+
+
+