Skip to content

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

License

Notifications You must be signed in to change notification settings

geemaple/leetcode

Repository files navigation

算法/Algorithm

LeetCode解题报告,记录自己的leetcode成长之路

LeetCode solutions, written in python and cpp

链接/Links

脚本/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

书籍/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)

列表/List

Status List Progress Notes
[--] 9c-basic.md 80/129 1 vip
[--] 9c-top.md 25/48 -
[--] lee215.md 2/34 -
[✅] 9c-dp.md 42/45 3 vips
[✅] geekbang.md 55/55 -
[✅] leetcode101.md 183/184 1 vip
[🔲] 9c-advanced.md 14/91 5 vips
[🔲] leetcode-contest.md 7/20 -

Solved: 432 problems

类型/Category

Math

Link Problem(19) Solution Tag Time Space Note Ref
leetcode-415 Add Strings c++, python3 Math O(N) O(1) - -
leetcode-504 Base 7 c++, python3 Math O(N) O(1) - -
leetcode-227 Basic Calculator II c++, python3 Math O(N) O(N) - -
leetcode-932 Beautiful Array c++, python3 Math O(N) O(N) dp -
leetcode-3274 Check If Two Chessboard Squares Have The Same Color c++, python3 Math O(1) O(1) - -
leetcode-3280 Convert Date To Binary c++, python3 Math O(1) O(1) - -
leetcode-204 Count Primes c++, python3 Math O(NlogN) O(N) - -
leetcode-168 Excel Sheet Column Title c++, python3 Math O(logN) O(1) - -
leetcode-172 Factorial Trailing Zeroes c++, python3 Math O(logN) O(1) - -
leetcode-202 Happy Number c++, python3 Math O(S) O(1) - -
leetcode-149 Max Points On A Line c++, python3 Math O(N^2) O(N) - -
leetcode-462 Minimum Moves To Equal Array Elements II c++, python3 Math O(NlogN) O(1) - -
leetcode-326 Power Of Three c++, python3 Math O(1) O(1) - -
leetcode-50 Powx N c++, python3 Math O(logN) O(1) - -
leetcode-48 Rotate Image c++, python3 Math O(N^2) O(1) - -
leetcode-69 Sqrtx c++, python3 Math N(logN) O(1) - -
leetcode-633 Sum Of Square Numbers c++, python3 Math O(N) O(1) - -
leetcode-263 Ugly Number c++, python3 Math O(k) O(1) - -
leetcode-367 Valid Perfect Square c++, python3 Math O(logN) O(1) - -

Probability

Link Problem(5) Solution Tag Time Space Note Ref
leetcode-470 Implement Rand10 Using Rand7 c++, python3 Probability O(1) O(1) - -
leetcode-380 Insert Delete Getrandom O1 c++, python3 Probability O(1) O(N) - -
leetcode-382 Linked List Random Node c++, python3 Probability O(N) O(1) - -
leetcode-528 Random Pick With Weight c++, python3 Probability O(NlogN) O(N) - -
leetcode-384 Shuffle An Array c++, python3 Probability O(N) O(N) - -

Bit Manipulation

Link Problem(15) Solution Tag Time Space Note Ref
leetcode-67 Add Binary c++, python3 Bit Manipulation O(M+N) O(1) - -
leetcode-693 Binary Number With Alternating Bits c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-338 Counting Bits c++, python3 Bit Manipulation O(N) O(1) - -
leetcode-287 Find The Duplicate Number c++, python3 Bit Manipulation O(N) O(1) - -
leetcode-461 Hamming Distance c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-318 Maximum Product Of Word Lengths c++, python3 Bit Manipulation O(N^2) O(N) - -
leetcode-268 Missing Number c++, python3 Bit Manipulation O(N) O(1) - -
leetcode-476 Number Complement c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-191 Number Of 1 Bits c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-342 Power Of Four c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-231 Power Of Two c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-190 Reverse Bits c++, python3 Bit Manipulation O(1) O(1) - -
leetcode-3276 Select Cells In Grid With Maximum Score c++, python3 Bit Manipulation O(NM*2^N) O(2^N) - -
leetcode-136 Single Number c++, python3 Bit Manipulation O(N) O(1) - -
leetcode-260 Single Number III c++, python3 Bit Manipulation O(N) O(1) - -

Simulation

Link Problem(7) Solution Tag Time Space Note Ref
leetcode-67 Add Binary c++, python3 Simulation O(M+N) O(1) - -
leetcode-415 Add Strings c++, python3 Simulation O(N) O(1) - -
leetcode-566 Reshape The Matrix c++, python3 Simulation O(MN) O(1) - -
leetcode-874 Walking Robot Simulation c++, python3 Simulation O(N) O(K) - -
lintcode-849 Basic Calculator III c++, python3 Simulation O(N) O(1) Leetcode-772 -
lintcode-553 Bomb Enemy c++, python3 Simulation O(NM) O(NM) Leetcode-361 -
lintcode-39 Recover Rotated Sorted Array c++, python3 Simulation O(N) O(1) Rotated -

Design

Link Problem(13) Solution Tag Time Space Note Ref
leetcode-432 All Oone Data Structure c++, python3 Design O(1) O(N) - -
leetcode-173 Binary Search Tree Iterator c++, python3 Design O(1) O(H) InOrder -
leetcode-232 Implement Queue Using Stacks c++, python3 Design O(*1) O(N) - -
leetcode-225 Implement Stack Using Queues c++, python3 Design O(N) O(N) - -
leetcode-208 Implement Trie Prefix Tree c++, python3 Design O(N) O(L) - -
leetcode-380 Insert Delete Getrandom O1 c++, python3 Design O(1) O(N) - -
leetcode-703 Kth Largest Element In A Stream c++, python3 Design O(logN) O(N) - -
leetcode-146 Lru Cache c++, python3 Design O(1) O(N) - -
leetcode-155 Min Stack c++, python3 Design O(1) O(N) - -
leetcode-304 Range Sum Query 2D Immutable c++, python3 Design O(*1) O(MN) - -
leetcode-303 Range Sum Query Immutable c++, python3 Design O(*1) O(N) - -
leetcode-307 Range Sum Query Mutable c++, python3 Design O(logN) O(N) - -
leetcode-297 Serialize And Deserialize Binary Tree c++, python3 Design O(N) O(N) Serialization -

Greedy

Link Problem(21) Solution Tag Time Space Note Ref
leetcode-870 Advantage Shuffle c++, python3 Greedy O(NlogN) O(N) - -
leetcode-455 Assign Cookies c++, python3 Greedy O(NlogN) O(1) - -
leetcode-122 Best Time To Buy And Sell Stock II c++, python3 Greedy O(N) O(1) - -
leetcode-714 Best Time To Buy And Sell Stock With Transaction Fee c++, python3 Greedy O(N) O(N) - -
leetcode-605 Can Place Flowers c++, python3 Greedy O(N) O(N) - -
leetcode-135 Candy c++, python3 Greedy O(N) O(N) - -
leetcode-3048 Earliest Second To Mark Indices I c++, python3 Greedy O(NlogN) O(N) - -
leetcode-55 Jump Game c++, python3 Greedy O(N) O(1) - -
leetcode-860 Lemonade Change c++, python3 Greedy O(N) O(1) - -
leetcode-409 Longest Palindrome c++, python3 Greedy O(N) O(N) - -
leetcode-769 Max Chunks To Make Sorted c++, python3 Greedy O(N) O(1) - -
leetcode-3281 Maximize Score Of Numbers In Ranges c++, python3 Greedy O(NlogN + NlogD) O(1) - -
leetcode-646 Maximum Length Of Pair Chain c++, python3 Greedy O(NlogN) O(N) - -
leetcode-452 Minimum Number Of Arrows To Burst Balloons c++, python3 Greedy O(NlogN) O(1) - -
leetcode-435 Non Overlapping Intervals c++, python3 Greedy O(NlogN) O(1) - -
leetcode-763 Partition Labels c++, python3 Greedy O(N) O(N) - -
leetcode-3282 Reach End Of Array With Max Score c++, python3 Greedy O(N) O(1) - -
leetcode-680 Valid Palindrome II c++, python3 Greedy O(N) O(1) - -
leetcode-376 Wiggle Subsequence c++, python3 Greedy O(N) O(N) - -
leetcode-44 Wildcard Matching c++, python3 Greedy O(NM) O(NM) - -
lintcode-3672 Connecting Cities With Minimum Cost c++, python3 Greedy O(ElogE) O(E+V) Leetcode-1135 -

Dynamic Programming

Link Problem(64) Solution Tag Time Space Note Ref
leetcode-542 01 Matrix c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-650 2 Keys Keyboard c++, python3 Dynamic Programming O(NlogN) O(N) - -
leetcode-413 Arithmetic Slices c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-121 Best Time To Buy And Sell Stock c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-122 Best Time To Buy And Sell Stock II c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-123 Best Time To Buy And Sell Stock III c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-188 Best Time To Buy And Sell Stock IV c++, python3 Dynamic Programming O(NK) O(NK) - -
leetcode-309 Best Time To Buy And Sell Stock With Cooldown c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-714 Best Time To Buy And Sell Stock With Transaction Fee c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-312 Burst Balloons c++, python3 Dynamic Programming O(N^3) O(N^2) - -
leetcode-787 Cheapest Flights Within K Stops c++, python3 Dynamic Programming O(ElogV) O(E+V) - -
leetcode-70 Climbing Stairs c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-322 Coin Change c++, python3 Dynamic Programming O(K * N) O(N) Index Video
leetcode-338 Counting Bits c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-91 Decode Ways c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-583 Delete Operation For Two Strings c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-241 Different Ways To Add Parentheses c++, python3 Dynamic Programming - - - -
leetcode-115 Distinct Subsequences c++, python3 Dynamic Programming O(NM) O(NM) - -
leetcode-72 Edit Distance c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-403 Frog Jump c++, python3 Dynamic Programming O(N^2) O(N^2) - -
leetcode-22 Generate Parentheses c++, python3 Dynamic Programming O(2^N) O(N) Catalan Number -
leetcode-198 House Robber c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-213 House Robber II c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-343 Integer Break c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-97 Interleaving String c++, python3 Dynamic Programming O(NM) O(M) Prove |n - m| <= 1 -
leetcode-55 Jump Game c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-1143 Longest Common Subsequence c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-300 Longest Increasing Subsequence c++, python3 Dynamic Programming O(N*logN) O(N) LIS | std::lower_bound -
leetcode-516 Longest Palindromic Subsequence c++, python3 Dynamic Programming O(N^2) O(N^2) - -
leetcode-5 Longest Palindromic Substring c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-85 Maximal Rectangle c++, python3 Dynamic Programming O(NM) O(M) - -
leetcode-221 Maximal Square c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-646 Maximum Length Of Pair Chain c++, python3 Dynamic Programming O(NlogN) O(N) - -
leetcode-152 Maximum Product Subarray c++, python3 Dynamic Programming O(N) O(1) - -
leetcode-53 Maximum Subarray c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-3277 Maximum Xor Score Subarray Queries c++, python3 Dynamic Programming O(N^2 + M) O(N^2) - -
leetcode-64 Minimum Path Sum c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-435 Non Overlapping Intervals c++, python3 Dynamic Programming O(NlogN) O(1) - -
leetcode-474 Ones And Zeroes c++, python3 Dynamic Programming O(KMN) O(MN) - -
leetcode-132 Palindrome Partitioning II c++, python3 Dynamic Programming O(N^2) O(N^2) - -
leetcode-647 Palindromic Substrings c++, python3 Dynamic Programming O(N^2) O(1) DP Slow -
leetcode-416 Partition Equal Subset Sum c++, python3 Dynamic Programming O(N^2) O(N) - -
leetcode-279 Perfect Squares c++, python3 Dynamic Programming O(NlogN) O(N) - -
leetcode-10 Regular Expression Matching c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-354 Russian Doll Envelopes c++, python3 Dynamic Programming O(NlogN) O(N) - -
leetcode-87 Scramble String c++, python3 Dynamic Programming O(N^4) O(N^3) - -
leetcode-3276 Select Cells In Grid With Maximum Score c++, python3 Dynamic Programming O(NM*2^N) O(2^N) - -
leetcode-313 Super Ugly Number c++, python3 Dynamic Programming O(NlogK) O(N+K) K-Linked-List(dup) -
leetcode-494 Target Sum c++, python3 Dynamic Programming O(N * Sum) O(N * Sum) - -
leetcode-120 Triangle c++, python3 Dynamic Programming O(N^2) O(N) - -
leetcode-62 Unique Paths c++, python3 Dynamic Programming O(MN) O(MN) - -
leetcode-63 Unique Paths II c++, python3 Dynamic Programming O(NM) O(NM) - -
leetcode-376 Wiggle Subsequence c++, python3 Dynamic Programming O(N) O(N) - -
leetcode-44 Wildcard Matching c++, python3 Dynamic Programming O(NM) O(NM) - -
leetcode-139 Word Break c++, python3 Dynamic Programming O(MN) O(N) - -
lintcode-92 Backpack c++, python3 Dynamic Programming O(N^2) O(N^2) - -
lintcode-125 Backpack II c++, python3 Dynamic Programming O(N^2) O(N^2) - -
lintcode-440 Backpack III c++, python3 Dynamic Programming O(N^2) O(N^2) - -
lintcode-562 Backpack IV c++, python3 Dynamic Programming O(N^2) O(N^2) - -
lintcode-563 Backpack V c++, python3 Dynamic Programming O(N^2) O(N) - -
lintcode-437 Copy Books c++, python3 Dynamic Programming O(N*logP) O(1) Answer | DP -
lintcode-89 K Sum c++, python3 Dynamic Programming O(NKT) O(NKT) - -
lintcode-515 Paint House c++, python3 Dynamic Programming O(N) O(N) Leetcode-256 -
lintcode-516 Paint House II c++, python3 Dynamic Programming O(NM) O(NM) Leetcode-265 -

Game Theory

Link Problem(2) Solution Tag Time Space Note Ref
leetcode-375 Guess Number Higher Or Lower II c++, python3 Game Theory O(N^3) O(N^2) DP(Index) -
lintcode-394 Coins In A Line c++, python3 Game Theory O(N) O(N) - -

Binary Search

Link Problem(36) Solution Tag Time Space Note Ref
leetcode-704 Binary Search c++, python3 Binary Search O(logN) O(1) Standard; Video
leetcode-3048 Earliest Second To Mark Indices I c++, python3 Binary Search O(NlogN) O(N) - -
leetcode-1901 Find A Peak Element II c++, python3 Binary Search O(N * logM) O(1) Mountain; -
leetcode-34 Find First And Last Position Of Element In Sorted Array c++, python3 Binary Search O(logN) O(1) std::lower_bound; Video
leetcode-658 Find K Closest Elements c++, python3 Binary Search O(Log(N - K)) O(1) Range -
leetcode-153 Find Minimum In Rotated Sorted Array c++, python3 Binary Search O(logN) O(1) Rotated; Video
leetcode-154 Find Minimum In Rotated Sorted Array II c++, python3 Binary Search O(logN) ~ O(N) O(1) Rotated; -
leetcode-162 Find Peak Element c++, python3 Binary Search O(logN) O(1) Mountain; Video
leetcode-287 Find The Duplicate Number c++, python3 Binary Search O(N) O(1) - -
leetcode-278 First Bad Version c++, python3 Binary Search O(logN) O(1) Range; Video
leetcode-374 Guess Number Higher Or Lower c++, python3 Binary Search O(logN) O(1) Standard -
leetcode-378 Kth Smallest Element In A Sorted Matrix c++, python3 Binary Search O(KlogN) O(N) - -
leetcode-2040 Kth Smallest Product Of Two Sorted Arrays c++, python3 Binary Search O(logA * NlogM) O(1) - -
leetcode-300 Longest Increasing Subsequence c++, python3 Binary Search O(N*logN) O(N) LIS | std::lower_bound -
leetcode-3281 Maximize Score Of Numbers In Ranges c++, python3 Binary Search O(NlogN + NlogD) O(1) - -
leetcode-2529 Maximum Count Of Positive Integer And Negative Integer c++, python3 Binary Search O(logN) O(1) std::lower_bound -
leetcode-4 Median Of Two Sorted Arrays c++, python3 Binary Search O(log(min(M, N))) O(1) - -
leetcode-209 Minimum Size Subarray Sum c++, python3 Binary Search O(N) O(1) - -
leetcode-268 Missing Number c++, python3 Binary Search O(N) O(1) - -
leetcode-1631 Path With Minimum Effort c++, python3 Binary Search O(NMlogNM) O(NM) - -
leetcode-852 Peak Index In A Mountain Array c++, python3 Binary Search O(logN) O(1) Mountain -
leetcode-528 Random Pick With Weight c++, python3 Binary Search O(NlogN) O(N) - -
leetcode-354 Russian Doll Envelopes c++, python3 Binary Search O(NlogN) O(N) - -
leetcode-74 Search A 2D Matrix c++, python3 Binary Search O(log(m * n)) O(1) Matrix; -
leetcode-240 Search A 2D Matrix II c++, python3 Binary Search O(M + N) O(1) Matrix -
leetcode-33 Search In Rotated Sorted Array c++, python3 Binary Search O(logN) O(1) Rotated; -
leetcode-81 Search In Rotated Sorted Array II c++, python3 Binary Search O(logN) ~ O(N) O(1) Rotated; -
leetcode-35 Search Insert Position c++, python3 Binary Search O(logN) O(1) std::lower_bound -
leetcode-540 Single Element In A Sorted Array c++, python3 Binary Search O(logN) O(1) - -
leetcode-2468 Split Message Based On Limit c++, python3 Binary Search O(logN + K) O(1) Answer | Bruteforce -
leetcode-69 Sqrtx c++, python3 Binary Search N(logN) O(1) - -
leetcode-633 Sum Of Square Numbers c++, python3 Binary Search O(N) O(1) - -
leetcode-167 Two Sum Ii Input Array Is Sorted c++, python3 Binary Search O(N) O(1) - -
leetcode-367 Valid Perfect Square c++, python3 Binary Search O(logN) O(1) - -
lintcode-437 Copy Books c++, python3 Binary Search O(N*logP) O(1) Answer | DP -
lintcode-600 Smallest Rectangle Enclosing Black Pixels c++, python3 Binary Search O(N * logM + M * logN) O(1) Graph | Leetcode-302 -

Linked List

Link Problem(20) Solution Tag Time Space Note Ref
leetcode-432 All Oone Data Structure c++, python3 Linked List O(1) O(N) - -
leetcode-109 Convert Sorted List To Binary Search Tree c++, python3 Linked List O(NlogN) O(logN) - -
leetcode-114 Flatten Binary Tree To Linked List c++, python3 Linked List O(N) O(H) PreOrder -
leetcode-160 Intersection Of Two Linked Lists c++, python3 Linked List O(N) O(1) - -
leetcode-141 Linked List Cycle c++, python3 Linked List O(N) O(1) - -
leetcode-142 Linked List Cycle II c++, python3 Linked List O(N) O(1) - -
leetcode-382 Linked List Random Node c++, python3 Linked List O(N) O(1) - -
leetcode-146 Lru Cache c++, python3 Linked List O(1) O(N) - -
leetcode-23 Merge K Sorted Lists c++, python3 Linked List O(NlogK) O(K) - -
leetcode-21 Merge Two Sorted Lists c++, python3 Linked List O(N) O(1) - -
leetcode-876 Middle Of The Linked List c++, python3 Linked List O(N) O(1) - -
leetcode-328 Odd Even Linked List c++, python3 Linked List O(N) O(1) - -
leetcode-234 Palindrome Linked List c++, python3 Linked List O(N) O(1) - -
leetcode-83 Remove Duplicates From Sorted List c++, python3 Linked List O(N) O(1) - -
leetcode-19 Remove Nth Node From End Of List c++, python3 Linked List O(N) O(1) - -
leetcode-206 Reverse Linked List c++, python3 Linked List O(N) O(N) - -
leetcode-25 Reverse Nodes In K Group c++, python3 Linked List O(N) O(1) - -
leetcode-148 Sort List c++, python3 Linked List O(NlogN) O(logN) - -
leetcode-24 Swap Nodes In Pairs c++, python3 Linked List O(N) O(1) - -
lintcode-1534 Convert Binary Search Tree To Sorted Doubly Linked List c++, python3 Linked List O(N) O(H) BST | Leetcode-426 -

Hash Table

Link Problem(39) Solution Tag Time Space Note Ref
leetcode-432 All Oone Data Structure c++, python3 Hash Table O(1) O(N) - -
leetcode-106 Construct Binary Tree From Inorder And Postorder Traversal c++, python3 Hash Table O(N) O(N) - -
leetcode-105 Construct Binary Tree From Preorder And Inorder Traversal c++, python3 Hash Table O(N) O(N) - -
leetcode-889 Construct Binary Tree From Preorder And Postorder Traversal c++, python3 Hash Table O(N) O(N) - -
leetcode-217 Contains Duplicate c++, python3 Hash Table O(N) O(N) - -
leetcode-697 Degree Of An Array c++, python3 Hash Table O(N) O(N) - -
leetcode-1110 Delete Nodes And Return Forest c++, python3 Hash Table O(N) O(N) - -
leetcode-438 Find All Anagrams In A String c++, python3 Hash Table O(N) O(1) - -
leetcode-448 Find All Numbers Disappeared In An Array c++, python3 Hash Table O(N) O(1) - -
leetcode-49 Group Anagrams c++, python3 Hash Table O(NL) O(N) - -
leetcode-202 Happy Number c++, python3 Hash Table O(S) O(1) - -
leetcode-208 Implement Trie Prefix Tree c++, python3 Hash Table O(N) O(L) - -
leetcode-380 Insert Delete Getrandom O1 c++, python3 Hash Table O(1) O(N) - -
leetcode-160 Intersection Of Two Linked Lists c++, python3 Hash Table O(N) O(1) - -
leetcode-205 Isomorphic Strings c++, python3 Hash Table O(N) O(N) - -
leetcode-141 Linked List Cycle c++, python3 Hash Table O(N) O(1) - -
leetcode-142 Linked List Cycle II c++, python3 Hash Table O(N) O(1) - -
leetcode-128 Longest Consecutive Sequence c++, python3 Hash Table O(N) O(N) - -
leetcode-594 Longest Harmonious Subsequence c++, python3 Hash Table O(N) O(N) - -
leetcode-409 Longest Palindrome c++, python3 Hash Table O(N) O(N) - -
leetcode-3 Longest Substring Without Repeating Characters c++, python3 Hash Table O(N) O(N) - -
leetcode-146 Lru Cache c++, python3 Hash Table O(1) O(N) - -
leetcode-169 Majority Element c++, python3 Hash Table O(N) O(1) - -
leetcode-149 Max Points On A Line c++, python3 Hash Table O(N^2) O(N) - -
leetcode-76 Minimum Window Substring c++, python3 Hash Table O(M + N) O(N) Hash + TP -
leetcode-268 Missing Number c++, python3 Hash Table O(N) O(1) - -
leetcode-763 Partition Labels c++, python3 Hash Table O(N) O(N) - -
leetcode-451 Sort Characters By Frequency c++, python3 Hash Table O(N) O(N) - -
leetcode-560 Subarray Sum Equals K c++, python3 Hash Table O(N) O(N) - -
leetcode-572 Subtree Of Another Tree c++, python3 Hash Table O(NM) O(H) - -
leetcode-37 Sudoku Solver c++, python3 Hash Table O(N^(N^2)) O(N) - -
leetcode-347 Top K Frequent Elements c++, python3 Hash Table O(N), O(C*logK) O(N) - -
leetcode-1 Two Sum c++, python3 Hash Table O(N) O(N) - -
leetcode-653 Two Sum Iv Input Is A Bst c++, python3 Hash Table O(NH) O(H) - -
leetcode-242 Valid Anagram c++, python3 Hash Table O(N) O(1) - -
leetcode-36 Valid Sudoku c++, python3 Hash Table O(N^2) O(N^2) - -
leetcode-874 Walking Robot Simulation c++, python3 Hash Table O(N) O(K) - -
leetcode-139 Word Break c++, python3 Hash Table O(MN) O(N) - -
leetcode-126 Word Ladder II c++, python3 Hash Table O((N*L)^C) O(N) - -

Stack

Link Problem(15) Solution Tag Time Space Note Ref
leetcode-227 Basic Calculator II c++, python3 Stack O(N) O(N) - -
leetcode-173 Binary Search Tree Iterator c++, python3 Stack O(1) O(H) InOrder -
leetcode-94 Binary Tree Inorder Traversal c++, python3 Stack O(N) O(H) InOrder -
leetcode-145 Binary Tree Postorder Traversal c++, python3 Stack O(N) O(H) PostOrder -
leetcode-144 Binary Tree Preorder Traversal c++, python3 Stack O(N) O(H) PreOrder -
leetcode-114 Flatten Binary Tree To Linked List c++, python3 Stack O(N) O(H) PreOrder -
leetcode-232 Implement Queue Using Stacks c++, python3 Stack O(*1) O(N) - -
leetcode-225 Implement Stack Using Queues c++, python3 Stack O(N) O(N) - -
leetcode-897 Increasing Order Search Tree c++, python3 Stack O(N) O(H) - -
leetcode-155 Min Stack c++, python3 Stack O(1) O(N) - -
leetcode-1249 Minimum Remove To Make Valid Parentheses c++, python3 Stack O(N) O(N) - -
leetcode-234 Palindrome Linked List c++, python3 Stack O(N) O(1) - -
leetcode-20 Valid Parentheses c++, python3 Stack O(N) O(N) - -
lintcode-849 Basic Calculator III c++, python3 Stack O(N) O(1) Leetcode-772 -
lintcode-859 Max Stack c++, python3 Stack - O(N) Leetcode-716 -

Monotonic Stack

Link Problem(5) Solution Tag Time Space Note Ref
leetcode-739 Daily Temperatures c++, python3 Monotonic Stack O(N) O(N) - -
leetcode-84 Largest Rectangle In Histogram c++, python3 Monotonic Stack O(N) O(N) - -
leetcode-769 Max Chunks To Make Sorted c++, python3 Monotonic Stack O(N) O(1) - -
leetcode-85 Maximal Rectangle c++, python3 Monotonic Stack O(NM) O(M) - -
leetcode-503 Next Greater Element II c++, python3 Monotonic Stack O(N) O(N) - -

Queue

Link Problem(2) Solution Tag Time Space Note Ref
leetcode-232 Implement Queue Using Stacks c++, python3 Queue O(*1) O(N) - -
leetcode-225 Implement Stack Using Queues c++, python3 Queue O(N) O(N) - -

Monotonic Queue

Link Problem(1) Solution Tag Time Space Note Ref
leetcode-239 Sliding Window Maximum c++, python3 Monotonic Queue O(N) O(K) - -

Heap

Link Problem(15) Solution Tag Time Space Note Ref
leetcode-787 Cheapest Flights Within K Stops c++, python3 Heap O(ElogV) O(E+V) - -
leetcode-658 Find K Closest Elements c++, python3 Heap O(Log(N - K)) O(1) Range -
leetcode-3275 K Th Nearest Obstacle Queries c++, python3 Heap O(NlogK) O(K) - -
leetcode-703 Kth Largest Element In A Stream c++, python3 Heap O(logN) O(N) - -
leetcode-215 Kth Largest Element In An Array c++, python3 Heap O(N) ~ O(N^2) O(1) QuickSelection -
leetcode-378 Kth Smallest Element In A Sorted Matrix c++, python3 Heap O(KlogN) O(N) - -
leetcode-23 Merge K Sorted Lists c++, python3 Heap O(NlogK) O(K) - -
leetcode-743 Network Delay Time c++, python3 Heap O(ElogE) O(E+V) - -
leetcode-1514 Path With Maximum Probability c++, python3 Heap O(VlogE) O(V+E) - -
leetcode-1631 Path With Minimum Effort c++, python3 Heap O(NMlogNM) O(NM) - -
leetcode-882 Reachable Nodes In Subdivided Graph c++, python3 Heap O(ElogE) O(V+E) - -
leetcode-239 Sliding Window Maximum c++, python3 Heap O(N) O(K) - -
leetcode-451 Sort Characters By Frequency c++, python3 Heap O(N) O(N) - -
leetcode-218 The Skyline Problem c++, python3 Heap O(NlogN) O(N) - -
leetcode-347 Top K Frequent Elements c++, python3 Heap O(N), O(C*logK) O(N) - -

Two Pointers

Link Problem(26) Solution Tag Time Space Note Ref
leetcode-15 3Sum c++, python3 Two Pointers O(N^2) O(1) - -
leetcode-18 4Sum c++, python3 Two Pointers O(N^3) O(1) - -
leetcode-870 Advantage Shuffle c++, python3 Two Pointers O(NlogN) O(N) - -
leetcode-455 Assign Cookies c++, python3 Two Pointers O(NlogN) O(1) - -
leetcode-696 Count Binary Substrings c++, python3 Two Pointers O(N) O(1) - -
leetcode-287 Find The Duplicate Number c++, python3 Two Pointers O(N) O(1) - -
leetcode-28 Find The Index Of The First Occurrence In A String c++, python3 Two Pointers O(M + N) O(N) - -
leetcode-202 Happy Number c++, python3 Two Pointers O(S) O(1) - -
leetcode-160 Intersection Of Two Linked Lists c++, python3 Two Pointers O(N) O(1) - -
leetcode-141 Linked List Cycle c++, python3 Two Pointers O(N) O(1) - -
leetcode-142 Linked List Cycle II c++, python3 Two Pointers O(N) O(1) - -
leetcode-5 Longest Palindromic Substring c++, python3 Two Pointers O(N) O(N) - -
leetcode-524 Longest Word In Dictionary Through Deleting c++, python3 Two Pointers O(N*logN + M * N) O(1) - -
leetcode-88 Merge Sorted Array c++, python3 Two Pointers O(M + N) O(1) - -
leetcode-876 Middle Of The Linked List c++, python3 Two Pointers O(N) O(1) - -
leetcode-234 Palindrome Linked List c++, python3 Two Pointers O(N) O(1) - -
leetcode-647 Palindromic Substrings c++, python3 Two Pointers O(N^2) O(1) DP Slow -
leetcode-763 Partition Labels c++, python3 Two Pointers O(N) O(N) - -
leetcode-19 Remove Nth Node From End Of List c++, python3 Two Pointers O(N) O(1) - -
leetcode-75 Sort Colors c++, python3 Two Pointers O(N) O(1) - -
leetcode-148 Sort List c++, python3 Two Pointers O(NlogN) O(logN) - -
leetcode-633 Sum Of Square Numbers c++, python3 Two Pointers O(N) O(1) - -
leetcode-167 Two Sum Ii Input Array Is Sorted c++, python3 Two Pointers O(N) O(1) - -
leetcode-653 Two Sum Iv Input Is A Bst c++, python3 Two Pointers O(NH) O(H) - -
leetcode-680 Valid Palindrome II c++, python3 Two Pointers O(N) O(1) - -
lintcode-386 Longest Substring With At Most K Distinct Characters c++, python3 Two Pointers O(N) O(K) Leetcode-159, 340 -

Sliding Window

Link Problem(7) Solution Tag Time Space Note Ref
leetcode-438 Find All Anagrams In A String c++, python3 Sliding Window O(N) O(1) - -
leetcode-658 Find K Closest Elements c++, python3 Sliding Window O(Log(N - K)) O(1) Range -
leetcode-594 Longest Harmonious Subsequence c++, python3 Sliding Window O(N) O(N) - -
leetcode-3 Longest Substring Without Repeating Characters c++, python3 Sliding Window O(N) O(N) - -
leetcode-209 Minimum Size Subarray Sum c++, python3 Sliding Window O(N) O(1) - -
leetcode-76 Minimum Window Substring c++, python3 Sliding Window O(M + N) O(N) Hash + TP -
leetcode-239 Sliding Window Maximum c++, python3 Sliding Window O(N) O(K) - -

Sorting

Link Problem(25) Solution Tag Time Space Note Ref
leetcode-15 3Sum c++, python3 Sorting O(N^2) O(1) - -
leetcode-18 4Sum c++, python3 Sorting O(N^3) O(1) - -
leetcode-870 Advantage Shuffle c++, python3 Sorting O(NlogN) O(N) - -
leetcode-455 Assign Cookies c++, python3 Sorting O(NlogN) O(1) - -
leetcode-217 Contains Duplicate c++, python3 Sorting O(N) O(N) - -
leetcode-658 Find K Closest Elements c++, python3 Sorting O(Log(N - K)) O(1) Range -
leetcode-49 Group Anagrams c++, python3 Sorting O(NL) O(N) - -
leetcode-215 Kth Largest Element In An Array c++, python3 Sorting O(N) ~ O(N^2) O(1) QuickSelection -
leetcode-378 Kth Smallest Element In A Sorted Matrix c++, python3 Sorting O(KlogN) O(N) - -
leetcode-524 Longest Word In Dictionary Through Deleting c++, python3 Sorting O(N*logN + M * N) O(1) - -
leetcode-769 Max Chunks To Make Sorted c++, python3 Sorting O(N) O(1) - -
leetcode-3281 Maximize Score Of Numbers In Ranges c++, python3 Sorting O(NlogN + NlogD) O(1) - -
leetcode-646 Maximum Length Of Pair Chain c++, python3 Sorting O(NlogN) O(N) - -
leetcode-23 Merge K Sorted Lists c++, python3 Sorting O(NlogK) O(K) - -
leetcode-88 Merge Sorted Array c++, python3 Sorting O(M + N) O(1) - -
leetcode-462 Minimum Moves To Equal Array Elements II c++, python3 Sorting O(NlogN) O(1) - -
leetcode-452 Minimum Number Of Arrows To Burst Balloons c++, python3 Sorting O(NlogN) O(1) - -
leetcode-268 Missing Number c++, python3 Sorting O(N) O(1) - -
leetcode-435 Non Overlapping Intervals c++, python3 Sorting O(NlogN) O(1) - -
leetcode-406 Queue Reconstruction By Height c++, python3 Sorting O(NlogN) O(1) - -
leetcode-354 Russian Doll Envelopes c++, python3 Sorting O(NlogN) O(N) - -
leetcode-75 Sort Colors c++, python3 Sorting O(N) O(1) - -
leetcode-148 Sort List c++, python3 Sorting O(NlogN) O(logN) - -
leetcode-242 Valid Anagram c++, python3 Sorting O(N) O(1) - -
lintcode-39 Recover Rotated Sorted Array c++, python3 Sorting O(N) O(1) Rotated -

Counting

Link Problem(5) Solution Tag Time Space Note Ref
leetcode-594 Longest Harmonious Subsequence c++, python3 Counting O(N) O(N) - -
leetcode-169 Majority Element c++, python3 Counting O(N) O(1) - -
leetcode-2529 Maximum Count Of Positive Integer And Negative Integer c++, python3 Counting O(logN) O(1) std::lower_bound -
leetcode-451 Sort Characters By Frequency c++, python3 Counting O(N) O(N) - -
leetcode-347 Top K Frequent Elements c++, python3 Counting O(N), O(C*logK) O(N) - -

Quickselect

Link Problem(2) Solution Tag Time Space Note Ref
leetcode-215 Kth Largest Element In An Array c++, python3 Quickselect O(N) ~ O(N^2) O(1) QuickSelection -
leetcode-347 Top K Frequent Elements c++, python3 Quickselect O(N), O(C*logK) O(N) - -

Divide and Conquer

Link Problem(18) Solution Tag Time Space Note Ref
leetcode-932 Beautiful Array c++, python3 Divide and Conquer O(N) O(N) dp -
leetcode-106 Construct Binary Tree From Inorder And Postorder Traversal c++, python3 Divide and Conquer O(N) O(N) - -
leetcode-105 Construct Binary Tree From Preorder And Inorder Traversal c++, python3 Divide and Conquer O(N) O(N) - -
leetcode-889 Construct Binary Tree From Preorder And Postorder Traversal c++, python3 Divide and Conquer O(N) O(N) - -
leetcode-109 Convert Sorted List To Binary Search Tree c++, python3 Divide and Conquer O(NlogN) O(logN) - -
leetcode-215 Kth Largest Element In An Array c++, python3 Divide and Conquer O(N) ~ O(N^2) O(1) QuickSelection -
leetcode-169 Majority Element c++, python3 Divide and Conquer O(N) O(1) - -
leetcode-53 Maximum Subarray c++, python3 Divide and Conquer O(N) O(N) - -
leetcode-4 Median Of Two Sorted Arrays c++, python3 Divide and Conquer O(log(min(M, N))) O(1) - -
leetcode-23 Merge K Sorted Lists c++, python3 Divide and Conquer O(NlogK) O(K) - -
leetcode-191 Number Of 1 Bits c++, python3 Divide and Conquer O(1) O(1) - -
leetcode-190 Reverse Bits c++, python3 Divide and Conquer O(1) O(1) - -
leetcode-240 Search A 2D Matrix II c++, python3 Divide and Conquer O(M + N) O(1) Matrix -
leetcode-148 Sort List c++, python3 Divide and Conquer O(NlogN) O(logN) - -
leetcode-218 The Skyline Problem c++, python3 Divide and Conquer O(NlogN) O(N) - -
leetcode-347 Top K Frequent Elements c++, python3 Divide and Conquer O(N), O(C*logK) O(N) - -
lintcode-1534 Convert Binary Search Tree To Sorted Doubly Linked List c++, python3 Divide and Conquer O(N) O(H) BST | Leetcode-426 -
lintcode-11 Search Range In Binary Search Tree c++, python3 Divide and Conquer O(N) O(H) InOrder -

Breadth-First Search

Link Problem(26) Solution Tag Time Space Note Ref
leetcode-542 01 Matrix c++, python3 Breadth-First Search O(MN) O(MN) - -
leetcode-637 Average Of Levels In Binary Tree c++, python3 Breadth-First Search O(N) O(N) - -
leetcode-102 Binary Tree Level Order Traversal c++, python3 Breadth-First Search O(N) O(Width) Level -
leetcode-322 Coin Change c++, python3 Breadth-First Search O(K * N) O(N) Index Video
leetcode-513 Find Bottom Left Tree Value c++, python3 Breadth-First Search O(N) O(W) - -
leetcode-226 Invert Binary Tree c++, python3 Breadth-First Search O(N) O(H) - -
leetcode-785 Is Graph Bipartite c++, python3 Breadth-First Search O(E+V) O(W) - -
leetcode-695 Max Area Of Island c++, python3 Breadth-First Search O(MN) O(MN) - -
leetcode-104 Maximum Depth Of Binary Tree c++, python3 Breadth-First Search O(N) O(H) Recursion -
leetcode-617 Merge Two Binary Trees c++, python3 Breadth-First Search O(N) O(H) - -
leetcode-530 Minimum Absolute Difference In Bst c++, python3 Breadth-First Search O(N) O(H) - -
leetcode-111 Minimum Depth Of Binary Tree c++, python3 Breadth-First Search O(N) O(W) - -
leetcode-200 Number Of Islands c++, python3 Breadth-First Search O(MN) O(MN) - -
leetcode-547 Number Of Provinces c++, python3 Breadth-First Search O(N^2) O(N) - -
leetcode-417 Pacific Atlantic Water Flow c++, python3 Breadth-First Search O(MN) O(MN) - -
leetcode-1631 Path With Minimum Effort c++, python3 Breadth-First Search O(NMlogNM) O(NM) - -
leetcode-279 Perfect Squares c++, python3 Breadth-First Search O(NlogN) O(N) - -
leetcode-684 Redundant Connection c++, python3 Breadth-First Search O(N) O(1) - -
leetcode-297 Serialize And Deserialize Binary Tree c++, python3 Breadth-First Search O(N) O(N) Serialization -
leetcode-934 Shortest Bridge c++, python3 Breadth-First Search O(N^2) O(N^2) - -
leetcode-404 Sum Of Left Leaves c++, python3 Breadth-First Search O(N) O(H) - -
leetcode-130 Surrounded Regions c++, python3 Breadth-First Search O(MN) O(1) - -
leetcode-101 Symmetric Tree c++, python3 Breadth-First Search O(N) O(H) - -
leetcode-653 Two Sum Iv Input Is A Bst c++, python3 Breadth-First Search O(NH) O(H) - -
leetcode-126 Word Ladder II c++, python3 Breadth-First Search O((N*L)^C) O(N) - -
lintcode-178 Graph Valid Tree c++, python3 Breadth-First Search O(N) O(N) LeetCode-261 -

Depth-First Search

Link Problem(38) Solution Tag Time Space Note Ref
leetcode-637 Average Of Levels In Binary Tree c++, python3 Depth-First Search O(N) O(N) - -
leetcode-110 Balanced Binary Tree c++, python3 Depth-First Search O(N) O(H) Recursion -
leetcode-94 Binary Tree Inorder Traversal c++, python3 Depth-First Search O(N) O(H) InOrder -
leetcode-145 Binary Tree Postorder Traversal c++, python3 Depth-First Search O(N) O(H) PostOrder -
leetcode-144 Binary Tree Preorder Traversal c++, python3 Depth-First Search O(N) O(H) PreOrder -
leetcode-538 Convert Bst To Greater Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-1110 Delete Nodes And Return Forest c++, python3 Depth-First Search O(N) O(N) - -
leetcode-543 Diameter Of Binary Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-513 Find Bottom Left Tree Value c++, python3 Depth-First Search O(N) O(W) - -
leetcode-114 Flatten Binary Tree To Linked List c++, python3 Depth-First Search O(N) O(H) PreOrder -
leetcode-897 Increasing Order Search Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-226 Invert Binary Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-785 Is Graph Bipartite c++, python3 Depth-First Search O(E+V) O(W) - -
leetcode-235 Lowest Common Ancestor Of A Binary Search Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-236 Lowest Common Ancestor Of A Binary Tree c++, python3 Depth-First Search O(N) O(H) Recursion -
leetcode-695 Max Area Of Island c++, python3 Depth-First Search O(MN) O(MN) - -
leetcode-104 Maximum Depth Of Binary Tree c++, python3 Depth-First Search O(N) O(H) Recursion -
leetcode-617 Merge Two Binary Trees c++, python3 Depth-First Search O(N) O(H) - -
leetcode-530 Minimum Absolute Difference In Bst c++, python3 Depth-First Search O(N) O(H) - -
leetcode-111 Minimum Depth Of Binary Tree c++, python3 Depth-First Search O(N) O(W) - -
leetcode-200 Number Of Islands c++, python3 Depth-First Search O(MN) O(MN) - -
leetcode-547 Number Of Provinces c++, python3 Depth-First Search O(N^2) O(N) - -
leetcode-417 Pacific Atlantic Water Flow c++, python3 Depth-First Search O(MN) O(MN) - -
leetcode-437 Path Sum III c++, python3 Depth-First Search O(N^2) O(H) - -
leetcode-1631 Path With Minimum Effort c++, python3 Depth-First Search O(NMlogNM) O(NM) - -
leetcode-332 Reconstruct Itinerary c++, python3 Depth-First Search O(ElogE) O(E+V) Containers -
leetcode-99 Recover Binary Search Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-684 Redundant Connection c++, python3 Depth-First Search O(N) O(1) - -
leetcode-297 Serialize And Deserialize Binary Tree c++, python3 Depth-First Search O(N) O(N) Serialization -
leetcode-934 Shortest Bridge c++, python3 Depth-First Search O(N^2) O(N^2) - -
leetcode-572 Subtree Of Another Tree c++, python3 Depth-First Search O(NM) O(H) - -
leetcode-404 Sum Of Left Leaves c++, python3 Depth-First Search O(N) O(H) - -
leetcode-130 Surrounded Regions c++, python3 Depth-First Search O(MN) O(1) - -
leetcode-101 Symmetric Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-669 Trim A Binary Search Tree c++, python3 Depth-First Search O(N) O(H) - -
leetcode-653 Two Sum Iv Input Is A Bst c++, python3 Depth-First Search O(NH) O(H) - -
leetcode-98 Validate Binary Search Tree c++, python3 Depth-First Search O(N) O(H) BST -
lintcode-11 Search Range In Binary Search Tree c++, python3 Depth-First Search O(N) O(H) InOrder -

Topological Sort

Link Problem(2) Solution Tag Time Space Note Ref
leetcode-210 Course Schedule II c++, python3 Topological Sort O(E+V) O(E+V) - -
leetcode-310 Minimum Height Trees c++, python3 Topological Sort O(N) O(N) - -

Shortest Path

Link Problem(4) Solution Tag Time Space Note Ref
leetcode-787 Cheapest Flights Within K Stops c++, python3 Shortest Path O(ElogV) O(E+V) - -
leetcode-743 Network Delay Time c++, python3 Shortest Path O(ElogE) O(E+V) - -
leetcode-1514 Path With Maximum Probability c++, python3 Shortest Path O(VlogE) O(V+E) - -
leetcode-882 Reachable Nodes In Subdivided Graph c++, python3 Shortest Path O(ElogE) O(V+E) - -

Backtracking

Link Problem(13) Solution Tag Time Space Note Ref
leetcode-257 Binary Tree Paths c++, python3 Backtracking O(N) O(H) - -
leetcode-40 Combination Sum II c++, python3 Backtracking O(2^N) O(N) - -
leetcode-77 Combinations c++, python3 Backtracking O(k * C(n, k)) O(K) - -
leetcode-22 Generate Parentheses c++, python3 Backtracking O(2^N) O(N) Catalan Number -
leetcode-51 N Queens c++, python3 Backtracking O(N!) O(N) - -
leetcode-52 N Queens II c++, python3 Backtracking O(N!) O(N) - -
leetcode-46 Permutations c++, python3 Backtracking O(N!) O(N) - -
leetcode-47 Permutations II c++, python3 Backtracking O(N!) O(N) - -
leetcode-37 Sudoku Solver c++, python3 Backtracking O(N^(N^2)) O(N) - -
leetcode-494 Target Sum c++, python3 Backtracking O(N * Sum) O(N * Sum) - -
leetcode-126 Word Ladder II c++, python3 Backtracking O((N*L)^C) O(N) - -
leetcode-79 Word Search c++, python3 Backtracking O(MN*4^L) O(MN) - -
leetcode-212 Word Search II c++, python3 Backtracking O(NM*4^L) O(MN + KL) - -

Line Sweep

Link Problem(1) Solution Tag Time Space Note Ref
leetcode-218 The Skyline Problem c++, python3 Line Sweep O(NlogN) O(N) - -

Ordered Set

Link Problem(1) Solution Tag Time Space Note Ref
leetcode-218 The Skyline Problem c++, python3 Ordered Set O(NlogN) O(N) - -

Binary Search Tree

Link Problem(16) Solution Tag Time Space Note Ref
leetcode-173 Binary Search Tree Iterator c++, python3 Binary Search Tree O(1) O(H) InOrder -
leetcode-538 Convert Bst To Greater Tree c++, python3 Binary Search Tree O(N) O(H) - -
leetcode-109 Convert Sorted List To Binary Search Tree c++, python3 Binary Search Tree O(NlogN) O(logN) - -
leetcode-450 Delete Node In A Bst c++, python3 Binary Search Tree O(H) O(H) Delete -
leetcode-897 Increasing Order Search Tree c++, python3 Binary Search Tree O(N) O(H) - -
leetcode-701 Insert Into A Binary Search Tree c++, python3 Binary Search Tree O(H) O(H) Insert -
leetcode-703 Kth Largest Element In A Stream c++, python3 Binary Search Tree O(logN) O(N) - -
leetcode-235 Lowest Common Ancestor Of A Binary Search Tree c++, python3 Binary Search Tree O(N) O(H) - -
leetcode-530 Minimum Absolute Difference In Bst c++, python3 Binary Search Tree O(N) O(H) - -
leetcode-99 Recover Binary Search Tree c++, python3 Binary Search Tree O(N) O(H) - -
leetcode-669 Trim A Binary Search Tree c++, python3 Binary Search Tree O(N) O(H) - -
leetcode-653 Two Sum Iv Input Is A Bst c++, python3 Binary Search Tree O(NH) O(H) - -
leetcode-98 Validate Binary Search Tree c++, python3 Binary Search Tree O(N) O(H) BST -
lintcode-1534 Convert Binary Search Tree To Sorted Doubly Linked List c++, python3 Binary Search Tree O(N) O(H) BST | Leetcode-426 -
lintcode-448 Inorder Successor In Bst c++, python3 Binary Search Tree O(H) O(1) Successor | Leetcode-285 -
lintcode-11 Search Range In Binary Search Tree c++, python3 Binary Search Tree O(N) O(H) InOrder -

Binary Indexed Tree

Link Problem(3) Solution Tag Time Space Note Ref
leetcode-406 Queue Reconstruction By Height c++, python3 Binary Indexed Tree O(NlogN) O(1) - -
leetcode-307 Range Sum Query Mutable c++, python3 Binary Indexed Tree O(logN) O(N) - -
leetcode-218 The Skyline Problem c++, python3 Binary Indexed Tree O(NlogN) O(N) - -

Segment Tree

Link Problem(7) Solution Tag Time Space Note Ref
leetcode-406 Queue Reconstruction By Height c++, python3 Segment Tree O(NlogN) O(1) - -
leetcode-307 Range Sum Query Mutable c++, python3 Segment Tree O(logN) O(N) - -
leetcode-218 The Skyline Problem c++, python3 Segment Tree O(NlogN) O(N) - -
lintcode-205 Interval Minimum Number c++, python3 Segment Tree O(NlogN) O(N) - -
lintcode-201 Segment Tree Build c++, python3 Segment Tree O(N) O(1) - -
lintcode-439 Segment Tree Build II c++, python3 Segment Tree O(N) O(1) - -
lintcode-203 Segment Tree Modify c++, python3 Segment Tree O(logN) O(1) - -

Union Find

Link Problem(12) Solution Tag Time Space Note Ref
leetcode-785 Is Graph Bipartite c++, python3 Union Find O(E+V) O(W) - -
leetcode-128 Longest Consecutive Sequence c++, python3 Union Find O(N) O(N) - -
leetcode-695 Max Area Of Island c++, python3 Union Find O(MN) O(MN) - -
leetcode-200 Number Of Islands c++, python3 Union Find O(MN) O(MN) - -
leetcode-547 Number Of Provinces c++, python3 Union Find O(N^2) O(N) - -
leetcode-1631 Path With Minimum Effort c++, python3 Union Find O(NMlogNM) O(NM) - -
leetcode-684 Redundant Connection c++, python3 Union Find O(N) O(1) - -
leetcode-130 Surrounded Regions c++, python3 Union Find O(MN) O(1) - -
lintcode-3672 Connecting Cities With Minimum Cost c++, python3 Union Find O(ElogE) O(E+V) Leetcode-1135 -
lintcode-591 Connecting Graph III c++, python3 Union Find O(N) O(N) - -
lintcode-178 Graph Valid Tree c++, python3 Union Find O(N) O(N) LeetCode-261 -
lintcode-434 Number Of Islands II c++, python3 Union Find O(K) O(NM + K) leetcode-305 -

Trie

Link Problem(3) Solution Tag Time Space Note Ref
leetcode-208 Implement Trie Prefix Tree c++, python3 Trie O(N) O(L) - -
leetcode-139 Word Break c++, python3 Trie O(MN) O(N) - -
leetcode-212 Word Search II c++, python3 Trie O(NM*4^L) O(MN + KL) - -

Array

Link Problem(4) Solution Tag Time Space Note Ref
leetcode-2210 Count Hills And Valleys In An Array c++, python3 Array O(N) O(1) - -
leetcode-674 Longest Continuous Increasing Subsequence c++, python3 Array O(N) O(1) - -
leetcode-665 Non Decreasing Array c++, python3 Array O(N) O(1) - -
leetcode-238 Product Of Array Except Self c++, python3 Array O(N) O(1) - -

String

Link Problem(1) Solution Tag Time Space Note Ref
lintcode-1790 Rotate String II c++, python3 String O(N) O(N) Simulation -

Other

Link Problem(149) Solution Tag Time Space Note Ref
leetcode-16 3Sum Closest c++, python3 Other - - - -
leetcode-454 4Sum II c++ Other - - - -
leetcode-721 Accounts Merge c++, python3 Other - - - -
leetcode-211 Add And Search Word Data Structure Design c++, python3 Other - - - -
leetcode-2 Add Two Numbers c++, python3 Other - - - -
leetcode-269 Alien Dictionary python3 Other - - - -
leetcode-561 Array Partition I c++ Other - - - -
leetcode-844 Backspace String Compare c++, python3 Other - - - -
leetcode-107 Binary Tree Level Order Traversal II c++, python3 Other - - - -
leetcode-156 Binary Tree Upside Down c++, python3 Other - - - -
leetcode-314 Binary Tree Vertical Order Traversal c++, python3 Other - - - -
leetcode-103 Binary Tree Zigzag Level Order Traversal c++, python3 Other - - - -
leetcode-859 Buddy Strings c++ Other - - - -
leetcode-815 Bus Routes python3 Other - - - -
leetcode-1150 Check If A Number Is Majority Element In A Sorted Array c++, python3 Other - - - -
leetcode-133 Clone Graph c++, python3 Other - - - -
leetcode-270 Closest Binary Search Tree Value c++, python3 Other - - - -
leetcode-39 Combination Sum c++, python3 Other - - - -
leetcode-377 Combination Sum IV c++, python3 Other - - - -
leetcode-175 Combine Two Tables sql Other - - - -
leetcode-829 Consecutive Numbers Sum python3 Other - - - -
leetcode-11 Container With Most Water python3 Other - - - -
leetcode-219 Contains Duplicate II c++ Other - - - -
leetcode-138 Copy List With Random Pointer python3 Other - - - -
leetcode-38 Count And Say python3 Other - - - -
leetcode-207 Course Schedule c++, python3 Other - - - -
leetcode-394 Decode String c++, python3 Other - - - -
leetcode-237 Delete Node In A Linked List python3 Other - - - -
leetcode-498 Diagonal Traverse c++ Other - - - -
leetcode-29 Divide Two Integers c++, python3 Other - - - -
leetcode-271 Encode And Decode Strings c++, python3 Other - - - -
leetcode-535 Encode And Decode Tinyurl python3 Other - - - -
leetcode-282 Expression Add Operators c++, python3 Other - - - -
leetcode-760 Find Anagram Mappings python3 Other - - - -
leetcode-652 Find Duplicate Subtrees c++ Other - - - -
leetcode-366 Find Leaves Of Binary Tree c++, python3 Other - - - -
leetcode-295 Find Median From Data Stream c++, python3 Other - - - -
leetcode-724 Find Pivot Index c++ Other - - - -
leetcode-277 Find The Celebrity c++, python3 Other - - - -
leetcode-41 First Missing Positive python3 Other - - - -
leetcode-387 First Unique Character In A String c++, python3 Other - - - -
leetcode-251 Flatten 2D Vector python3 Other - - - -
leetcode-341 Flatten Nested List Iterator python3 Other - - - -
leetcode-832 Flipping An Image python3 Other - - - -
leetcode-289 Game Of Life python3 Other - - - -
leetcode-249 Group Shifted Strings c++ Other - - - -
leetcode-57 Insert Interval c++, python3 Other - - - -
leetcode-273 Integer To English Words python3 Other - - - -
leetcode-12 Integer To Roman c++, python3 Other - - - -
leetcode-349 Intersection Of Two Arrays c++, python3 Other - - - -
leetcode-350 Intersection Of Two Arrays II c++, python3 Other - - - -
leetcode-751 Ip To Cidr python3 Other - - - -
leetcode-463 Island Perimeter python3 Other - - - -
leetcode-771 Jewels And Stones c++ Other - - - -
leetcode-45 Jump Game II c++, python3 Other - - - -
leetcode-532 K Diff Pairs In An Array c++, python3 Other - - - -
leetcode-683 K Empty Slots c++, python3 Other - - - -
leetcode-368 Largest Divisible Subset c++, python3 Other - - - -
leetcode-747 Largest Number At Least Twice Of Others c++ Other - - - -
leetcode-17 Letter Combinations Of A Phone Number c++, python3 Other - - - -
leetcode-359 Logger Rate Limiter c++ Other - - - -
leetcode-388 Longest Absolute File Path c++, python3 Other - - - -
leetcode-14 Longest Common Prefix c++, python3 Other - - - -
leetcode-687 Longest Univalue Path c++, python3 Other - - - -
leetcode-229 Majority Element II c++, python3 Other - - - -
leetcode-677 Map Sum Pairs c++, python3 Other - - - -
leetcode-485 Max Consecutive Ones c++ Other - - - -
leetcode-654 Maximum Binary Tree c++, python3 Other - - - -
leetcode-253 Meeting Rooms II c++, python3 Other - - - -
leetcode-56 Merge Intervals c++, python3 Other - - - -
leetcode-924 Minimize Malware Spread python3 Other - - - -
leetcode-928 Minimize Malware Spread II python3 Other - - - -
leetcode-433 Minimum Genetic Mutation c++, python3 Other - - - -
leetcode-599 Minimum Index Sum Of Two Lists c++ Other - - - -
leetcode-163 Missing Ranges c++, python3 Other - - - -
leetcode-283 Move Zeroes c++, python3 Other - - - -
leetcode-346 Moving Average From Data Stream c++, python3 Other - - - -
leetcode-43 Multiply Strings c++, python3 Other - - - -
leetcode-31 Next Permutation c++, python3 Other - - - -
leetcode-447 Number Of Boomerangs c++, python3 Other - - - -
leetcode-323 Number Of Connected Components In An Undirected Graph c++, python3 Other - - - -
leetcode-933 Number Of Recent Calls c++, python3 Other - - - -
leetcode-161 One Edit Distance c++, python3 Other - - - -
leetcode-276 Paint Fence c++, python3 Other - - - -
leetcode-9 Palindrome Number c++, python3 Other - - - -
leetcode-336 Palindrome Pairs python3 Other - - - -
leetcode-131 Palindrome Partitioning c++, python3 Other - - - -
leetcode-86 Partition List c++, python3 Other - - - -
leetcode-118 Pascals Triangle c++, python3 Other - - - -
leetcode-119 Pascals Triangle II c++, python3 Other - - - -
leetcode-66 Plus One c++, python3 Other - - - -
leetcode-755 Pour Water python3 Other - - - -
leetcode-370 Range Addition c++, python3 Other - - - -
leetcode-157 Read N Characters Given Read4 c++, python3 Other - - - -
leetcode-836 Rectangle Overlap c++, python3 Other - - - -
leetcode-26 Remove Duplicates From Sorted Array c++, python3 Other - - - -
leetcode-27 Remove Element c++, python3 Other - - - -
leetcode-203 Remove Linked List Elements python3 Other - - - -
leetcode-143 Reorder List python3 Other - - - -
leetcode-7 Reverse Integer c++, python3 Other - - - -
leetcode-92 Reverse Linked List II c++, python3 Other - - - -
leetcode-344 Reverse String c++, python3 Other - - - -
leetcode-345 Reverse Vowels Of A String c++, python3 Other - - - -
leetcode-657 Robot Return To Origin python3 Other - - - -
leetcode-13 Roman To Integer c++, python3 Other - - - -
leetcode-61 Rotate List python3 Other - - - -
leetcode-796 Rotate String c++, python3 Other - - - -
leetcode-702 Search In A Sorted Array Of Unknown Size c++, python3 Other - - - -
leetcode-444 Sequence Reconstruction c++, python3 Other - - - -
leetcode-773 Sliding Puzzle python3 Other - - - -
leetcode-311 Sparse Matrix Multiplication c++, python3 Other - - - -
leetcode-54 Spiral Matrix c++, python3 Other - - - -
leetcode-8 String To Integer Atoi c++, python3 Other - - - -
leetcode-246 Strobogrammatic Number c++, python3 Other - - - -
leetcode-78 Subsets c++, python3 Other - - - -
leetcode-90 Subsets II c++, python3 Other - - - -
leetcode-30 Substring With Concatenation Of All Words c++, python3 Other - - - -
leetcode-228 Summary Ranges python3 Other - - - -
leetcode-68 Text Justification python3 Other - - - -
leetcode-42 Trapping Rain Water c++, python3 Other - - - -
leetcode-407 Trapping Rain Water II c++, python3 Other - - - -
leetcode-170 Two Sum Iii Data Structure Design c++, python3 Other - - - -
leetcode-929 Unique Email Addresses python3 Other - - - -
leetcode-288 Unique Word Abbreviation c++, python3 Other - - - -
leetcode-393 Utf 8 Validation c++, python3 Other - - - -
leetcode-125 Valid Palindrome c++, python3 Other - - - -
leetcode-408 Valid Word Abbreviation c++, python3 Other - - - -
leetcode-286 Walls And Gates c++, python3 Other - - - -
leetcode-280 Wiggle Sort python3 Other - - - -
leetcode-324 Wiggle Sort II python3 Other - - - -
leetcode-527 Word Abbreviation c++, python3 Other - - - -
leetcode-127 Word Ladder c++, python3 Other - - - -
leetcode-425 Word Squares c++, python3 Other - - - -
leetcode-6 Zigzag Conversion python3 Other - - - -
lintcode-652 Factorization c++, python3 Other - - - -
lintcode-390 Find Peak Element II c++, python3 Other - - - -
lintcode-144 Interleaving Positive And Negative Numbers c++, python3 Other - - - -
lintcode-611 Knight Shortest Path c++, python3 Other - - - -
lintcode-526 Load Balancer c++, python3 Other - - - -
lintcode-629 Minimum Spanning Tree c++, python3 Other - - - -
lintcode-391 Number Of Airplanes In The Sky c++, python3 Other - - - -
lintcode-31 Partition Array python3 Other - - - -
lintcode-618 Search Graph Nodes c++, python3 Other - - - -
lintcode-447 Search In A Big Sorted Array c++, python3 Other - - - -
lintcode-586 Sqrtx II c++, python3 Other - - - -
lintcode-139 Subarray Sum Closest c++, python3 Other - - - -
lintcode-382 Triangle Count c++, python3 Other - - - -
lintcode-183 Wood Cut c++, python3 Other - - - -
lintcode-598 Zombie In Matrix c++, python3 Other - - - -

About

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

Topics

Resources

License

Stars

Watchers

Forks