我个人的力扣答案, 公众号:GeekPal
这是一个持续更新的开源项目
My personal leetcode answers
This is a continually updated open source project
Total sovled: 338
Auto updated at: 2024-07-10 17:38:49
pip install -r requirements.txt
python problem.py <leetcode/lintcode> [-l java|cpp|python(default)] [-t]
# 例如(e.g.):
python problem.py https://leetcode.com/problems/online-stock-span/
python problem.py https://www.lintcode.com/problem/92 -l cpp
- 《算法技术手册》/ Algorithms in a Nutshell
- 《STL源码剖析》/ The Annotated STL Sources
- 《算法心得:高效算法的奥秘》/ Hacker's Delight, 2nd Edition
- 《数学之美》(A chinese version book by Doctor Wujun)
- 《编程之美 : 微软技术面试心得》(A chinese version book by Mircosoft Developers)
- Math
- Bit Manipulation
- Simulation
- Design
- Binary Search
- Linked List
- Two Pointers
- Sliding Window
- Stack
- Sorting
- Greedy
- Dynamic Programming
- Backtracking
- Divide and Conquer
- Breadth-First Search
- Depth-First Search
- Priority Queue
- Union Find
- Trie
- Segment Tree
Problem(5) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-69. Sqrtx | c++, python | N(logN) | O(1) | - | - |
Leetcode-70. Climbing Stairs | c++, python | O(N) | O(1) | - | - |
Leetcode-263. Ugly Number | c++, python | O(k) | O(1) | - | - |
Leetcode-375. Guess Number Higher Or Lower II | c++, python | O(N^3) | O(N^2) | DP(Index) | - |
Leetcode-633. Sum Of Square Numbers | c++, python | O(N) | O(1) | - | - |
Problem(1) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Lintcode-39. Recover Rotated Sorted Array | c++, python | O(N) | O(1) | Rotated | - |
Problem(2) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-173. Binary Search Tree Iterator | c++, python | O(1) | O(Height) | InOrder | - |
Leetcode-297. Serialize And Deserialize Binary Tree | c++, python | O(N) | O(N) | Serialization | - |
Problem(4) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-114. Flatten Binary Tree To Linked List | c++, python | O(N) | O(Height) | PreOrder | - |
Leetcode-141. Linked List Cycle | c++, python | O(N) | O(1) | - | - |
Leetcode-142. Linked List Cycle II | c++, python | O(N) | O(1) | - | - |
Lintcode-1534. Convert Binary Search Tree To Sorted Doubly Linked List | c++, python | O(N) | O(Height) | BST | Leetcode-426 | - |
Problem(12) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-75. Sort Colors | c++, python | O(N) | O(1) | - | - |
Leetcode-88. Merge Sorted Array | c++, python | O(M + N) | O(1) | - | - |
Leetcode-141. Linked List Cycle | c++, python | O(N) | O(1) | - | - |
Leetcode-142. Linked List Cycle II | c++, python | O(N) | O(1) | - | - |
Leetcode-167. Two Sum Ii Input Array Is Sorted | c++, python | O(N) | O(1) | - | - |
Leetcode-455. Assign Cookies | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-524. Longest Word In Dictionary Through Deleting | c++, python | O(N*logN + M * N) | O(1) | - | - |
Leetcode-633. Sum Of Square Numbers | c++, python | O(N) | O(1) | - | - |
Leetcode-658. Find K Closest Elements | c++, python | O(Log(N - K)) | O(1) | Range | - |
Leetcode-680. Valid Palindrome II | c++, python | O(N) | O(1) | - | - |
Leetcode-763. Partition Labels | c++, python | O(N) | O(N) | - | - |
Lintcode-386. Longest Substring With At Most K Distinct Characters | c++, python | O(N) | O(K) | Leetcode-340 | - |
Problem(2) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-76. Minimum Window Substring | c++, python | O(M) | O(N) | Hash + TP | - |
Leetcode-658. Find K Closest Elements | c++, python | O(Log(N - K)) | O(1) | Range | - |
Problem(6) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-94. Binary Tree Inorder Traversal | c++, python | O(N) | O(Height) | InOrder | - |
Leetcode-114. Flatten Binary Tree To Linked List | c++, python | O(N) | O(Height) | PreOrder | - |
Leetcode-144. Binary Tree Preorder Traversal | c++, python | O(N) | O(Height) | PreOrder | - |
Leetcode-145. Binary Tree Postorder Traversal | c++, python | O(N) | O(Height) | PostOrder | - |
Leetcode-173. Binary Search Tree Iterator | c++, python | O(1) | O(Height) | InOrder | - |
Leetcode-1249. Minimum Remove To Make Valid Parentheses | c++, python | O(N) | O(N) | - | - |
Problem(12) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-75. Sort Colors | c++, python | O(N) | O(1) | - | - |
Leetcode-88. Merge Sorted Array | c++, python | O(M + N) | O(1) | - | - |
Leetcode-215. Kth Largest Element In An Array | c++, python | O(N) ~ O(N^2) | O(1) | QuickSelection | - |
Leetcode-347. Top K Frequent Elements | c++, python | O(N), O(C*logK) | O(N) | - | - |
Leetcode-406. Queue Reconstruction By Height | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-435. Non Overlapping Intervals | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-451. Sort Characters By Frequency | c++, python | O(N) | O(N) | - | - |
Leetcode-452. Minimum Number Of Arrows To Burst Balloons | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-455. Assign Cookies | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-524. Longest Word In Dictionary Through Deleting | c++, python | O(N*logN + M * N) | O(1) | - | - |
Leetcode-658. Find K Closest Elements | c++, python | O(Log(N - K)) | O(1) | Range | - |
Lintcode-39. Recover Rotated Sorted Array | c++, python | O(N) | O(1) | Rotated | - |
Problem(9) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-122. Best Time To Buy And Sell Stock II | c++, python | O(N) | O(1) | - | - |
Leetcode-135. Candy | c++, python | O(N) | O(N) | - | - |
Leetcode-435. Non Overlapping Intervals | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-452. Minimum Number Of Arrows To Burst Balloons | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-455. Assign Cookies | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-605. Can Place Flowers | c++, python | O(N) | O(N) | - | - |
Leetcode-680. Valid Palindrome II | c++, python | O(N) | O(1) | - | - |
Leetcode-763. Partition Labels | c++, python | O(N) | O(N) | - | - |
Leetcode-3048. Earliest Second To Mark Indices I | c++, python | O(M*logM) | O(M) | - | - |
Problem(13) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-64. Minimum Path Sum | c++, python | O(MN) | O(MN) | - | - |
Leetcode-70. Climbing Stairs | c++, python | O(N) | O(1) | - | - |
Leetcode-120. Triangle | c++, python | O(N^2) | O(N) | - | - |
Leetcode-122. Best Time To Buy And Sell Stock II | c++, python | O(N) | O(1) | - | - |
Leetcode-198. House Robber | c++, python | O(N) | O(N) | - | - |
Leetcode-221. Maximal Square | c++, python | O(MN) | O(MN) | - | - |
Leetcode-300. Longest Increasing Subsequence | c++, python | O(N*logN) | O(N) | LIS | std::lower_bound | - |
Leetcode-322. Coin Change | c++, python | O(K * N) | O(N) | Index | Video |
Leetcode-375. Guess Number Higher Or Lower II | c++, python | O(N^3) | O(N^2) | DP(Index) | - |
Leetcode-413. Arithmetic Slices | c++, python | O(N) | O(N) | - | - |
Leetcode-435. Non Overlapping Intervals | c++, python | O(N * logN) | O(1) | - | - |
Leetcode-542. 01 Matrix | c++, python | O(MN) | O(MN) | - | - |
Lintcode-437. Copy Books | c++, python | O(N*logP) | O(1) | Answer | DP | - |
Problem(9) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-37. Sudoku Solver | c++, python | O(N^(N^2)) | O(N) | - | - |
Leetcode-40. Combination Sum II | c++, python | O(2^N) | O(N) | - | - |
Leetcode-46. Permutations | c++, python | O(N!) | O(N) | - | - |
Leetcode-47. Permutations II | c++, python | O(N!) | O(N) | - | - |
Leetcode-51. N Queens | c++, python | O(N!) | O(N) | - | - |
Leetcode-77. Combinations | c++, python | O(k * C(n, k)) | O(K) | - | - |
Leetcode-79. Word Search | c++, python | O(MN*4^L) | O(MN) | - | - |
Leetcode-126. Word Ladder II | c++, python | O((N*L)^C) | O(N) | - | - |
Leetcode-257. Binary Tree Paths | c++, python | O(N) | O(Height) | - | - |
Problem(6) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-4. Median Of Two Sorted Arrays | c++, python | O(log(min(M, N))) | O(1) | - | - |
Leetcode-215. Kth Largest Element In An Array | c++, python | O(N) ~ O(N^2) | O(1) | QuickSelection | - |
Leetcode-240. Search A 2D Matrix II | c++, python | O(m * logN) | O(1) | Matrix | - |
Leetcode-347. Top K Frequent Elements | c++, python | O(N), O(C*logK) | O(N) | - | - |
Lintcode-11. Search Range In Binary Search Tree | c++, python | O(N) | O(Height) | InOrder | - |
Lintcode-1534. Convert Binary Search Tree To Sorted Doubly Linked List | c++, python | O(N) | O(Height) | BST | Leetcode-426 | - |
Problem(12) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-102. Binary Tree Level Order Traversal | c++, python | O(N) | O(Width) | Level | - |
Leetcode-104. Maximum Depth Of Binary Tree | c++, python | O(N) | O(Height) | Recursion | - |
Leetcode-126. Word Ladder II | c++, python | O((N*L)^C) | O(N) | - | - |
Leetcode-130. Surrounded Regions | c++, python | O(MN) | O(1) | - | - |
Leetcode-297. Serialize And Deserialize Binary Tree | c++, python | O(N) | O(N) | Serialization | - |
Leetcode-310. Minimum Height Trees | c++, python | O(N) | O(N) | - | - |
Leetcode-322. Coin Change | c++, python | O(K * N) | O(N) | Index | Video |
Leetcode-417. Pacific Atlantic Water Flow | c++, python | O(MN) | O(MN) | - | - |
Leetcode-542. 01 Matrix | c++, python | O(MN) | O(MN) | - | - |
Leetcode-547. Number Of Provinces | c++, python | O(N^2) | O(N) | - | - |
Leetcode-695. Max Area Of Island | c++, python | O(MN) | O(MN) | - | - |
Leetcode-934. Shortest Bridge | c++, python | O(N^2) | O(N^2) | - | - |
Problem(4) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-215. Kth Largest Element In An Array | c++, python | O(N) ~ O(N^2) | O(1) | QuickSelection | - |
Leetcode-347. Top K Frequent Elements | c++, python | O(N), O(C*logK) | O(N) | - | - |
Leetcode-451. Sort Characters By Frequency | c++, python | O(N) | O(N) | - | - |
Leetcode-658. Find K Closest Elements | c++, python | O(Log(N - K)) | O(1) | Range | - |
Problem(3) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-130. Surrounded Regions | c++, python | O(MN) | O(1) | - | - |
Leetcode-547. Number Of Provinces | c++, python | O(N^2) | O(N) | - | - |
Leetcode-695. Max Area Of Island | c++, python | O(MN) | O(MN) | - | - |
Problem(1) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-406. Queue Reconstruction By Height | c++, python | O(N * logN) | O(1) | - | - |
Problem(2) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Leetcode-665. Non Decreasing Array | c++, python | O(N) | O(1) | - | - |
Leetcode-2210. Count Hills And Valleys In An Array | c++, python | O(N) | O(1) | - | - |
Problem(1) | Solution | Time | Space | Note | Ref |
---|---|---|---|---|---|
Lintcode-1790. Rotate String II | c++, python | O(N) | O(N) | Simulation | - |