leetcode golang.pdf
⽬录
说明
⽬录
第⼀章 序章
数据结构知识
算法知识
第⼆章 算法专题
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
第三章 ⼀些模板
线段树 Segment Tree
并查集 UnionFind
最近最少使⽤ LRUCache
最不经常最少使⽤ LFUCache
第四章 LeetCode 题解
1. Two Sum
2. Add Two Numbers
3. Longest Substring Without Repeating Characters
4. Median of Two Sorted Arrays
7. Reverse Integer
9. Palindrome Number
11. Container With Most Water
13. Roman to Integer
15. 3Sum
16. 3Sum Closest
17. Letter Combinations of a Phone Number
18. 4Sum
19. Remove Nth Node From End of List
20. Valid Parentheses
21. Merge Two Sorted Lists
22. Generate Parentheses
23. Merge k Sorted Lists
24. Swap Nodes in Pairs
25. Reverse Nodes in k-Group
26. Remove Duplicates from Sorted Array
27. Remove Element
28. Implement strStr()
29. Divide Two Integers
30. Substring with Concatenation of All Words
31. Next Permutation
33. Search in Rotated Sorted Array
34. Find First and Last Position of Element in Sorted Array
35. Search Insert Position
36. Valid Sudoku
37. Sudoku Solver
39. Combination Sum
40. Combination Sum II
41. First Missing Positive
42. Trapping Rain Water
46. Permutations
47. Permutations II
48. Rotate Image
49. Group Anagrams
50. Pow(x, n)
51. N-Queens
52. N-Queens II
53. Maximum Subarray
54. Spiral Matrix
55. Jump Game
56. Merge Intervals
57. Insert Interval
59. Spiral Matrix II
60. Permutation Sequence
61. Rotate List
62. Unique Paths
63. Unique Paths II
64. Minimum Path Sum
66. Plus One
67. Add Binary
69. Sqrt(x)
70. Climbing Stairs
71. Simplify Path
74. Search a 2D Matrix
75. Sort Colors
76. Minimum Window Substring
77. Combinations
78. Subsets
79. Word Search
80. Remove Duplicates from Sorted Array II
81. Search in Rotated Sorted Array II
82. Remove Duplicates from Sorted List II
83. Remove Duplicates from Sorted List
84. Largest Rectangle in Histogram
86. Partition List
88. Merge Sorted Array
89. Gray Code
90. Subsets II
91. Decode Ways
92. Reverse Linked List II
93. Restore IP Addresses
94. Binary Tree Inorder Traversal
95. Unique Binary Search Trees II
96. Unique Binary Search Trees
98. Validate Binary Search Tree
99. Recover Binary Search Tree
100. Same Tree
101. Symmetric Tree
102. Binary Tree Level Order Traversal
103. Binary Tree Zigzag Level Order Traversal
104. Maximum Depth of Binary Tree
105. Construct Binary Tree from Preorder and Inorder Traversal
106. Construct Binary Tree from Inorder and Postorder Traversal
107. Binary Tree Level Order Traversal II
108. Convert Sorted Array to Binary Search Tree
109. Convert Sorted List to Binary Search Tree
110. Balanced Binary Tree
111. Minimum Depth of Binary Tree
112. Path Sum
113. Path Sum II
114. Flatten Binary Tree to Linked List
118. Pascal's Triangle
119. Pascal's Triangle II
120. Triangle
121. Best Time to Buy and Sell Stock
122. Best Time to Buy and Sell Stock II
124. Binary Tree Maximum Path Sum
125. Valid Palindrome
126. Word Ladder II
127. Word Ladder
128. Longest Consecutive Sequence
129. Sum Root to Leaf Numbers
130. Surrounded Regions
131. Palindrome Partitioning
136. Single Number
137. Single Number II
138. Copy List with Random Pointer
141. Linked List Cycle
142. Linked List Cycle II
143. Reorder List
144. Binary Tree Preorder Traversal
145. Binary Tree Postorder Traversal
146. LRU Cache
147. Insertion Sort List
148. Sort List
150. Evaluate Reverse Polish Notation
151. Reverse Words in a String
152. Maximum Product Subarray
153. Find Minimum in Rotated Sorted Array
154. Find Minimum in Rotated Sorted Array II
155. Min Stack
160. Intersection of Two Linked Lists
162. Find Peak Element
164. Maximum Gap
167. Two Sum II - Input array is sorted
168. Excel Sheet Column Title
169. Majority Element
171. Excel Sheet Column Number
172. Factorial Trailing Zeroes
173. Binary Search Tree Iterator
174. Dungeon Game
179. Largest Number
187. Repeated DNA Sequences
189. Rotate Array
190. Reverse Bits
191. Number of 1 Bits
198. House Robber
199. Binary Tree Right Side View
200. Number of Islands
201. Bitwise AND of Numbers Range
202. Happy Number
203. Remove Linked List Elements
204. Count Primes
205. Isomorphic Strings
206. Reverse Linked List
207. Course Schedule
208. Implement Trie (Prefix Tree)
209. Minimum Size Subarray Sum
210. Course Schedule II
211. Design Add and Search Words Data Structure
212. Word Search II
213. House Robber II
215. Kth Largest Element in an Array
216. Combination Sum III
217. Contains Duplicate
218. The Skyline Problem
219. Contains Duplicate II
220. Contains Duplicate III
222. Count Complete Tree Nodes
223. Rectangle Area
224. Basic Calculator
225. Implement Stack using Queues
226. Invert Binary Tree
228. Summary Ranges
229. Majority Element II
230. Kth Smallest Element in a BST
231. Power of Two
232. Implement Queue using Stacks
234. Palindrome Linked List
235. Lowest Common Ancestor of a Binary Search Tree
236. Lowest Common Ancestor of a Binary Tree
237. Delete Node in a Linked List
239. Sliding Window Maximum
240. Search a 2D Matrix II
242. Valid Anagram
257. Binary Tree Paths
258. Add Digits
260. Single Number III
263. Ugly Number
268. Missing Number
274. H-Index
275. H-Index II
283. Move Zeroes
284. Peeking Iterator
287. Find the Duplicate Number
290. Word Pattern
300. Longest Increasing Subsequence
303. Range Sum Query - Immutable
306. Additive Number
307. Range Sum Query - Mutable
309. Best Time to Buy and Sell Stock with Cooldown
315. Count of Smaller Numbers After Self
318. Maximum Product of Word Lengths
322. Coin Change
324. Wiggle Sort II
326. Power of Three
327. Count of Range Sum
328. Odd Even Linked List
329. Longest Increasing Path in a Matrix
331. Verify Preorder Serialization of a Binary Tree
337. House Robber III
338. Counting Bits
342. Power of Four
343. Integer Break
344. Reverse String
345. Reverse Vowels of a String
347. Top K Frequent Elements
349. Intersection of Two Arrays
350. Intersection of Two Arrays II
354. Russian Doll Envelopes
357. Count Numbers with Unique Digits
367. Valid Perfect Square
371. Sum of Two Integers
372. Super Pow
373. Find K Pairs with Smallest Sums
378. Kth Smallest Element in a Sorted Matrix
385. Mini Parser
386. Lexicographical Numbers
387. First Unique Character in a String
389. Find the Difference
392. Is Subsequence
393. UTF-8 Validation
394. Decode String
397. Integer Replacement
399. Evaluate Division
401. Binary Watch
402. Remove K Digits
404. Sum of Left Leaves
405. Convert a Number to Hexadecimal
409. Longest Palindrome
410. Split Array Largest Sum
412. Fizz Buzz
414. Third Maximum Number
416. Partition Equal Subset Sum
421. Maximum XOR of Two Numbers in an Array
424. Longest Repeating Character Replacement
433. Minimum Genetic Mutation
435. Non-overlapping Intervals
436. Find Right Interval
437. Path Sum III
438. Find All Anagrams in a String
441. Arranging Coins
445. Add Two Numbers II
447. Number of Boomerangs
448. Find All Numbers Disappeared in an Array
451. Sort Characters By Frequency
453. Minimum Moves to Equal Array Elements
454. 4Sum II
455. Assign Cookies
456. 132 Pattern
457. Circular Array Loop
460. LFU Cache
461. Hamming Distance
463. Island Perimeter
470. Implement Rand10() Using Rand7()
474. Ones and Zeroes
475. Heaters
476. Number Complement
477. Total Hamming Distance
480. Sliding Window Median
483. Smallest Good Base
485. Max Consecutive Ones
491. Increasing Subsequences
493. Reverse Pairs
494. Target Sum
496. Next Greater Element I
497. Random Point in Non-overlapping Rectangles
498. Diagonal Traverse
500. Keyboard Row
503. Next Greater Element II
507. Perfect Number
508. Most Frequent Subtree Sum
509. Fibonacci Number
513. Find Bottom Left Tree Value
515. Find Largest Value in Each Tree Row
524. Longest Word in Dictionary through Deleting
526. Beautiful Arrangement
528. Random Pick with Weight
529. Minesweeper
532. K-diff Pairs in an Array
537. Complex Number Multiplication
538. Convert BST to Greater Tree
541. Reverse String II
542. 01 Matrix
547. Number of Provinces
557. Reverse Words in a String III
561. Array Partition I
563. Binary Tree Tilt
566. Reshape the Matrix
567. Permutation in String
572. Subtree of Another Tree
575. Distribute Candies
594. Longest Harmonious Subsequence
598. Range Addition II
599. Minimum Index Sum of Two Lists
605. Can Place Flowers
628. Maximum Product of Three Numbers
632. Smallest Range Covering Elements from K Lists
633. Sum of Square Numbers
636. Exclusive Time of Functions
637. Average of Levels in Binary Tree
638. Shopping Offers
643. Maximum Average Subarray I
645. Set Mismatch
648. Replace Words
653. Two Sum IV - Input is a BST
658. Find K Closest Elements
661. Image Smoother
662. Maximum Width of Binary Tree
665. Non-decreasing Array
668. Kth Smallest Number in Multiplication Table
669. Trim a Binary Search Tree
674. Longest Continuous Increasing Subsequence
676. Implement Magic Dictionary
682. Baseball Game
684. Redundant Connection
685. Redundant Connection II
693. Binary Number with Alternating Bits
695. Max Area of Island
697. Degree of an Array
699. Falling Squares
703. Kth Largest Element in a Stream
704. Binary Search
705. Design HashSet
706. Design HashMap
707. Design Linked List
710. Random Pick with Blacklist
713. Subarray Product Less Than K
714. Best Time to Buy and Sell Stock with Transaction Fee
715. Range Module
717. 1-bit and 2-bit Characters
718. Maximum Length of Repeated Subarray
719. Find K-th Smallest Pair Distance
720. Longest Word in Dictionary
721. Accounts Merge
724. Find Pivot Index
725. Split Linked List in Parts
726. Number of Atoms
729. My Calendar I
732. My Calendar III
733. Flood Fill
735. Asteroid Collision
739. Daily Temperatures
744. Find Smallest Letter Greater Than Target
745. Prefix and Suffix Search
746. Min Cost Climbing Stairs
748. Shortest Completing Word
753. Cracking the Safe
756. Pyramid Transition Matrix
762. Prime Number of Set Bits in Binary Representation
763. Partition Labels
765. Couples Holding Hands
766. Toeplitz Matrix
767. Reorganize String
771. Jewels and Stones
778. Swim in Rising Water
781. Rabbits in Forest
784. Letter Case Permutation
785. Is Graph Bipartite?
786. K-th Smallest Prime Fraction
793. Preimage Size of Factorial Zeroes Function
802. Find Eventual Safe States
803. Bricks Falling When Hit
811. Subdomain Visit Count
812. Largest Triangle Area
815. Bus Routes
817. Linked List Components
819. Most Common Word
821. Shortest Distance to a Character
826. Most Profit Assigning Work
828. Count Unique Characters of All Substrings of a Given String
830. Positions of Large Groups
832. Flipping an Image
834. Sum of Distances in Tree
836. Rectangle Overlap
838. Push Dominoes
839. Similar String Groups
841. Keys and Rooms
842. Split Array into Fibonacci Sequence
844. Backspace String Compare
845. Longest Mountain in Array
850. Rectangle Area II
851. Loud and Rich
852. Peak Index in a Mountain Array
853. Car Fleet
856. Score of Parentheses
862. Shortest Subarray with Sum at Least K
863. All Nodes Distance K in Binary Tree
864. Shortest Path to Get All Keys
867. Transpose Matrix
872. Leaf-Similar Trees
875. Koko Eating Bananas
876. Middle of the Linked List
878. Nth Magical Number
880. Decoded String at Index
881. Boats to Save People
884. Uncommon Words from Two Sentences
885. Spiral Matrix III
887. Super Egg Drop
888. Fair Candy Swap
891. Sum of Subsequence Widths
892. Surface Area of 3D Shapes
895. Maximum Frequency Stack
896. Monotonic Array
897. Increasing Order Search Tree
898. Bitwise ORs of Subarrays
901. Online Stock Span
904. Fruit Into Baskets
907. Sum of Subarray Minimums
910. Smallest Range II
911. Online Election
914. X of a Kind in a Deck of Cards
918. Maximum Sum Circular Subarray
920. Number of Music Playlists
921. Minimum Add to Make Parentheses Valid
922. Sort Array By Parity II
923. 3Sum With Multiplicity
924. Minimize Malware Spread
925. Long Pressed Name
927. Three Equal Parts
928. Minimize Malware Spread II
930. Binary Subarrays With Sum
933. Number of Recent Calls
942. DI String Match
946. Validate Stack Sequences
947. Most Stones Removed with Same Row or Column
949. Largest Time for Given Digits
952. Largest Component Size by Common Factor
953. Verifying an Alien Dictionary
959. Regions Cut By Slashes
961. N-Repeated Element in Size 2N Array
968. Binary Tree Cameras
969. Pancake Sorting
970. Powerful Integers
973. K Closest Points to Origin
976. Largest Perimeter Triangle
977. Squares of a Sorted Array
978. Longest Turbulent Subarray
979. Distribute Coins in Binary Tree
980. Unique Paths III
981. Time Based Key-Value Store
984. String Without AAA or BBB
985. Sum of Even Numbers After Queries
986. Interval List Intersections
987. Vertical Order Traversal of a Binary Tree
989. Add to Array-Form of Integer
990. Satisfiability of Equality Equations
992. Subarrays with K Different Integers
993. Cousins in Binary Tree
995. Minimum Number of K Consecutive Bit Flips
996. Number of Squareful Arrays
999. Available Captures for Rook
1002. Find Common Characters
1003. Check If Word Is Valid After Substitutions
1004. Max Consecutive Ones III
1005. Maximize Sum Of Array After K Negations
1011. Capacity To Ship Packages Within D Days
1017. Convert to Base -2
1018. Binary Prefix Divisible By 5
1019. Next Greater Node In Linked List
1020. Number of Enclaves
1021. Remove Outermost Parentheses
1025. Divisor Game
1026. Maximum Difference Between Node and Ancestor
1028. Recover a Tree From Preorder Traversal
1030. Matrix Cells in Distance Order
1037. Valid Boomerang
1038. Binary Search Tree to Greater Sum Tree
1040. Moving Stones Until Consecutive II
1047. Remove All Adjacent Duplicates In String
1049. Last Stone Weight II
1051. Height Checker
1052. Grumpy Bookstore Owner
1054. Distant Barcodes
1073. Adding Two Negabinary Numbers
1074. Number of Submatrices That Sum to Target
1078. Occurrences After Bigram
1079. Letter Tile Possibilities
1089. Duplicate Zeros
1091. Shortest Path in Binary Matrix
1093. Statistics from a Large Sample
1105. Filling Bookcase Shelves
1108. Defanging an IP Address
1110. Delete Nodes And Return Forest
1111. Maximum Nesting Depth of Two Valid Parentheses Strings
1122. Relative Sort Array
1123. Lowest Common Ancestor of Deepest Leaves
1128. Number of Equivalent Domino Pairs
1137. N-th Tribonacci Number
1145. Binary Tree Coloring Game
1154. Day of the Year
1157. Online Majority Element In Subarray
1160. Find Words That Can Be Formed by Characters
1170. Compare Strings by Frequency of the Smallest Character
1171. Remove Zero Sum Consecutive Nodes from Linked List
1175. Prime Arrangements
1184. Distance Between Bus Stops
1185. Day of the Week
1189. Maximum Number of Balloons
1200. Minimum Absolute Difference
1201. Ugly Number III
1202. Smallest String With Swaps
1203. Sort Items by Groups Respecting Dependencies
1207. Unique Number of Occurrences
1208. Get Equal Substrings Within Budget
1217. Minimum Cost to Move Chips to The Same Position
1221. Split a String in Balanced Strings
1232. Check If It Is a Straight Line
1234. Replace the Substring for Balanced String
1235. Maximum Profit in Job Scheduling
1252. Cells with Odd Values in a Matrix
1254. Number of Closed Islands
1260. Shift 2D Grid
1266. Minimum Time Visiting All Points
1275. Find Winner on a Tic Tac Toe Game
1281. Subtract the Product and Sum of Digits of an Integer
1283. Find the Smallest Divisor Given a Threshold
1287. Element Appearing More Than 25% In Sorted Array
1290. Convert Binary Number in a Linked List to Integer
1295. Find Numbers with Even Number of Digits
1299. Replace Elements with Greatest Element on Right Side
1300. Sum of Mutated Array Closest to Target
1302. Deepest Leaves Sum
1304. Find N Unique Integers Sum up to Zero
1305. All Elements in Two Binary Search Trees
1306. Jump Game III
1313. Decompress Run-Length Encoded List
1317. Convert Integer to the Sum of Two No-Zero Integers
1319. Number of Operations to Make Network Connected
1329. Sort the Matrix Diagonally
1380. Lucky Numbers in a Matrix
1385. Find the Distance Value Between Two Arrays
1389. Create Target Array in the Given Order
1423. Maximum Points You Can Obtain from Cards
1437. Check If All 1's Are at Least Length K Places Away
1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows
1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence
1463. Cherry Pickup II
1464. Maximum Product of Two Elements in an Array
1470. Shuffle the Array
1480. Running Sum of 1d Array
1512. Number of Good Pairs
1539. Kth Missing Positive Number
1573. Number of Ways to Split a String
1579. Remove Max Number of Edges to Keep Graph Fully Traversable
1603. Design Parking System
1608. Special Array With X Elements Greater Than or Equal X
1614. Maximum Nesting Depth of the Parentheses
1619. Mean of Array After Removing Some Elements
1624. Largest Substring Between Two Equal Characters
1629. Slowest Key
1631. Path With Minimum Effort
1636. Sort Array by Increasing Frequency
1640. Check Array Formation Through Concatenation
1641. Count Sorted Vowel Strings
1646. Get Maximum in Generated Array
1647. Minimum Deletions to Make Character Frequencies Unique
1648. Sell Diminishing-Valued Colored Balls
1649. Create Sorted Array through Instructions
1652. Defuse the Bomb
1653. Minimum Deletions to Make String Balanced
1654. Minimum Jumps to Reach Home
1655. Distribute Repeating Integers
1656. Design an Ordered Stream
1657. Determine if Two Strings Are Close
1658. Minimum Operations to Reduce X to Zero
1659. Maximize Grid Happiness
1662. Check If Two String Arrays are Equivalent
1663. Smallest String With A Given Numeric Value
1664. Ways to Make a Fair Array
1665. Minimum Initial Energy to Finish Tasks
1668. Maximum Repeating Substring
1669. Merge In Between Linked Lists
1670. Design Front Middle Back Queue
1672. Richest Customer Wealth
1673. Find the Most Competitive Subsequence
1674. Minimum Moves to Make Array Complementary
1675. Minimize Deviation in Array
1678. Goal Parser Interpretation
1679. Max Number of K-Sum Pairs
1680. Concatenation of Consecutive Binary Numbers
1681. Minimum Incompatibility
1684. Count the Number of Consistent Strings
1685. Sum of Absolute Differences in a Sorted Array
1688. Count of Matches in Tournament
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers
1690. Stone Game VII
1691. Maximum Height by Stacking Cuboids
1694. Reformat Phone Number
1695. Maximum Erasure Value
1696. Jump Game VI
1700. Number of Students Unable to Eat Lunch
1704. Determine if String Halves Are Alike
1716. Calculate Money in Leetcode Bank
1720. Decode XORed Array
1725. Number Of Rectangles That Can Form The Largest Square
1732. Find the Highest Altitude
1736. Latest Time by Replacing Hidden Digits
1742. Maximum Number of Balls in a Box
1748. Sum of Unique Elements
1752. Check if Array Is Sorted and Rotated
1758. Minimum Changes To Make Alternating Binary String]
评论