Skip to content

geemaple/leetcode

Repository files navigation

算法/Algorithm

我个人的力扣答案, 公众号:GeekPal
这是一个持续更新的开源项目

My personal leetcode answers
This is a continually updated open source project

软件/Softwares

脚本/Script

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

文章/Articles

书籍/Books

  • 《算法技术手册》/ 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)

Bit Manipulation

Simulation

Problem Solution Time Space Note Ref
Lintcode-39. Recover Rotated Sorted Array c++, python O(N) O(1) Rotated -

Design

Problem 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 -

Binary Search

Problem Solution Time Space Note Ref
Leetcode-3048. Earliest Second To Mark Indices I c++, python O(M*logM) O(M) - -
Leetcode-2468. Split Message Based On Limit c++, python O(logN + K) O(1) Answer | Bruteforce -
Lintcode-437. Copy Books c++, python O(N*logP) O(1) Answer | DP -
Lintcode-600. Smallest Rectangle Enclosing Black Pixels c++, python O(N * logM + M * logN) O(1) Graph | Leetcode-302 -
Leetcode-74. Search A 2D Matrix c++, python O(log(m * n)) O(1) Matrix; -
Leetcode-240. Search A 2D Matrix II c++, python O(m * logN) O(1) Matrix -
Leetcode-162. Find Peak Element c++, python O(logN) O(1) Mountain; Video
Leetcode-852. Peak Index In A Mountain Array c++, python O(logN) O(1) Mountain -
Leetcode-1901. Find A Peak Element II c++, python O(N * logM) O(1) Mountain; -
Leetcode-278. First Bad Version c++, python O(logN) O(1) Range; Video
Leetcode-302. Smallest Rectangle Enclosing Black Pixels c++, python O(N * logM + M * logN) O(1) Range -
Leetcode-658. Find K Closest Elements c++, python O(Log(N - K)) O(1) Range -
Leetcode-33. Search In Rotated Sorted Array c++, python O(logN) O(1) Rotated; -
Leetcode-81. Search In Rotated Sorted Array II c++, python O(logN) ~ O(N) O(1) Rotated; -
Leetcode-153. Find Minimum In Rotated Sorted Array c++, python O(logN) O(1) Rotated; Video
Leetcode-154. Find Minimum In Rotated Sorted Array II c++, python O(logN) ~ O(N) O(1) Rotated; -
Leetcode-374. Guess Number Higher Or Lower c++, python O(logN) O(1) Standard -
Leetcode-704. Binary Search c++, python O(logN) O(1) Standard; Video
Leetcode-34. Find First And Last Position Of Element In Sorted Array c++, python O(logN) O(1) std::lower_bound; Video
Leetcode-35. Search Insert Position c++, python O(logN) O(1) std::lower_bound -
Leetcode-2529. Maximum Count Of Positive Integer And Negative Integer c++, python O(logN) O(1) std::lower_bound -

Two Pointers

Greedy

Dynamic Programming

Problem Solution Time Space Note Ref
Leetcode-375. Guess Number Higher Or Lower II c++, python O(N^3) O(N^2) DP(Index) -
Leetcode-322. Coin Change c++, python O(K * N) O(N) Index Video

Backtracking

Problem Solution Time Space Note Ref
Leetcode-257. Binary Tree Paths c++, python O(N) O(Height) - -

Divide and Conquer

Problem Solution Time Space Note Ref
Lintcode-1534. Convert Binary Search Tree To Sorted Doubly Linked List c++, python O(N) O(Height) BST | Leetcode-426 -
Lintcode-11. Search Range In Binary Search Tree c++, python O(N) O(Height) InOrder -

Breadth-First Search

Problem 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 -

Depth-First Search

Problem Solution Time Space Note Ref
Leetcode-98. Validate Binary Search Tree c++, python O(N) O(Height) BST -
Leetcode-94. Binary Tree Inorder Traversal c++, python O(N) O(Height) InOrder -
Leetcode-145. Binary Tree Postorder Traversal c++, python O(N) O(Height) PostOrder -
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-110. Balanced Binary Tree c++, python O(N) O(Height) Recursion -
Leetcode-236. Lowest Common Ancestor Of A Binary Tree c++, python O(N) O(Height) Recursion -

Hash Table

Binary Search Tree

Problem Solution Time Space Note Ref
Leetcode-450. Delete Node In A Bst c++, python O(Height) O(Height) Delete -
Leetcode-701. Insert Into A Binary Search Tree c++, python O(Height) O(Height) Insert -
Lintcode-448. Inorder Successor In Bst c++, python O(Height) O(1) Successor | Leetcode-285 -

Union Find

Trie

Linked List

String

Problem Solution Time Space Note Ref
Leetcode-1249. Minimum Remove To Make Valid Parentheses c++, python O(N) O(N) - -
Lintcode-1790. Rotate String II c++, python O(N) O(N) Simulation -

Array

Problem Solution Time Space Note Ref
Leetcode-2210. Count Hills And Valleys In An Array c++, python O(N) O(1) - -

Other

Problem Solution Time Space Note Ref
Leetcode-1. Two Sum c++, python - - - -
Leetcode-2. Add Two Numbers c++, python - - - -
Leetcode-3. Longest Substring Without Repeating Characters c++, python - - - -
Leetcode-4. Median Of Two Sorted Arrays c++, python - - - -
Leetcode-5. Longest Palindromic Substring python - - - -
Leetcode-6. Zigzag Conversion python - - - -
Leetcode-7. Reverse Integer c++, python - - - -
Leetcode-8. String To Integer Atoi c++, python - - - -
Leetcode-9. Palindrome Number c++, python - - - -
Leetcode-10. Regular Expression Matching c++, python - - - -
Leetcode-11. Container With Most Water python - - - -
Leetcode-12. Integer To Roman c++, python - - - -
Leetcode-13. Roman To Integer c++, python - - - -
Leetcode-14. Longest Common Prefix c++, python - - - -
Leetcode-15. 3Sum c++, python - - - -
Leetcode-16. 3Sum Closest c++, python - - - -
Leetcode-17. Letter Combinations Of A Phone Number c++, python - - - -
Leetcode-18. 4Sum c++, python - - - -
Leetcode-19. Remove Nth Node From End Of List c++, python - - - -
Leetcode-20. Valid Parentheses c++, python - - - -
Leetcode-21. Merge Two Sorted Lists c++, python - - - -
Leetcode-22. Generate Parentheses python - - - -
Leetcode-23. Merge K Sorted Lists c++, python - - - -
Leetcode-24. Swap Nodes In Pairs c++, python - - - -
Leetcode-25. Reverse Nodes In K Group c++, python - - - -
Leetcode-26. Remove Duplicates From Sorted Array c++, python - - - -
Leetcode-27. Remove Element c++, python - - - -
Leetcode-28. Implement Strstr c++, python - - - -
Leetcode-29. Divide Two Integers c++, python - - - -
Leetcode-30. Substring With Concatenation Of All Words c++, python - - - -
Leetcode-31. Next Permutation c++, python - - - -
Leetcode-36. Valid Sudoku c++, python - - - -
Leetcode-37. Sudoku Solver python - - - -
Leetcode-39. Combination Sum c++, python - - - -
Leetcode-40. Combination Sum II c++, python - - - -
Leetcode-41. First Missing Positive python - - - -
Leetcode-42. Trapping Rain Water c++, python - - - -
Leetcode-43. Multiply Strings c++, python - - - -
Leetcode-44. Wildcard Matching c++, python - - - -
Leetcode-45. Jump Game II c++, python - - - -
Leetcode-46. Permutations c++, python - - - -
Leetcode-47. Permutations II c++, python - - - -
Leetcode-48. Rotate Image c++, python - - - -
Leetcode-49. Group Anagrams c++ - - - -
Leetcode-50. Powx N c++, python - - - -
Leetcode-51. N Queens c++, python - - - -
Leetcode-52. N Queens II c++, python - - - -
Leetcode-53. Maximum Subarray c++, python - - - -
Leetcode-54. Spiral Matrix c++, python - - - -
Leetcode-55. Jump Game c++, python - - - -
Leetcode-56. Merge Intervals c++, python - - - -
Leetcode-57. Insert Interval c++, python - - - -
Leetcode-61. Rotate List python - - - -
Leetcode-62. Unique Paths c++, python - - - -
Leetcode-63. Unique Paths II c++, python - - - -
Leetcode-64. Minimum Path Sum c++, python - - - -
Leetcode-66. Plus One c++, python - - - -
Leetcode-67. Add Binary c++, python - - - -
Leetcode-68. Text Justification python - - - -
Leetcode-69. Sqrtx c++, python - - - -
Leetcode-70. Climbing Stairs c++, python - - - -
Leetcode-72. Edit Distance c++, python - - - -
Leetcode-75. Sort Colors c++, python - - - -
Leetcode-76. Minimum Window Substring c++, python - - - -
Leetcode-78. Subsets c++, python - - - -
Leetcode-79. Word Search c++, python - - - -
Leetcode-84. Largest Rectangle In Histogram c++, python - - - -
Leetcode-85. Maximal Rectangle c++, python - - - -
Leetcode-86. Partition List c++, python - - - -
Leetcode-87. Scramble String c++, python - - - -
Leetcode-88. Merge Sorted Array c++, python - - - -
Leetcode-90. Subsets II c++, python - - - -
Leetcode-91. Decode Ways c++, python - - - -
Leetcode-92. Reverse Linked List II c++, python - - - -
Leetcode-97. Interleaving String c++, python - - - -
Leetcode-103. Binary Tree Zigzag Level Order Traversal c++, python - - - -
Leetcode-107. Binary Tree Level Order Traversal II c++, python - - - -
Leetcode-115. Distinct Subsequences c++, python - - - -
Leetcode-118. Pascals Triangle c++, python - - - -
Leetcode-119. Pascals Triangle II c++, python - - - -
Leetcode-120. Triangle c++, python - - - -
Leetcode-121. Best Time To Buy And Sell Stock c++, python - - - -
Leetcode-122. Best Time To Buy And Sell Stock II c++, python - - - -
Leetcode-123. Best Time To Buy And Sell Stock III c++, python - - - -
Leetcode-125. Valid Palindrome c++, python - - - -
Leetcode-126. Word Ladder II c++, python - - - -
Leetcode-127. Word Ladder c++, python - - - -
Leetcode-128. Longest Consecutive Sequence c++, python - - - -
Leetcode-130. Surrounded Regions c++, python - - - -
Leetcode-131. Palindrome Partitioning c++, python - - - -
Leetcode-132. Palindrome Partitioning II c++, python - - - -
Leetcode-133. Clone Graph c++, python - - - -
Leetcode-136. Single Number c++, python - - - -
Leetcode-138. Copy List With Random Pointer python - - - -
Leetcode-141. Linked List Cycle c++, python - - - -
Leetcode-142. Linked List Cycle II c++, python - - - -
Leetcode-143. Reorder List python - - - -
Leetcode-148. Sort List python - - - -
Leetcode-155. Min Stack c++, python - - - -
Leetcode-156. Binary Tree Upside Down c++, python - - - -
Leetcode-157. Read N Characters Given Read4 c++, python - - - -
Leetcode-159. Longest Substring With At Most Two Distinct Characters c++, python - - - -
Leetcode-160. Intersection Of Two Linked Lists c++, python - - - -
Leetcode-161. One Edit Distance c++, python - - - -
Leetcode-163. Missing Ranges c++, python - - - -
Leetcode-167. Two Sum Ii Input Array Is Sorted c++, python - - - -
Leetcode-169. Majority Element c++, python - - - -
Leetcode-170. Two Sum Iii Data Structure Design c++, python - - - -
Leetcode-175. Combine Two Tables sql - - - -
Leetcode-188. Best Time To Buy And Sell Stock IV c++, python - - - -
Leetcode-198. House Robber c++, python - - - -
Leetcode-200. Number Of Islands c++, python - - - -
Leetcode-202. Happy Number c++, python - - - -
Leetcode-203. Remove Linked List Elements python - - - -
Leetcode-205. Isomorphic Strings c++, python - - - -
Leetcode-206. Reverse Linked List c++, python - - - -
Leetcode-207. Course Schedule c++, python - - - -
Leetcode-208. Implement Trie Prefix Tree c++, python - - - -
Leetcode-209. Minimum Size Subarray Sum c++, python - - - -
Leetcode-210. Course Schedule II c++, python - - - -
Leetcode-211. Add And Search Word Data Structure Design c++, python - - - -
Leetcode-212. Word Search II c++, python - - - -
Leetcode-213. House Robber II c++, python - - - -
Leetcode-215. Kth Largest Element In An Array c++, python - - - -
Leetcode-217. Contains Duplicate c++ - - - -
Leetcode-219. Contains Duplicate II c++ - - - -
Leetcode-221. Maximal Square c++, python - - - -
Leetcode-228. Summary Ranges python - - - -
Leetcode-231. Power Of Two python - - - -
Leetcode-234. Palindrome Linked List c++, python - - - -
Leetcode-237. Delete Node In A Linked List python - - - -
Leetcode-239. Sliding Window Maximum c++, python - - - -
Leetcode-242. Valid Anagram c++, python - - - -
Leetcode-246. Strobogrammatic Number c++, python - - - -
Leetcode-249. Group Shifted Strings c++ - - - -
Leetcode-251. Flatten 2D Vector python - - - -
Leetcode-253. Meeting Rooms II c++, python - - - -
Leetcode-256. Paint House c++, python - - - -
Leetcode-261. Graph Valid Tree c++, python - - - -
Leetcode-263. Ugly Number c++, python - - - -
Leetcode-265. Paint House II c++, python - - - -
Leetcode-269. Alien Dictionary python - - - -
Leetcode-270. Closest Binary Search Tree Value c++, python - - - -
Leetcode-271. Encode And Decode Strings c++, python - - - -
Leetcode-273. Integer To English Words python - - - -
Leetcode-276. Paint Fence c++, python - - - -
Leetcode-277. Find The Celebrity c++, python - - - -
Leetcode-279. Perfect Squares c++, python - - - -
Leetcode-280. Wiggle Sort python - - - -
Leetcode-282. Expression Add Operators c++, python - - - -
Leetcode-283. Move Zeroes c++, python - - - -
Leetcode-285. Inorder Successor In Bst c++, python - - - -
Leetcode-286. Walls And Gates c++, python - - - -
Leetcode-288. Unique Word Abbreviation c++, python - - - -
Leetcode-289. Game Of Life python - - - -
Leetcode-295. Find Median From Data Stream c++, python - - - -
Leetcode-300. Longest Increasing Subsequence c++, python - - - -
Leetcode-305. Number Of Islands II c++, python - - - -
Leetcode-311. Sparse Matrix Multiplication c++, python - - - -
Leetcode-312. Burst Balloons c++, python - - - -
Leetcode-314. Binary Tree Vertical Order Traversal c++, python - - - -
Leetcode-318. Maximum Product Of Word Lengths c++, python - - - -
Leetcode-323. Number Of Connected Components In An Undirected Graph c++, python - - - -
Leetcode-324. Wiggle Sort II python - - - -
Leetcode-326. Power Of Three python - - - -
Leetcode-328. Odd Even Linked List python - - - -
Leetcode-336. Palindrome Pairs python - - - -
Leetcode-338. Counting Bits c++, python - - - -
Leetcode-340. Longest Substring With At Most K Distinct Characters c++, python - - - -
Leetcode-341. Flatten Nested List Iterator python - - - -
Leetcode-342. Power Of Four python - - - -
Leetcode-344. Reverse String c++, python - - - -
Leetcode-345. Reverse Vowels Of A String c++, python - - - -
Leetcode-346. Moving Average From Data Stream c++, python - - - -
Leetcode-347. Top K Frequent Elements c++ - - - -
Leetcode-349. Intersection Of Two Arrays c++, python - - - -
Leetcode-350. Intersection Of Two Arrays II c++, python - - - -
Leetcode-354. Russian Doll Envelopes c++, python - - - -
Leetcode-359. Logger Rate Limiter c++ - - - -
Leetcode-361. Bomb Enemy c++, python - - - -
Leetcode-366. Find Leaves Of Binary Tree c++, python - - - -
Leetcode-367. Valid Perfect Square c++, python - - - -
Leetcode-368. Largest Divisible Subset c++, python - - - -
Leetcode-370. Range Addition c++, python - - - -
Leetcode-377. Combination Sum IV c++, python - - - -
Leetcode-378. Kth Smallest Element In A Sorted Matrix c++, python - - - -
Leetcode-380. Insert Delete Getrandom O1 c++ - - - -
Leetcode-387. First Unique Character In A String c++, python - - - -
Leetcode-388. Longest Absolute File Path c++, python - - - -
Leetcode-393. Utf 8 Validation c++, python - - - -
Leetcode-394. Decode String c++, python - - - -
Leetcode-403. Frog Jump c++ - - - -
Leetcode-406. Queue Reconstruction By Height c++, python - - - -
Leetcode-407. Trapping Rain Water II c++, python - - - -
Leetcode-408. Valid Word Abbreviation c++, python - - - -
Leetcode-415. Add Strings c++, python - - - -
Leetcode-425. Word Squares c++, python - - - -
Leetcode-426. Convert Binary Search Tree To Sorted Doubly Linked List c++, python - - - -
Leetcode-433. Minimum Genetic Mutation c++, python - - - -
Leetcode-438. Find All Anagrams In A String c++, python - - - -
Leetcode-444. Sequence Reconstruction c++, python - - - -
Leetcode-447. Number Of Boomerangs c++, python - - - -
Leetcode-448. Find All Numbers Disappeared In An Array python - - - -
Leetcode-454. 4Sum II c++ - - - -
Leetcode-463. Island Perimeter python - - - -
Leetcode-474. Ones And Zeroes c++, python - - - -
Leetcode-485. Max Consecutive Ones c++ - - - -
Leetcode-498. Diagonal Traverse c++ - - - -
Leetcode-516. Longest Palindromic Subsequence c++, python - - - -
Leetcode-527. Word Abbreviation c++, python - - - -
Leetcode-532. K Diff Pairs In An Array c++, python - - - -
Leetcode-535. Encode And Decode Tinyurl python - - - -
Leetcode-538. Convert Bst To Greater Tree c++, python - - - -
Leetcode-560. Subarray Sum Equals K c++, python - - - -
Leetcode-561. Array Partition I c++ - - - -
Leetcode-599. Minimum Index Sum Of Two Lists c++ - - - -
Leetcode-652. Find Duplicate Subtrees c++ - - - -
Leetcode-654. Maximum Binary Tree c++, python - - - -
Leetcode-657. Robot Return To Origin python - - - -
Leetcode-674. Longest Continuous Increasing Subsequence c++, python - - - -
Leetcode-677. Map Sum Pairs c++, python - - - -
Leetcode-683. K Empty Slots c++, python - - - -
Leetcode-687. Longest Univalue Path c++, python - - - -
Leetcode-702. Search In A Sorted Array Of Unknown Size c++, python - - - -
Leetcode-721. Accounts Merge c++, python - - - -
Leetcode-724. Find Pivot Index c++ - - - -
Leetcode-739. Daily Temperatures python - - - -
Leetcode-747. Largest Number At Least Twice Of Others c++ - - - -
Leetcode-751. Ip To Cidr python - - - -
Leetcode-755. Pour Water python - - - -
Leetcode-760. Find Anagram Mappings python - - - -
Leetcode-771. Jewels And Stones c++ - - - -
Leetcode-773. Sliding Puzzle python - - - -
Leetcode-787. Cheapest Flights Within K Stops python - - - -
Leetcode-796. Rotate String c++, python - - - -
Leetcode-815. Bus Routes python - - - -
Leetcode-829. Consecutive Numbers Sum python - - - -
Leetcode-832. Flipping An Image python - - - -
Leetcode-836. Rectangle Overlap c++, python - - - -
Leetcode-844. Backspace String Compare c++, python - - - -
Leetcode-859. Buddy Strings c++ - - - -
Leetcode-924. Minimize Malware Spread python - - - -
Leetcode-928. Minimize Malware Spread II python - - - -
Leetcode-929. Unique Email Addresses python - - - -
Leetcode-933. Number Of Recent Calls c++, python - - - -
Leetcode-1150. Check If A Number Is Majority Element In A Sorted Array c++, python - - - -
Lintcode-31. Partition Array python - - - -
Lintcode-77. Longest Common Subsequence c++, python - - - -
Lintcode-81. Find Median From Data Stream c++, python - - - -
Lintcode-89. K Sum c++, python - - - -
Lintcode-91. Minimum Adjustment Cost c++, python - - - -
Lintcode-92. Backpack c++, python - - - -
Lintcode-125. Backpack II c++, python - - - -
Lintcode-139. Subarray Sum Closest c++, python - - - -
Lintcode-144. Interleaving Positive And Negative Numbers c++, python - - - -
Lintcode-183. Wood Cut c++, python - - - -
Lintcode-382. Triangle Count c++, python - - - -
Lintcode-390. Find Peak Element II c++, python - - - -
Lintcode-391. Number Of Airplanes In The Sky c++, python - - - -
Lintcode-394. Coins In A Line c++, python - - - -
Lintcode-396. Coins In A Line III c++, python - - - -
Lintcode-440. Backpack III c++, python - - - -
Lintcode-447. Search In A Big Sorted Array c++, python - - - -
Lintcode-465. Kth Smallest Sum In Two Sorted Arrays c++, python - - - -
Lintcode-526. Load Balancer c++, python - - - -
Lintcode-543. Kth Largest In N Arrays c++, python - - - -
Lintcode-563. Backpack V c++, python - - - -
Lintcode-586. Sqrtx II c++, python - - - -
Lintcode-589. Connecting Graph c++, python - - - -
Lintcode-590. Connecting Graph II c++, python - - - -
Lintcode-591. Connecting Graph III c++, python - - - -
Lintcode-598. Zombie In Matrix c++, python - - - -
Lintcode-611. Knight Shortest Path c++, python - - - -
Lintcode-618. Search Graph Nodes c++, python - - - -
Lintcode-629. Minimum Spanning Tree c++, python - - - -
Lintcode-652. Factorization c++, python - - - -
Leetcode-38. Count And Say python - - Each term of the sequence of integers will be represented as a -
Leetcode-229. Majority Element II c++, python - - The algorithm should run in linear time and in O(1) space. -

其他/Other

Total sovled: 318
PS: semicolon(;) after each note means related questions are checked

Auto updated at: 2024-02-27 18:52:49

About

LeetCode solutions, written in python and cpp(LeetCode解题报告,记录自己的leetcode成长之路)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published