Computer science is no more about computers than astronomy is about telescopes. — E. W. Dijkstra
Welcome! This repository contains my solutions to LeetCode problems, implemented in Go and Python.
Each problem is organized by language and directory. Solutions include clean code, unit tests, and concise explanations where appropriate.
- 📂
go/— Go solutions - 📂
python/— Python solutions
Feel free to explore, learn, and discuss. Contributions and suggestions are always welcome!
- Linked List: traversal, reversal, merging, cycle detection
- Binary Tree: level order(max/min depth, symmetric tree), preorder/inorder/postorder traversal (both recursive and iterative), inversion, lowest common ancestor, merge two binary trees
- Sorting: quick sort, merge sort, insertion sort, selection sort, bubble sort, heap sort
- Binary Search: on sorted arrays, binary trees
- Bit Manipulation Techniques:
- XOR (
^): find numbers that appear only once or twice. - AND (&):
n & (n-1): removes the lowest set bit, commonly used to check if a number is a power of 2.n & -n: gets the lowest set bit.
<<and>>: efficient multiplication and division by 2.- Use XOR to find the unique unpaired number.
- XOR (
- Math Techniques: fast exponentiation, GCD/LCM, elementary math simulation
- Hash table: trading space for time
- Two pointers: fast/slow pointers, left/right pointers (collision pointers), sliding window
- DFS: using a stack
- BFS/backtracking: using a queue
- Dynamic Programming (DP)
- Arrays & Strings
- 1. Two Sum
- 121. Best Time to Buy and Sell Stock
- 189. Rotate Array
- 217. Contains Duplicate
- 238. Product of Array Except Self
- 3. Longest Substring Without Repeating Characters
- 125. Valid Palindrome
- Linked Lists
- 206. Reverse Linked List
- 21. Merge Two Sorted Lists
- 141. Linked List Cycle
- 19. Remove Nth Node From End of List
- 234. Palindrome Linked List
- Stacks & Queues
- Hash Tables
- Binary Search
- 704. Binary Search
- 35. Search Insert Position
- 153. Find Minimum in Rotated Sorted Array
- 33. Search in Rotated Sorted Array
- Dynamic Programming
- 70. Climbing Stairs
- 53. Maximum Subarray
- 322. Coin Change
- 300. Longest Increasing Subsequence
- 72. Edit Distance
- Backtracking
- Trees & Recursion
- 104. Maximum Depth of Binary Tree
- 226. Invert Binary Tree
- 101. Symmetric Tree
- 102. Binary Tree Level Order Traversal
- 235. Lowest Common Ancestor of a BST
- Graphs (BFS & DFS)
- Greedy Algorithms
- Math & Bit Manipulation
- 中英双语文档
- 每个题目分析平均、最好、最坏时间复杂度
- 每个题目分析不同解法的优缺点
- 使用 Python 求解