The project's README from github.com/halfrost/LeetCode-Go. As one markdown file: README.md.
English | 中文
LeetCode Online Judge 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. Please feel free to reference and STAR to support this repo, thank you!

The solution e-book LeetCode Cookbook, with Progressive Web App and Dark Mode support — Online Reading
Offline PDF edition of the e-book LeetCode Cookbook — Download here
Install the PWA edition of LeetCode Cookbook to your home screen from an iOS / Android browser and study anytime.
Topics marked with ✅ have all their problems completed; those without the mark still have problems left to solve.
| Data Structure | Variants | Related Problems | Articles |
|---|---|---|---|
| Sequential list: vector | |||
| Singly linked list | 1. Doubly linked list 2. Static linked list 3. Symmetric matrix 4. Sparse matrix |
||
| Hash table | 1. Hash functions 2. Collision resolution / load factor |
||
| Stack and queue | 1. Generalized stack 2. Deque |
||
| Queue | 1. Linked-list implementation 2. Circular-array implementation 3. Deque |
||
| String | 1. KMP algorithm 2. Finite-state automaton 3. Pattern-matching finite-state automaton 4. Boyer-Moore (BM) algorithm 5. BM-KMP algorithm 6. Brute-force (BF) algorithm |
||
| Tree | 1. Binary tree 2. Union-Find (disjoint set) 3. Huffman tree |
||
| Array-based heap | 1. Max-heap and min-heap 2. Min-max heap 3. Double-ended heap (deap) 4. d-ary heap |
||
| Tree-based heap | 1. Leftist heap 2. Skew heap 3. Binomial heap 4. Fibonacci heap 5. Pairing heap |
||
| Search | 1. Hash table 2. Skip list 3. Binary search tree 4. AVL tree 5. B-tree / B+ tree / B* tree 6. AA tree 7. Red-black tree 8. Sorted binary heap 9. Splay tree 10. Double-chained tree 11. Trie 12. R-tree |
| Algorithm | Specific Types | Related Problems | Articles |
|---|---|---|---|
| Sorting algorithms | 1. Bubble sort 2. Insertion sort 3. Selection sort 4. Shell sort 5. Quicksort 6. Merge sort 7. Heap sort 8. Linear-time sorting 9. Introsort 10. Indirect sort 11. Counting sort 12. Radix sort 13. Bucket sort 14. External sort - k-way merge with a loser tree 15. External sort - optimal merge tree |
||
| Recursion & divide and conquer | 1. Binary search 2. Multiplication of large integers 3. Strassen's matrix multiplication 4. Chessboard covering 5. Merge sort 6. Quicksort 7. Linear-time selection 8. Closest pair of points 9. Round-robin tournament scheduling |
||
| Dynamic programming | 1. Matrix-chain multiplication 2. Longest common subsequence 3. Maximum subarray sum 4. Optimal triangulation of a convex polygon 5. The polygon game 6. Image compression 7. Circuit wiring 8. Flow-shop scheduling 9. 0-1 knapsack / the "nine knapsack lectures" 10. Optimal binary search tree 11. DP speed-up principles 12. Tree DP |
||
| Greedy | 1. Activity-selection problem 2. Optimal loading 3. Huffman coding 4. Single-source shortest paths 5. Minimum spanning tree 6. Multi-machine scheduling |
||
| Backtracking | 1. Loading problem 2. Batch-job scheduling 3. Sign-of-triangle problem 4. n-queens problem 5. 0-1 knapsack 6. Maximum-clique problem 7. Graph m-coloring problem 8. Traveling-salesman problem 9. Circle-arrangement problem 10. Circuit-board placement problem 11. Consecutive-postage problem |
||
| Search | 1. Enumeration 2. DFS 3. BFS 4. Heuristic search |
||
| Randomization | 1. Random numbers 2. Numerical randomized algorithms 3. Sherwood algorithm 4. Las Vegas algorithm 5. Monte Carlo algorithm |
1. Computing the value of π 2. Computing definite integrals 3. Solving nonlinear systems 4. Linear-time selection 5. Skip list 6. n-queens problem 7. Integer factorization 8. Majority-element problem 9. Primality testing |
|
| Graph theory | 1. Traversal: DFS / BFS 2. AOV / AOE networks 3. Kruskal's algorithm (MST) 4. Prim's algorithm (MST) 5. Borůvka's algorithm (MST) 6. Dijkstra's algorithm (single-source shortest path) 7. Bellman-Ford algorithm (single-source shortest path) 8. SPFA algorithm (single-source shortest path) 9. Floyd algorithm (all-pairs shortest path) 10. Johnson's algorithm (all-pairs shortest path) 11. Fleury's algorithm (Eulerian circuit) 12. Ford-Fulkerson algorithm (max-flow augmenting path) 13. Edmonds-Karp algorithm (max flow) 14. Dinic's algorithm (max flow) 15. Generic push-relabel algorithm 16. Highest-label push-relabel (HLPP) algorithm 17. Primal-Dual algorithm (min-cost flow)18. Kosaraju's algorithm (strongly connected components) 19. Tarjan's algorithm (strongly connected components) 20. Gabow's algorithm (strongly connected components) 21. Hungarian algorithm (bipartite matching) 22. Hopcroft-Karp algorithm (bipartite matching) 23. Kuhn-Munkres algorithm (optimal bipartite matching) 24. Edmonds' Blossom-Contraction algorithm (general graph matching) |
1. Graph traversal 2. Strong/weak connectivity of directed and undirected graphs 3. Cut vertices / cut edges 3. AOV networks and topological sorting 4. AOE networks and the critical path 5. Minimum-cost spanning tree / second-best MST 6. Shortest-path problem / K-th shortest path 7. Maximum-flow problem 8. Minimum-cost flow problem 9. Graph-coloring problem 10. System of difference constraints 11. Eulerian circuit 12. Chinese postman problem 13. Hamiltonian cycle 14. Best edge/vertex cut set / minimum edge/vertex cut set / minimum path cover / minimum vertex cover 15. Edge cover set 16. Bipartite perfect matching and maximum matching 17. Cactus graph 18. Chordal graph 19. Stable-marriage problem 20. Maximum-clique problem |
|
| Number theory | 1. Greatest common divisor 2. Least common multiple 3. Prime factorization 4. Primality testing 5. Base conversion 6. Arbitrary-precision arithmetic 7. Divisibility 8. Congruences 9. Euler's totient function 10. Extended Euclidean algorithm 11. Permutation groups 12. Generating functions 13. Discrete transforms 14. Cantor expansion 15. Matrices 16. Vectors 17. Systems of linear equations 18. Linear programming |
||
| Geometry | 1. Convex hull - gift wrapping 2. Convex hull - Graham scan 3. Line-segment problems 4. Problems on polygons and polyhedra |
||
| NP-completeness | 1. Computation models 2. Class-P and class-NP problems 3. NP-complete problems 4. Approximation algorithms for NP-complete problems |
1. Random-access machine (RAM) 2. Random-access stored-program machine (RASP) 3. Turing machine 4. Non-deterministic Turing machine 5. Class-P and class-NP languages 6. Polynomial-time verification 7. Polynomial-time reduction 8. Cook's theorem 9. CNF satisfiability (CNF-SAT) 10. 3-CNF satisfiability (3-SAT) 11. Clique problem (CLIQUE) 12. Vertex-cover problem (VERTEX-COVER) 13. Subset-sum problem (SUBSET-SUM) 14. Hamiltonian-cycle problem (HAM-CYCLE) 15. Traveling-salesman problem (TSP) 16. Approximation algorithm for vertex cover 17. Approximation algorithm for TSP 18. TSP with the triangle inequality 19. General TSP 20. Approximation algorithm for set cover 21. Approximation algorithm for subset sum 22. Exponential-time algorithm for subset sum 23. Polynomial-time approximation scheme for subset sum |
| Easy | Medium | Hard | Total | |
|---|---|---|---|---|
| Optimizing | 31 | 78 | 43 | 152 |
| Accepted | 287 | 484 | 142 | 913 |
| Total | 600 | 1305 | 539 | 2444 |
| Perfection Rate | 89.2% | 83.9% | 69.7% | 83.4% |
| Completion Rate | 47.8% | 37.1% | 26.3% | 37.4% |
787 problems already have solutions here; another 11 are still being optimized toward beats 100%.
| No. | Title | Solution | Acceptance | Difficulty | Frequency |
|---|---|---|---|---|---|
| 0001 | Two Sum | Go | 49.1% | Easy | |
| 0002 | Add Two Numbers | Go | 39.7% | Medium | |
| 0003 | Longest Substring Without Repeating Characters | Go | 33.8% | Medium | |
| 0004 | Median of Two Sorted Arrays | Go | 35.1% | Hard | |
| 0005 | Longest Palindromic Substring | Go | 32.4% | Medium | |
| 0006 | Zigzag Conversion | Go | 43.0% | Medium | |
| 0007 | Reverse Integer | Go | 27.2% | Medium | |
| 0008 | String to Integer (atoi) | Go | 16.6% | Medium | |
| 0009 | Palindrome Number | Go | 52.8% | Easy | |
| 0010 | Regular Expression Matching | 28.3% | Hard | ||
| 0011 | Container With Most Water | Go | 54.3% | Medium | |
| 0012 | Integer to Roman | Go | 60.5% | Medium | |
| 0013 | Roman to Integer | Go | 58.2% | Easy | |
| 0014 | Longest Common Prefix | Go | 40.7% | Easy | |
| 0015 | 3Sum | Go | 32.2% | Medium | |
| 0016 | 3Sum Closest | Go | 46.2% | Medium | |
| 0017 | Letter Combinations of a Phone Number | Go | 55.5% | Medium | |
| 0018 | 4Sum | Go | 36.5% | Medium | |
| 0019 | Remove Nth Node From End of List | Go | 39.9% | Medium | |
| 0020 | Valid Parentheses | Go | 40.7% | Easy | |
| 0021 | Merge Two Sorted Lists | Go | 61.8% | Easy | |
| 0022 | Generate Parentheses | Go | 71.7% | Medium | |
| 0023 | Merge k Sorted Lists | Go | 48.3% | Hard | |
| 0024 | Swap Nodes in Pairs | Go | 60.3% | Medium | |
| 0025 | Reverse Nodes in k-Group | Go | 53.4% | Hard | |
| 0026 | Remove Duplicates from Sorted Array | Go | 50.3% | Easy | |
| 0027 | Remove Element | Go | 52.0% | Easy | |
| 0028 | Find the Index of the First Occurrence in a String | Go | 37.4% | Medium | |
| 0029 | Divide Two Integers | Go | 17.4% | Medium | |
| 0030 | Substring with Concatenation of All Words | Go | 30.9% | Hard | |
| 0031 | Next Permutation | Go | 37.1% | Medium | |
| 0032 | Longest Valid Parentheses | Go | 32.7% | Hard | |
| 0033 | Search in Rotated Sorted Array | Go | 38.6% | Medium | |
| 0034 | Find First and Last Position of Element in Sorted Array | Go | 41.5% | Medium | |
| 0035 | Search Insert Position | Go | 42.0% | Easy | |
| 0036 | Valid Sudoku | Go | 56.7% | Medium | |
| 0037 | Sudoku Solver | Go | 56.6% | Hard | |
| 0038 | Count and Say | 51.1% | Medium | ||
| 0039 | Combination Sum | Go | 67.5% | Medium | |
| 0040 | Combination Sum II | Go | 53.3% | Medium | |
| 0041 | First Missing Positive | Go | 36.5% | Hard | |
| 0042 | Trapping Rain Water | Go | 58.7% | Hard | |
| 0043 | Multiply Strings | Go | 38.7% | Medium | |
| 0044 | Wildcard Matching | 26.8% | Hard | ||
| 0045 | Jump Game II | Go | 38.5% | Medium | |
| 0046 | Permutations | Go | 74.6% | Medium | |
| 0047 | Permutations II | Go | 56.6% | Medium | |
| 0048 | Rotate Image | Go | 69.8% | Medium | |
| 0049 | Group Anagrams | Go | 65.9% | Medium | |
| 0050 | Pow(x, n) | Go | 32.8% | Medium | |
| 0051 | N-Queens | Go | 62.8% | Hard | |
| 0052 | N-Queens II | Go | 70.8% | Hard | |
| 0053 | Maximum Subarray | [Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/00 |