Home

Awesome

home

Disclaimer: 这里的题目跟具体的面试毫无关系, 也没有任何指向性; 这些题目是我当年在努力刷题的过程中积累下来的经验和总结!

简介

这个站点已经开启超过7年, 很高兴它可以帮到有需要的人. 信息有价, 知识无价, 每逢闲暇, 我会来维护这个repo, 给刷题的朋友们一些我的想法和见解. 下面来简单介绍一下:

001 | about 土汪

tuwangbrick.substack.com 是2022年开启的一个news letter周刊, 每周一更新, 内容是一些工作上遇到的思考, 介绍些遇到的新工具, 偶尔吐槽. 欢迎大家订阅我的周刊. 或者订阅RSS Feed: https://tuwangbrick.substack.com/feed.

○ 📅 欢迎大家在Calendly上跟我约时间1:1, 聊工作生活

○ 👨‍💻 Social Media: YouTube, 小红书, B站, Twitter

○ 🎙 Podcast: 土汪遛弯儿 (小宇宙, Spotify, Apple Podcast)

○ 💬 Chat: 微信 TuwangZ, Discord - tuwang

Youtube 频道: 土汪遛弯儿未来会持续更新在北美科技行业工作的故事和经验. 有任何程序员工作的疑问, 可以加入上面的discord留言.

希望大家学习顺利, 对未来充满希望!

002 | 目录 Java Algorithm Problems

Leetcode#ProblemLevelTagsTimeSpaceLanguageSequence
N/AJump Game II.javaHard[Array, Coordinate DP, DP, Greedy]O(n)O(1)Java0
N/AMajority Number II.javaMedium[Enumeration, Greedy]Java1
N/ASearch a 2D Matrix II.javaMedium[Binary Search, Divide and Conquer]Java2
N/AMissing Ranges.javaMedium[Array]Java3
N/AInorder Successor in BST.javaMedium[BST, Tree]Java4
N/AConvert Integer A to Integer B.javaEasy[Bit Manipulation]Java5
N/ABackpack VI.javaMedium[Backpack DP, DP]Java6
N/ATotal Occurrence of Target.javaMedium[]Java7
N/AHouse Robber III.javaMedium[DFS, DP, Status DP, Tree]Java8
N/ABinary Tree Maximum Path Sum II.javaMedium[DFS, Tree]Java9
N/ABackpack V.javaMedium[Backpack DP, DP]Java10
N/AClosest Number in Sorted Array.javaEasy[Binary Search]Java11
N/AConvert Expression to Polish Notation.javaHard[Binary Tree, DFS, Expression Tree, Stack]Java12
N/AMissing Number.javaEasy[Array, Bit Manipulation, Math]Java13
N/ARestore IP Addresses.javaMedium[Backtracking, DFS, String]Java14
N/ALinked List Cycle II.javaMedium[Linked List, Math, Two Pointers]Java15
N/AUnique Binary Search Tree.javaMedium[BST, DP, Tree]Java16
N/ALargest Number.javaMedium[Sort]Java17
N/AReverse String.javaEasy[String, Two Pointers]Java18
N/ATriangles.javaMedium[Array, Coordinate DP, DFS, DP, Memoization]Java19
N/AFrog Jump.javaHard[DP, Hash Table]Java20
N/ASummary Ranges.javaMedium[Array]Java21
N/ASliding Window Median.javaHard[Design, Heap, MaxHeap, MinHeap, Sliding Window]Java22
N/ASingle Number III.javaMedium[Bit Manipulation]Java23
N/ATrailing Zeros.javaEasy[Math]Java24
N/AFast Power.javaMedium[DFS, Divide and Conquer]Java25
N/APerfect Rectangle.javaHard[Design, Geometry, Hash Table]Java26
N/ATotal Hamming Distance.javaMedium[Bit Manipulation]O(n)O(1), 32-bit arrayJava27
N/AWord Pattern.javaEasy[]Java28
N/ATwo Sum IV - Input is a BST.javaEasy[Tree]Java29
N/ACount 1 in Binary.javaEasy[Bit Manipulation]Java30
N/ATwo Lists Sum.javaMedium[Linked List]Java31
N/AFlatten 2D Vector.javaMedium[Design]Java32
N/AHamming Distance.javaEasy[]Java33
N/AFind the Weak Connected Component in the Directed Graph.javaMedium[Union Find]Java34
N/AInterval Minimum Number.javaMedium[Binary Search, Divide and Conquer, Lint, Segment Tree]Java35
N/AStone Game.javaMedium[DP]Java36
N/ALongest Increasing Continuous subsequence II.javaMedium[Array, Coordinate DP, DP, Memoization]Java37
N/APlus One.javaEasy[Array, Math]Java38
N/APaint Fence.javaEasy[DP, Sequence DP]O(n)O(n)Java39
N/ALine Reflection.javaMedium[Hash Table, Math]O(n)O(n)Java40
N/ABinary Representation.javaHard[Bit Manipulation, String]Java41
N/ALongest Consecutive Sequence.javaHard[Array, Hash Table, Union Find]Java42
N/AFind Minimum in Rotated Sorted Array.javaMedium[Array, Binary Search]Java43
N/ABinary Tree Longest Consecutive Sequence II.javaMedium[DFS, Divide and Conquer, Double Recursive, Tree]Java44
N/AMinimum Subarray.javaEasy[Array, DP, Greedy, Sequence DP, Subarray]O(m)O(1)Java45
N/AConnecting Graph.javaMedium[Union Find]Java46
N/ACount of Smaller Number.javaMedium[Binary Search, Lint, Segment Tree]Java47
N/ABinary Gap.javaEasy[Bit Manipulation]O(n), n = # of bitsO(1)Java48
N/AFlip Game II.javaMedium[Backtracking, DFS, DP]Java49
N/ASubtree of Another Tree.javaEasy[DFS, Divide and Conquer, Tree]Java50
N/ABinary Tree Level Order Traversal II.javaMedium[BFS, Tree]Java51
N/AMaximum Average Subarray I.javaEasy[Array, Subarray]O(n)O(1)Java52
N/AIndexMatch.javaEasy[]Java53
N/AWalls and Gates.javaMedium[BFS, DFS]Java54
N/ADecode String.javaMedium[DFS, Divide and Conquer, Stack]Java55
N/AThe Maze.javaMedium[BFS, DFS]Java56
N/APalindromic Substrings.javaMedium[DP, String]Java57
N/ARearrange String k Distance Apart.javaHard[Greedy, Hash Table, Heap]Java58
N/ACount and Say.javaEasy[Basic Implementation, String]Java59
N/AMedian of Two Sorted Arrays.javaHard[Array, Binary Search, DFS, Divide and Conquer]Java60
N/APerfect Squares.javaMedium[BFS, DP, Math, Partition DP]Java61
N/AWord Search.javaMedium[Array, Backtracking, DFS]Java62
N/ABackpack II.javaMedium[Backpack DP, DP]Java63
N/AReshape the Matrix.javaEasy[]Java64
N/AUpdate Bits.javaMedium[Bit Manipulation]Java65
N/ATriangle Count.javaMedium[Array]Java66
N/ARemove Duplicate Letters.javaHard[Greedy, Hash Table, Stack]Java67
N/APermutation Sequence.javaMedium[Backtracking, Math]Java68
N/AHouse Robber II.javaMedium[DP, Sequence DP, Status DP]Java69
N/AO(1) Check Power of 2.javaEasy[Bit Manipulation]Java70
N/ALetter Combinations of a Phone Number.javaMedium[Backtracking, String]Java71
N/ABackspace String Compare.javaEasy[Stack, Two Pointers]Java72
N/AMinimum Size Subarray Sum.javaMedium[Array, Binary Search, Subarray, Two Pointers]O(n)O(1)Java73
N/AImplement Stack using Queues.javaEasy[Design, Stack]Java74
N/AMinimum Absolute Difference in BST.javaEasy[BST]Java75
N/AMaximum Binary Tree.javaMedium[Stack, Tree]Java76
N/AColorGrid.javaMedium[Design, Hash Table]Java77
N/AHashWithArray.javaEasy[]Java78
N/AFlood Fill.javaEasy[DFS]Java79
N/AConstruct Binary Tree from Inorder and Postorder Traversal.javaMedium[Array, DFS, Divide and Conquer, Tree]Java80
N/ABackpack.javaMedium[Backpack DP, DP]Java81
N/ALongest Common Subsequence.javaMedium[DP, Double Sequence DP, Sequence DP]Java82
N/APeeking Iterator.javaMedium[Design]Java83
N/AOrderly Queue.javaHard[Math, String]Java84
N/AQuickSort.javaMedium[Quick Sort, Sort]Java85
N/AMaximal Rectangle.javaHard[Array, DP, Hash Table, Stack]Java86
N/AExpression Evaluation.javaHard[Binary Tree, DFS, Expression Tree, Minimum Binary Tree, Stack]Java87
N/ASubtree.javaEasy[DFS, Tree]Java88
N/ALFU Cache.javaHard[Design, Hash Table]Java89
N/ACosine Similarity.javaEasy[Basic Implementation]Java90
N/AScramble String.javaHard[DP, Interval DP, String]Java91
N/ARedundant Connection.javaMedium[BFS, DFS, Graph, Tree, Union Find]Java92
N/ARotate List.javaMedium[Linked List, Two Pointers]Java93
N/ASwap Nodes in Pairs.javaMedium[Linked List]Java94
N/ALongest Increasing Continuous subsequence.javaEasy[Array, Coordinate DP, DP]Java95
N/AK Edit Distance.javaHard[DP, Double Sequence DP, Sequence DP, Trie]Java96
N/ACombinations.javaMedium[Backtracking, Combination, DFS]Java97
N/AMax Area of Island.javaEasy[Array, DFS]Java98
N/ASort List.javaMedium[Divide and Conquer, Linked List, Merge Sort, Sort]Java99
N/AFind Peak Element.javaMedium[Array, Binary Search]Java100
N/AWord Search II.javaHard[Backtracking, DFS, Trie]Java101
N/AK Empty Slots.javaHard[Array, BST, TreeSet]Java102
N/AGray Code.javaMedium[Backtracking]Java103
N/AEncode and Decode TinyURL.javaMedium[Hash Table, Math]Java104
N/AGame of Life.javaMedium[Array]Java105
N/ACompare Version Numbers.javaMedium[String]Java106
N/ASingleton.javaEasy[Design]Java107
N/AUgly Number.javaMedium[Math]Java108
N/ARussian Doll Envelopes.javaHard[Binary Search, Coordinate DP, DP]Java109
N/ARehashing.javaMedium[Hash Table]Java110
N/AKth Smallest Sum In Two Sorted Arrays.javaHard[]Java111
N/ALongest Common Substring.javaMedium[DP, Double Sequence DP, Sequence DP, String]Java112
N/ARotate Image.javaMedium[Array, Enumeration]Java113
N/ABackpack III.javaHard[Backpack DP, DP]Java114
N/ACombination Sum IV.javaMedium[Array, Backpack DP, DP]Java115
N/ANumber of Longest Increasing Subsequence.javaMedium[Coordinate DP, DP]O(n^2)Java116
N/APermutation Index.javaEasy[]Java117
N/A4Sum.javaMedium[Hash Table]Java118
N/AShortest Palindrome.javaHard[KMP, String]Java119
N/AConvert Sorted Array to Binary Search Tree.javaEasy[DFS, Divide and Conquer, Tree]Java120
N/APopulating Next Right Pointers in Each Node.javaMedium[DFS, Divide and Conquer, Tree]Java121
N/ASpace Replacement.javaMedium[String]Java122
N/AContiguous Array.javaMedium[Hash Table]Java123
N/AReverse Linked List II .javaMedium[Linked List]Java124
N/APalindrome Pairs.javaHard[Hash Table, String, Trie]Java125
N/AFind Peak Element II.javaHard[Binary Search, DFS, Divide and Conquer]Java126
N/AMinimum Height Trees.javaMedium[BFS, Graph]Java127
N/ALongest Substring Without Repeating Characters.javaMedium[Hash Table, String, Two Pointers]Java128
N/AFraction to Recurring Decimal.javaMedium[Hash Table, Math]Java129
N/AWiggle Sort.javaMedium[Array, Sort]Java130
N/AReverse Words in a String II.javaMedium[String]Java131
N/ARemove Node in Binary Search Tree.javaHard[BST]Java132
N/AReorder List.javaMedium[Linked List]Java133
N/ARedundant Connection II.javaHard[DFS, Graph, Tree, Union Find]Java134
N/A[tool] Quick Select - Median.javaEasy[Array, Lint, Quick Select, Quick Sort, Two Pointers]O(n)O(logN)Java135
N/ASwap Bits.javaEasy[Bit Manipulation]Java136
N/AFriends Of Appropriate Ages.javaMedium[Array, Math]Java137
N/ALongest Increasing Subsequence.javaMedium[Binary Search, Coordinate DP, DP, Memoization]O(n^2) dp, O(nLogN) binary searchO(n)Java138
N/APower of Two.javaEasy[Bit Manipulation, Math]Java139
N/AMin Stack.javaEasy[Design, Stack]Java140
N/ACount of Smaller Number before itself.javaHard[]Java141
N/AMajority Number III.javaMedium[Hash Table, Linked List]Java142
N/ANumber of Digit One.javaHard[Math]Java143
N/ATweaked Identical Binary Tree.javaEasy[DFS, Tree]Java144
N/ASearch Range in Binary Search Tree .javaMedium[BST, Binary Tree]Java145
N/ABest Time to Buy and Sell Stock III.javaHard[Array, DP, Sequence DP]Java146
N/ADesign Search Autocomplete System.javaHard[Design, Hash Table, MinHeap, PriorityQueue, Trie]input: O(x), where x = possible words, constructor: O(mn) m = max length, n = # of wordsO(n^2), n = # of possible words, n = # of trie levels; mainlay saving the Map<S, freq>Java147
N/ASubsets II.javaMedium[Array, BFS, Backtracking, DFS]O(2^n)Java148
N/AOne Edit Distance.javaMedium[String]Java149
N/ASegment Tree Modify.javaMedium[Binary Tree, DFS, Divide and Conquer, Lint, Segment Tree]Java150
N/ADistinct Subsequences.javaHard[DP, String]Java151
N/AInsert Node in a Binary Search Tree .javaEasy[BST]Java152
N/AContainer With Most Water.javaMedium[Array, Two Pointers]Java153
N/AWord Ladder.javaMedium[BFS]Java154
N/ASingle Number II.javaMedium[Bit Manipulation]Java155
N/AHeaters.javaEasy[]Java156
N/AKth Smallest Element in a BST.javaMedium[BST, DFS, Stack, Tree]Java157
N/ARobot Room Cleaner.javaHard[Backtracking, DFS]Java158
N/ACoins in a Line II.javaMedium[Array, DP, Game Theory, Memoization, MiniMax]Java159
N/APartition List.javaMedium[Linked List, Two Pointers]Java160
N/AClassical Binary Search.javaEasy[Binary Search]Java161
N/AWood Cut.javaMedium[Binary Search]Java162
N/AConnecting Graph III.javaMedium[Union Find]Java163
N/AInvert Binary Tree.javaEasy[BFS, DFS, Tree]Java164
N/ARemove Duplicates from Unsorted List.javaMedium[Linked List]Java165
N/AMaximum Size Subarray Sum Equals k.javaMedium[Hash Table, PreSum, Subarray]O(n)O(n)Java166
N/AThe Smallest Difference.javaMedium[Array, Sort, Two Pointers]Java167
N/AUnique Binary Search Tree II.javaMedium[BST, DP, Divide and Conquer, Tree]Java168
N/AEncode and Decode Strings.javaMedium[String]Java169
N/ARemove Duplicates from Sorted List II.javaMedium[Linked List]Java170
N/ASubarray Sum II.javaHard[Array, Binary Search, Two Pointers]Java171
N/AMatrix Zigzag Traversal.javaEasy[]Java172
N/AOnes and Zeroes.javaHard[DP]Java173
N/ANumber of Connected Components in an Undirected Graph.javaMedium[BFS, DFS, Graph, Union Find]Java174
N/ASubmatrix Sum.javaMedium[Array, Hash Table, PreSum]Java175
N/AZigzag Iterator.javaMedium[BST]Java176
N/AFind the Connected Component in the Undirected Graph.javaMedium[BFS, DFS]Java177
N/AImplement Stack.javaEasy[Stack]Java178
N/ANumber of Airplane in the sky.javaMedium[Array, Interval, PriorityQueue, Sort, Sweep Line]Java179
N/ASurrounded Regions.javaMedium[BFS, DFS, Matrix DFS, Union Find]Java180
N/AWildcard Matching.javaHard[Backtracking, DP, Double Sequence DP, Greedy, Sequence DP, String]Java181
N/AExpression Add Operators.javaHard[Backtracking, DFS, Divide and Conquer, String]O(4^n)O(4^n)Java182
N/ACracking the Safe.javaHard[DFS, Greedy, Math]Java183
N/AUnique Word Abbreviation.javaMedium[Design, Hash Table]Java184
N/ABest Time to Buy and Sell Stock IV.javaHard[DP, Sequence DP]Java185
N/AFind Minimum in Rotated Sorted Array II.javaHard[Array, Binary Search]Java186
N/ALongest Valid Parentheses.javaHard[Coordinate DP, Stack, String]Java187
N/AUgly Number II.javaMedium[DP, Enumeration, Heap, Math, PriorityQueue]O(n)O(n)Java188
N/AAdd Two Numbers II.javaMedium[Linked List]Java189
N/AMaximum Average Subarray II.javaReview[Array, Binary Search, PreSum]Java190
N/AExpression Tree Build.javaHard[Binary Tree, Expression Tree, Minimum Binary Tree, Stack]Java191
N/AMerge Two Binary Trees.javaEasy[DFS, Tree]Java192
N/ACopy Books.javaHard[Binary Search, DP, Partition DP]Java193
N/APower of Three.javaEasy[Math]Java194
N/ASort Colors II.javaMedium[Partition, Quick Sort, Sort, Two Pointers]Java195
N/AMaximum Subarray III.javaReview[]Java196
N/APath Sum II.javaEasy[Backtracking, DFS, Tree]Java197
N/ASegment Tree Query II.javaMedium[Binary Tree, DFS, Divide and Conquer, Lint, Segment Tree]Java198
N/AShortest Distance from All Buildings.javaHard[BFS]Java199
N/ABrick Wall.javaMedium[Hash Table]O(mn)O(X), X = max wall widthJava200
N/ALongest Increasing Path in a Matrix.javaHard[Coordinate DP, DFS, DP, Memoization, Topological Sort]Java201
N/AInterleaving String.javaHard[DP, String]Java202
N/AShuffle an Array.javaMedium[Permutation]Java203
N/ARecover Binary Search Tree.javaHard[BST, DFS, Tree]Java204
N/AMy Calendar I.javaMedium[Array, TreeMap]Java205
N/AEvaluate Reverse Polish Notation.javaMedium[Stack]O(n)O(n)Java206
N/ACounting Bits.javaMedium[Bit Manipulation, Bitwise DP, DP]Java207
N/ASort Letters by Case.javaMedium[Partition, Sort, String, Two Pointers]Java208
N/ATwo Strings Are Anagrams.javaEasy[]Java209
N/ATwo Sum II - Input array is sorted.javaMedium[Array, Binary Search, Two Pointers]Java210
N/A[HackerRank]. Change to Anagram.javaEasy[String]Java211
N/AImplement Queue using Stacks.javaEasy[Design, Stack]Java212
N/ABasic Calculator.javaHard[Binary Tree, Expression Tree, Math, Minimum Binary Tree, Stack]Java213
N/AWord Squares.javaHard[Backtracking, Trie]Java214
N/AInsertion Sort List.javaMedium[Linked List, Sort]Java215
N/AInterval Sum.javaMedium[Binary Search, Lint, Segment Tree]Java216
N/AStrobogrammatic Number II.javaMedium[DFS, Enumeration, Math, Sequence DFS]Java217
N/AThe Maze II.javaMedium[BFS, DFS, PriorityQueue]Java218
N/Ak Sum.javaHard[DP]Java219
N/ACoins in a Line III.javaHard[Array, DP, Game Theory, Interval DP, Memoization]Java220
N/AConvert Sorted List to Binary Search Tree.javaMedium[BST, DFS, Divide and Conquer, Linked List]Java221
N/AGuess Number Higher or Lower.javaEasy[Binary Search]Java222
N/ATrapping Rain Water II.javaHard[BFS, Heap, MinHeap, PriorityQueue]Java223
N/ABricks Falling When Hit.javaHard[Union Find]Java224
N/ASubarray Sum Closest.javaMedium[PreSum, PriorityQueue, Sort, Subarray]O(nlogn)O(n)Java225
N/ABurst Balloons.javaHard[DP, Divide and Conquer, Interval DP, Memoization]Java226
N/APartition Array by Odd and Even.javaEasy[Array, Two Pointers]Java227
N/ABest Time to Buy and Sell Stock with Cooldown.javaMedium[DP]Java228
N/APalindrome Partitioning II.javaHard[DP, Partition DP]Java229
N/AConvert Binary Search Tree to Sorted Doubly Linked List (extra space).javaMedium[Linked List, Stack, Tree]O(n)O(n)Java230
N/AKth Largest Element in an Array.javaMedium[Divide and Conquer, Heap, MinHeap, PriorityQueue, Quick Sort]Java231
N/ASliding Puzzle.javaHard[BFS, Graph]Java232
N/AInterval Sum II.javaHard[Binary Search, Lint, Segment Tree]Java233
N/AAdd Digits.javaEasy[Math]Java234
N/AHashWithCustomizedClass(LinkedList).javaMedium[Hash Table]Java235
N/AMaximum Vacation Days.javaHard[DP]Java236
N/ASmallest Subtree with all the Deepest Nodes.javaMedium[DFS, Divide and Conquer, Tree]O(n)O(n)Java237
N/AKth Smallest Element in a Sorted Matrix.javaMedium[Binary Search, Heap]O(n + klogn)O(n)Java238
N/ACombination Sum III.javaMedium[Array, Backtracking, Combination, DFS]Java239
N/ALast Position of Target.javaEasy[Binary Search]Java240
N/APath Sum III.javaEasy[DFS, Double Recursive, Tree]Java241
N/AConvert Expression to Reverse Polish Notation.javaHard[Binary Tree, DFS, Expression Tree, Stack]Java242
N/AComplete Binary Tree.javaEasy[BFS, Tree]Java243
N/ABest Time to Buy and Sell Stock with Transaction Fee.javaMedium[Array, DP, Greedy, Sequence DP, Status DP]O(n)O(n), O(1) rolling arrayJava244
N/APow(x, n).javaMedium[Binary Search, Math]Java245
N/AMaximum Subarray II.javaMedium[Array, DP, Greedy, PreSum, Sequence DP, Subarray]Java246
N/ASort Colors.javaMedium[Array, Partition, Quick Sort, Sort, Two Pointers]Java247
N/AWord Ladder II.javaHard[Array, BFS, Backtracking, DFS, Hash Table, String]Java248
N/ASum of Two Integers.javaEasy[Bit Manipulation]Java249
N/APredict the Winner.javaMedium[DP, MiniMax]Java250
N/AConnecting Graph II.javaMedium[Union Find]Java251
N/ASearch Insert Position.javaEasy[]Java252
N/ALongest Univalue Path.javaEasy[]Java253
N/AContains Duplicate III.javaMedium[BST]Java254
N/ASpiral Matrix.javaMedium[Array, Enumeration]Java255
N/ANext Closest Time.javaMedium[Basic Implementation, Enumeration, String]Java256
N/AGroup Shifted Strings.javaMedium[Hash Table, String]Java257
N/AThe Maze III.javaHard[BFS, DFS, PriorityQueue]Java258
N/ACoins in a Line.javaMedium[DP, Game Theory, Greedy]Java259
N/ABinary Tree Longest Consecutive Sequence.javaMedium[DFS, Divide and Conquer, Tree]Java260
N/AThe Spiral Matrix II.javaMedium[Array]Java261
N/ATrim a Binary Search Tree.javaEasy[BST, Tree]Java262
N/ANumber Of Corner Rectangles.javaMedium[DP, Math]Java263
N/AQueue Reconstruction by Height.javaMedium[Greedy]Java264
N/AMinimum Swaps To Make Sequences Increasing.javaMedium[Coordinate DP, DP, Status DP]Java265
N/AInterleaving Positive and Negative Numbers.javaMedium[Two Pointers]Java266
N/APath Sum IV.javaMedium[DFS, Hash Table, Tree]Java267
N/AExcel Sheet Column Number.javaEasy[Math]Java268
N/ATarget Sum.javaMedium[DFS, DP]Java269
N/APartition Array.javaMedium[Array, Quick Sort, Sort, Two Pointers]Java270
N/ABus Routes.javaHard[BFS]Java271
N/AMax Sum of Rectangle No Larger Than K.javaHard[Array, BST, Binary Search, DP, Queue, TreeSet]Java272
N/AString Permutation.javaEasy[]Java273
N/AMaximum XOR of Two Numbers in an Array.javaMedium[Bit Manipulation, Trie]Java274
N/ASearch for a Range.javaMedium[Array, Binary Search]Java275
N/APalindrome Permutation II.javaMedium[Backtracking, Permutation]Java276
N/APopulating Next Right Pointers in Each Node II.javaMedium[DFS, Tree]O(n)O(1)Java277
N/ANim Game.javaEasy[Brainteaser, DP, Game Theory]Java278
N/ASearch a 2D Matrix.javaMedium[Array, Binary Search]Java279
N/ALargest Rectangle in Histogram.javaHard[Array, Monotonous Stack, Stack]Java280
[lint][lint]. Merge k Sorted Arrays.javaMedium[Heap, MinHeap, PriorityQueue]O(nlogk)O(k)Java281
[lint][lint]. Segment Tree Build II.javaMedium[Binary Tree, Divide and Conquer, Lint, Segment Tree]Java282
[lint][lint]. Nth to Last Node in List.javaEasy[Linked List, Lint]Java283
[lint][lint]. Product of Array Exclude Itself.javaMedium[Array, Lint]Java284
[lint][lint]. Compare Strings.javaEasy[Lint, String]Java285
[lint][lint]. Segment Tree Query.javaMedium[Binary Tree, DFS, Divide and Conquer, Lint, Segment Tree]Java286
[lint][lint]. HashHeap.javaHard[HashHeap, Heap, Lint]Java287
[lint][lint]. Longest Words.javaEasy[Hash Table, Lint, String]Java288
[lint][lint]. Anagrams.javaMedium[Array, Hash Table, Lint]O(n)O(n)Java289
[lint][lint]. 3 Sum Closest.javaMedium[Array, Lint, Two Pointers]Java290
[lint][lint]. Unique Characters.javaEasy[Array, Lint, String]Java291
[lint][lint]. Lowest Common Ancestor II.javaEasy[Hash Table, Lint, Tree]Java292
[lint][lint]. Heapify.javaMedium[HashHeap, Heap, Lint, MinHeap]Java293
[lint][lint]. Subarray Sum.javaEasy[Array, Hash Table, Lint, PreSum, Subarray]O(n)O(n)Java294
[lint][lint]. Recover Rotated Sorted Array.javaEasy[Array, Lint]Java295
[lint][lint]. 2 Sum II.javaMedium[Array, Binary Search, Lint, Two Pointers]Java296
[lint][lint]. Segment Tree Build.javaMedium[Binary Tree, Divide and Conquer, Lint, Segment Tree]Java297
[tool][tool]. MergeSort.javaMedium[Lint, Merge Sort, Sort]O(mlogn)O(n)Java298
[tool][tool]. Hash Function.javaEasy[Hash Table, Lint]O(1) getO(n) store mapJava299
[tool][tool]. UnionFind.javaMedium[Lint, Union Find]O(n), with Path Compression O(mN), with Union by Rank O(logN)O(n)Java300
[tool][tool]. Topological Sorting.javaMedium[BFS, DFS, Lint, Topological Sort]O(V + E)O(V + E)Java301
3636. Valid Sudoku.javaEasy[Enumeration, Hash Table](mn)(mn)Java302
359359. Logger Rate Limiter.javaEasy[Design, Hash Table]O(1)O(n)Java303
198198. House Robber.javaEasy[DP, Sequence DP, Status DP]O(n)O(n) or rolling array O(1)Java304
2121. Merge Two Sorted Lists.javaEasy[Linked List]O(n)O(1)Java305
102102. Binary Tree Level Order Traversal.javaMedium[BFS, DFS, Tree]O(n)O(n)Java306
788788. Rotated Digits.javaEasy[Basic Implementation, String]O(n)O(n)Java307
4242. Trapping Rain Water.javaHard[Array, Stack, Two Pointers]O(n)O(1)Java308
347347. Top K Frequent Elements.javaMedium[Hash Table, Heap, MaxHeap, MinHeap, PriorityQueue]O(n)O(n)Java309
269269. Alien Dictionary.javaHard[BFS, Backtracking, DFS, Graph, Topological Sort]O(n), n = # of graph edgesO(n)Java310
237237. Delete Node in a Linked List.javaEasy[Linked List]Java311
142142. Linked List Cycle II.javaMedium[Cycle Detection, Linked List, Slow Fast Pointer, Two Pointers]O(n)O(1)Java312
448448. Find All Numbers Disappeared in an Array.javaEasy[Array, Bucket Sort]O(n)O(1)Java313
360360. Sort Transformed Array.javaMedium[Math, Two Pointers]O(n)O(n) store resultJava314
2222. Generate Parentheses.javaMedium[Backtracking, DFS, Sequence DFS, String]O(2^n)O(2^n)Java315
849849. Maximize Distance to Closest Person.javaEasy[Array, Basic Implementation, Two Pointers]O(n)O(1)Java316
408408. Valid Word Abbreviation.javaEasy[Basic Implementation, String]Java317
415415. Add Strings.javaEasy[Basic Implementation, Math, String]O(n)O(n)Java318
8383. Remove Duplicates from Sorted List.javaEasy[Linked List]Java319
11081108. Defanging an IP Address.javaEasy[Basic Implementation, String]Java320
10211021. Remove Outermost Parentheses.javaEasy[Stack]Java321
236236. Lowest Common Ancestor of a Binary Tree.javaMedium[DFS, Tree]O(n)O(n)Java322
766766. Toeplitz Matrix.javaEasy[Array]O(mn)O(1)Java323
953953. Verifying an Alien Dictionary.javaEasy[Hash Table]O(nm)O(1)Java324
10531053. Previous Permutation With One Swap.javaMedium[Array, Greedy, Permutation]O(n)O(1)Java325
12131213. Intersection of Three Sorted Arrays.javaEasy[Hash Table, Two Pointers]O(m + n + h) two pointers approachO(1)Java326
383383. Ransom Note.javaEasy[Basic Implementation, String]Java327
5656. Merge Intervals.javaMedium[Array, PriorityQueue, Sort, Sweep Line]O(nlogn)O(n)Java328
252252. Meeting Rooms.javaEasy[PriorityQueue, Sort, Sweep Line]O(nlogn)O(1)Java329
665665. Non-decreasing Array.javaEasy[Array]O(n)O(1)Java330
843843. Guess the Word.javaHard[MiniMax]TODOTODOJava331
986986. Interval List Intersections.javaMedium[Two Pointers]O(n)O(1)Java332
7676. Minimum Window Substring.javaHard[Hash Table, Sliding Window, String, Two Pointers]O(n)O(1)Java333
293293. Flip Game.javaEasy[String]Java334
244244. Shortest Word Distance II.javaMedium[Array, Design, Hash Table, Two Pointers]O(n) to build map, O(a + b) to queryO(n)Java335
686686. Repeated String Match.javaEasy[Basic Implementation, Edge Case, String]Java336
8080.Remove Duplicates from Sorted Array II.javaMedium[Array, Two Pointers]Java337
301301. Remove Invalid Parentheses.javaHard[BFS, DFS, DP]Java338
111111. Minimum Depth of Binary Tree.javaEasy[BFS, DFS, Tree]O(n)O(n)Java339
12161216. Valid Palindrome III.javaHard[DFS, DP, Memoization, String]O(n^2)O(n^2)Java340
77. Reverse Integer.javaEasy[Math]O(n)O(1)Java341
55. Longest Palindromic Substring.javaMedium[DP, String]O(n^2)O(n^2)Java342
303303. Range Sum Query - Immutable.javaEasy[DP, PreSum]O(1) query, O(n) setupO(n)Java343
674674. Longest Continuous Increasing Subsequence.javaEasy[Array, Coordinate DP, DP, Sliding Window]O(n)O(1)Java344
10071007. Minimum Domino Rotations For Equal Row.javaMedium[Array, Greedy]O(n)O(1)Java345
485485. Max Consecutive Ones.javaEasy[Array, Basic Implementation]O(n)O(1)Java346
896896. Monotonic Array.javaEasy[Array]Java347
207207. Course Schedule.javaMedium[BFS, Backtracking, DFS, Graph, Topological Sort]O(n)O(n)Java348
327327. Count of Range Sum.javaHard[BIT, Divide and Conquer, Merge Sort, PreSum, Segment Tree]O(nlogn)O(n)Java349
987987. Vertical Order Traversal of a Binary Tree.javaMedium[BFS, Binary Tree, DFS, Hash Table, Tree]Java350
2626.Remove Duplicates from Sorted Array.javaEasy[Array, Two Pointers]Java351
429429. N-ary Tree Level Order Traversal.javaMedium[BFS, Tree]O(n)O(n)Java352
275275. H-Index II.javaMedium[Binary Search]O(logN)O(1) extraJava353
204204. Count Primes.javaEasy[Hash Table, Math]Java354
5858. Length of Last Word.javaEasy[String]Java355
496496. Next Greater Element I.javaEasy[Hash Table, Stack]O(n)O(n)Java356
4141. First Missing Positive.javaHard[Analysis, Array, Edge Case]O(n)O(1)Java357
694694. Number of Distinct Islands.javaMedium[DFS, Hash Table]O(n)O(n)Java358
717717. 1-bit and 2-bit Characters.javaEasy[Array]Java359
5353. Maximum Subarray.javaEasy[Array, DFS, DP, Divide and Conquer, PreSum, Sequence DP, Subarray]O(n)O(n), O(1) rolling arrayJava360
152152. Maximum Product Subarray.javaMedium[Array, DP, PreProduct, Subarray]O(n)O(1)Java361
199199. Binary Tree Right Side View.javaMedium[BFS, DFS, Tree]O(n)O(n)Java362
259259. 3Sum Smaller.javaMedium[Array, Sort, Two Pointers]Java363
977977. Squares of a Sorted Array.javaEasy[Array, Two Pointers]O(n)O(n)Java364
824824. Goat Latin.javaEasy[Basic Implementation, String]O(n)O(1)Java365
308308. Range Sum Query 2D - Mutable.javaHard[Binary Indexed Tree, Segment Tree]build(n), update(logn), rangeRuery(logn + k)O(n)Java366
12031203. Sort Items by Groups Respecting Dependencies.javaHard[BFS, DFS, Graph, Topological Sort]O(V + E) to traverse the graph, #nodes + #edgesO(V + E)Java367
11531153. String Transforms Into Another String.javaHard[Graph]O(n)O(n)Java368
10081008. Construct Binary Search Tree from Preorder Traversal.javaMedium[DFS, Tree]O(n)O(n)Java369
151151. Reverse Words in a String.javaMedium[String]O(n)Java370
855855. Exam Room.javaMedium[PriorityQueue, Sort, TreeMap, TreeSet]O(logn)O(n)Java371
3131. Next Permutation.javaMedium[Array, Permutation]O(n)O(1)Java372
518518. Coin Change 2.javaMedium[Backpack DP, DP]O(n)O(n)Java373
405405. Convert a Number to Hexadecimal.javaEasy[Bit Manipulation]Java374
850850. Rectangle Area II.javaHard[Segment Tree, Sweep Line]O(n^2)O(n)Java375
515515. Find Largest Value in Each Tree Row.javaMedium[BFS, DFS, Tree]O(n)O(n)Java376
253253. Meeting Rooms II.javaMedium[Greedy, Heap, PriorityQueue, Sort, Sweep Line]O(nlogn)O(n)Java377
11611161. Maximum Level Sum of a Binary Tree.javaMedium[BFS, DFS, Graph]O(n) visit all nodesO(n)Java378
509509. Fibonacci Number.javaEasy[DP, Math, Memoization]Java379
221221. Maximal Square.javaMedium[Coordinate DP, DP]O(mn)O(mn)Java380
131131. Palindrome Partitioning.javaMedium[Backtracking, DFS]O(2^n)O(n^2)Java381
136136. Single Number.javaEasy[Bit Manipulation, Hash Table]Java382
222222. Count Complete Tree Nodes.javaMedium[Binary Search, DFS, Tree]O(n)O(h)Java383
257257. Binary Tree Paths.javaEasy[Backtracking, Binary Tree, DFS]O(n)O(nlogn)Java384
543543. Diameter of Binary Tree.javaEasy[Tree]O(n) when non-balancedO(n) when non-balancedJava385
398398. Random Pick Index.javaMedium[Reservior Sampling]O(n)O(n) for input int[], O(1) extra space usedJava386
238238. Product of Array Except Self.javaMedium[Array, PreProduct]O(n)O(1)Java387
10601060. Missing Element in Sorted Array.javaMedium[Binary Search]O(logn)O(1)Java388
10481048. Longest String Chain.javaMedium[Bucket Sort, DP, Hash Table, Sort]O(n)O(n)Java389
6767. Add Binary.javaEasy[Math, String, Two Pointers]Java390
299299. Bulls and Cows.javaMedium[Hash Table]O(n)O(n)Java391
557557. Reverse Words in a String III.javaEasy[String]Java392
203203. Remove Linked List Elements.javaEasy[Linked List]Java393
12191219. Path with Maximum Gold.javaMedium[Backtracking, DFS]O(n^2)O(n) recursive depthJava394
266266. Palindrome Permutation.javaEasy[Hash Table]O(n)O(n)Java395
6262. Unique Path.javaMedium[Array, Coordinate DP, DP]O(mn)O(mn), rolling array O(n)Java396
10911091. Shortest Path in Binary Matrix.javaMedium[BFS]O(n^2)Java397
11101110. Delete Nodes And Return Forest.javaMedium[DFS, Divide and Conquer, Tree]O(n)O(logn)Java398
12491249. Minimum Remove to Make Valid Parentheses.javaMedium[Stack, String]O(n)O(n)Java399
1515. 3Sum.javaMedium[Array, Sort, Two Pointers]O(n^2)Java400
311311. Sparse Matrix Multiplication.javaMedium[Hash Table]O(mnk), where m = A.row, n = B.col, k = A.col = B.rowO(1) extraJava401
339339. Nested List Weight Sum.javaEasy[BFS, DFS, NestedInteger]O(n)O(h), h = levelsJava402
322322. Coin Change.javaMedium[Backpack DP, DFS, DP, Memoization]O(n * S)O(S)Java403
5555. Jump Game.javaMedium[Array, DP, Greedy]O(n)O(1)Java404
173173. Binary Search Tree Iterator.javaMedium[BST, Design, Stack, Tree]O(1) averageO(h)Java405
140140. Word Break II.javaHard[Backtracking, DFS, DP, Hash Table, Memoization]O(n!)O(n!)Java406
5151. N-Queens.javaHard[Backtracking]O(n!)O(n^2)Java407
875875. Koko Eating Bananas.javaMedium[Binary Search]O(n*logM)O(1)Java408
189189. Rotate Array.javaEasy[Array, Rotation]Java409
1919. Remove Nth Node From End of List.javaMedium[Linked List, Two Pointers]O(n)O(1)Java410
134134. Gas Station.javaMedium[Greedy]O(n)O(1)Java411
119119. Pascal's Triangle II.javaEasy[Array, Basic Implementation]O(k^2), pascal triangle sizeO(k^2)Java412
11971197. Minimum Knight Moves.javaMedium[BFS]O(8^n)O(8^n)Java413
493493. Reverse Pairs.javaMedium[BST, Binary Indexed Tree, Divide and Conquer, Merge Sort, Segment Tree]Java414
13061306. Jump Game III.javaMedium[BFS, Graph]O(n)O(n)Java415
305305. Number of Islands II.javaHard[Union Find]O(k * log(mn))O(mn)Java416
206206. Reverse Linked List.javaEasy[Linked List]Java417
277277. Find the Celebrity.javaMedium[Adjacency Matrix, Array, Graph, Greedy, Pruning]O(n)O(1)Java418
741741. Cherry Pickup.javaHard[DFS, DP]O(n^3)O(n^3), memo sizeJava419
168168. Excel Sheet Column Title.javaEasy[Math]O(n)O(1)Java420
104104. Maximum Depth of Binary Tree.javaEasy[DFS, Tree]Java421
349349. Intersection of Two Arrays.javaEasy[Binary Search, Hash Table, Sort, Two Pointers]O(m + n)O(m + n)Java422
443443. String Compression.javaEasy[Basic Implementation, String]Java423
297297. Serialize and Deserialize Binary Tree.javaHard[BFS, DFS, Deque, Design, Divide and Conquer, Tree]O(n)O(n)Java424
4646. Permutations.javaMedium[BFS, Backtracking, DFS, Permutation]O(n!)O(n!)Java425
844844. Backspace String Compare.javaEasy[Stack, Two Pointers]O(n)O(1)Java426
99. Palindrome Number.javaEasy[Math]Java427
10941094. Car Pooling.javaMedium[Greedy, Heap, PriorityQueue, Sort]O(n)O(1) only use bucket size 1000Java428
245245. Shortest Word Distance III.javaMedium[Array, Design, Hash Table, Two Pointers]O(n)O(1)Java429
11171117. Building H2O.javaMedium[Lock, Semaphore, Thread]Java430
973973. K Closest Points to Origin.javaMedium[Divide and Conquer, Heap, Sort]O(klogk)O(k)Java431
771771. Jewels and Stones.javaEasy[Hash Table]O(n)O(n)Java432
200200. Number of Islands.javaMedium[BFS, DFS, Matrix DFS, Union Find]O(n)O(n)Java433
141141. Linked List Cycle.javaEasy[Cycle Detection, Linked List, Slow Fast Pointer, Two Pointers]O(n)O(1)Java434
567567. Permutation in String.javaMedium[Sliding Window, Two Pointers]O(m + n)O(1)Java435
727727. Minimum Window Subsequence.javaHard[DP, Hash Table, Sliding Window, String, Two Pointers]O(n^2)O(1)Java436
158158. Read N Characters Given Read4 II - Call multiple times.javaHard[Enumeration, String]O(n)O(n)Java437
369369. Plus One Linked List.javaMedium[Linked List]O(n)O(1)Java438
211211. Add and Search Word - Data structure design.javaMedium[Backtracking, Design, Trie]O(n) to search and to add word< O(mn), depends on the input. m = # of wordsJava439
4343. Multiply Strings.javaMedium[Math, String]O(mn)O(mn)Java440
621621. Task Scheduler.javaMedium[Array, Enumeration, Greedy, PriorityQueue, Queue]O(n)O(1)Java441
680680. Valid Palindrome II.javaEasy[String]Java442
295295. Find Median from Data Stream.javaHard[Design, Heap, MaxHeap, MinHeap]O(1) get, O(logn) addNumO(n)Java443
7070. Climbing Stairs.javaEasy[DP, Memoization, Sequence DP]Java444
747747. Largest Number At Least Twice of Others.javaEasy[Array]Java445
315315. Count of Smaller Numbers After Self.javaHard[BST, Binary Indexed Tree, Binary Search, Divide and Conquer, Segment Tree]O(nlogn)O(n)Java446
239239. Sliding Window Maximum.javaHard[Deque, Heap, Sliding Window]O(n)O(n)Java447
4747. Permutations II.javaMedium[Backtracking, DFS]Java448
332332. Reconstruct Itinerary.javaMedium[Backtracking, DFS, Graph]O(n^n)O(m)Java449
8888. Search in Rotated Sorted Array II.javaMedium[Array, Binary Search]O(logn), worst O(n)O(1)Java450
561561. Array Partition I.javaEasy[Array]O(nlogn)O(1)Java451
387387. First Unique Character in a String.javaEasy[Hash Table, String]O(n)O(256) = O(1)Java452
345345. Reverse Vowels of a String.javaEasy[String, Two Pointers]Java453
3939. Combination Sum.javaMedium[Array, Backtracking, Combination, DFS]O(k * 2^n), k = avg rst lengthO(k) stack depth, if not counting result sizeJava454
1010. Regular Expression Matching.javaHard[Backtracking, DP, Double Sequence DP, Sequence DP, String]Java455
367367. Valid Perfect Square.javaEasy[Binary Search, Math]O(logN)O(1)Java456
270270. Closest Binary Search Tree Value.javaEasy[BST, Binary Search, Tree]O(logn)O(1)Java457
2828. Implement strStr().javaEasy[String, Two Pointers]Java458
11061106. Parsing A Boolean Expression.javaHard[DFS, Stack, String]Java459
144144. Binary Tree Preorder Traversal.javaMedium[BFS, DFS, Stack, Tree]O(n)O(n)Java460
852852. Peak Index in a Mountain Array.javaEasy[Binary Search]O(logn)O(1)Java461
146146. LRU Cache.javaMedium[Design, Doubly Linked List, Hash Table, Linked List]O(1)O(1)Java462
110110. Balanced Binary Tree.javaEasy[DFS, Tree]Java463
10401040. Moving Stones Until Consecutive II.javaMedium[Array, Sliding Window]O(nlogn)O(n)Java464
246246. Strobogrammatic Number.javaEasy[Enumeration, Hash Table, Math, Two Pointers]O(n)O(1)Java465
100100. Same Tree.javaEasy[BFS, DFS, Tree]O(n)O(logn)Java466
307307. Range Sum Query - Mutable.javaMedium[Binary Indexed Tree, Segment Tree]build O(n), query (logn +k), update O(logn)O(n)Java467
8888. Merge Sorted Array.javaEasy[Array, Two Pointers]O(n)O(1)Java468
319319. Bulb Switcher.javaMedium[Brainteaser, Math]O(1)O(1)Java469
112112. Path Sum.javaEasy[DFS, Tree]Java470
463463. Island Perimeter.javaEasy[Hash Table]O(n)Java471
170170. Two Sum III - Data structure design.javaEasy[Design, Hash Table, Memoization]O(n)O(n)Java472
122122. Best Time to Buy and Sell Stock II.javaEasy[Array, DP, Greedy, Sequence DP, Status DP]O(n)O(1) greedy, O(n) dpJava473
715715. Range Module.javaHard[Segment Tree, TreeSet]query O(logn), update O(n)O(n)Java474
1212. Integer to Roman.javaMedium[Basic Implementation, Math, String]O(n)O(n)Java475
1414. Longest Common Prefix.javaEasy[String]Java476
243243. Shortest Word Distance.javaEasy[Array, Two Pointers]O(n)O(1)Java477
414414. Third Maximum Number.javaEasy[Array, PriorityQueue]Java478
12671267. Count Servers that Communicate.javaMedium[Array, Graph]O(mn)O(m + n)Java479
2020. Valid Parentheses.javaEasy[Stack, String]O(n)O(n)Java480
893893. Groups of Special-Equivalent Strings.javaEasy[Basic Implementation, String]Java481
427427. Construct Quad Tree.javaMedium[Tree]O(n^2)O(n^2)Java482
981981. Time Based Key-Value Store.javaMedium[Binary Search, Hash Table, TreeMap]set O(1), get(logn)O(n)Java483
169169. Majority Element.javaEasy[Array, Bit Manipulation, Divide and Conquer, Moore Voting, Sort]O(n)O(1)Java484
234234. Palindrome Linked List.javaEasy[Linked List, Two Pointers]O(n)O(1)Java485
202202. Happy Number.javaEasy[Hash Table, Math]O(m), m iterationsO(m), m number in setJava486
6969. Sqrt(x).javaEasy[Binary Search, Math]Java487
876876. Middle of Linked List.javaEasy[Linked List]Java488
10261026. Maximum Difference Between Node and Ancestor.javaMedium[DFS, Tree]O(n)O(logn)Java489
7878. Subsets.javaMedium[Array, BFS, Backtracking, Bit Manipulation, DFS]O(2^n)O(2^n)Java490
432432. All One Data Structure.javaHard[Design, Doubly Linked List]O(1)O(n)Java491
380380. Insert Delete GetRandom O(1).javaMedium[Array, Design, Hash Table]O(1) avgO(n)Java492
560560. Subarray Sum Equals K.javaMedium[Array, Hash Table, PreSum, Subarray]O(n)O(n)Java493
219219. Contains Duplicate II.javaEasy[Array, Hash Table]O(n)O(n)Java494
9191. Decode Ways.javaMedium[DP, Partition DP, String]O(n)O(n)Java495
205205. Isomorphic Strings.javaEasy[Hash Table]O(n)O(n)Java496
639639. Decode Ways II.javaHard[DP, Enumeration, Partition DP]O(n)O(n)Java497
346346. Moving Average from Data Stream.javaEasy[Design, Queue, Sliding Window]O(1) for next()O(size) for fixed storageJava498
145145. Binary Tree Postorder Traversal.javaMedium[Stack, Tree, Two Stacks]O(n)O(n)Java499
938938. Range Sum of BST.javaEasy[BST, Recursion, Tree]Java500
210210. Course Schedule II.javaMedium[BFS, DFS, Graph, Topological Sort]O(n)O(n)Java501
6868. Text Justification.javaHard[Enumeration, String]O(n) go over wordsO(maxLength) buffer listJava502
314314. Binary Tree Vertical Order Traversal.javaMedium[BFS, DFS, Hash Table, Tree]O(n)O(n)Java503
287287. Find the Duplicate Number.javaMedium[Array, Binary Search, Binary Search on Value, Cycle Detection, Slow Fast Pointer, Two Pointers]O(n)O(1)Java504
242242. Valid Anagram.javaEasy[Hash Table, Sort]O(n)O(1), unique charsJava505
340340. Longest Substring with At Most K Distinct Characters.javaHard[Hash Table, LinkedHashMap, Sliding Window, String, Two Pointers]O(n)O(k)Java506
217217. Contains Duplicate.javaEasy[Array, Hash Table]O(n)O(1)Java507
103103. Binary Tree Zigzag Level Order Traversal.javaMedium[BFS, Stack, Tree]O(n)O(n)Java508
10571057. Campus Bikes.javaMedium[Bucket Sort, Greedy, PriorityQueue, Sort]O(mn)O(mn)Java509
261261. Graph Valid Tree.javaMedium[BFS, DFS, Graph, Union Find]Java510
6464. Minimum Path Sum.javaMedium[Array, Coordinate DP, DP]O(mn)O(n) rolling arrayJava511
796796. Rotate String.javaEasy[String]Java512
229229. Majority Element II.javaMedium[Array, Moore Voting]O(n)(1)Java513
10411041. Robot Bounded In Circle.javaEasy[String]Java514
22. Add Two Numbers.javaMedium[Linked List, Math]O(max(m,n))O(max(m,n))Java515
157157. Read N Characters Given Read4.javaEasy[Enumeration, String]Java516
114114. Flatten Binary Tree to Linked List.javaMedium[Binary Tree, DFS]O(n)O(n), stacksJava517
121121. Best Time to Buy and Sell Stock.javaEasy[Array, DP, Sequence DP]Java518
10041004. Max Consecutive Ones III.javaMedium[Sliding Window, Two Pointers]O(n)O(1)Java519
11461146. Snapshot Array.javaMedium[Array, Hash Table, TreeMap]O(1) set, O(logn) get, O(x) snap, x = # of changesO(n * m), n = array size, m = # of snapsJava520
273273. Integer to English Words.javaHard[Enumeration, Math, String]O(n)O(1)Java521
304304. Range Sum Query 2D - Immutable.javaMedium[DP, PreSum]O(mn) build, O(1) queryO(mn)Java522
605605. Can Place Flowers.javaEasy[Array, Greedy]O(n)O(1)Java523
11. Two Sum.javaEasy[Array, Hash Table]O(n)O(n)Java524
118118. Pascal's Triangle.javaEasy[Array, Basic Implementation, List]O(n^2) based on pascal triangle sizeO(n^2)Java525
2323. Merge k Sorted Lists.javaMedium[Divide and Conquer, Heap, Linked List, Merge Sort, PriorityQueue]O(nlogk)O(logk)Java526
283283. Move Zeroes.javaEasy[Array, Two Pointers]O(n)O(1)Java527
208208. Implement Trie (Prefix Tree).javaMedium[Design, Trie]Java528
516516. Longest Palindromic Subsequence.javaMedium[DFS, DP, Interval DP, Memoization]O(n^2)O(n^2)Java529
218218. The Skyline Problem.javaHard[BIT, Divide and Conquer, HashHeap, Heap, PriorityQueue, Segment Tree, Sweep Line]O(n^2logn)O(n)Java530
430430. Flatten a Multilevel Doubly Linked List.javaMedium[DFS, Linked List]O(n)O(1)Java531
6363. Unique Paths II.javaMedium[Array, Coordinate DP, DP]O(mn)O(mn)Java532
5252. N-Queens II.javaHard[Backtracking]O(n!)O(n)Java533
10331033. Moving Stones Until Consecutive.javaEasy[Basic Implementation, Sort]O(1), only 3 elementsO(1)Java534
139139. Word Break.javaMedium[DP, Hash Table, Sequence DP]O(n^2)O(n)Java535
105105. Construct Binary Tree from Preorder and Inorder Traversal.javaMedium[Array, DFS, Divide and Conquer, Hash Table, Tree]O(n)O(n)Java536
125125. Valid Palindrome.javaEasy[String, Two Pointers]Java537
449449. Serialize and Deserialize BST.javaMedium[Tree]O(n)O(n)Java538
274274.H-Index.javaMedium[Bucket Sort, Hash Table, Sort]O(n)O(n)Java539
160160. Intersection of Two Linked Lists.javaEasy[Linked List]Java540
4040. Combination Sum II.javaMedium[Array, Backtracking, Combination, DFS]O(k * 2^n), k = avg rst lengthO(n) stack depth, if not counting result sizeJava541
410410. Split Array Largest Sum.javaN/A[]Java542
724724. Find Pivot Index.javaEasy[Array, PreSum]O(n)O(1)Java543
523523. Continuous Subarray Sum.javaMedium[Coordinate DP, DP, Math, PreSum, Subarray]O(n)O(k)Java544
6565. Valid Number.javaHard[Enumeration, Math, String]O(n)O(1)Java545
350350. Intersection of Two Arrays II.javaEasy[Binary Search, Hash Table, Sort, Two Pointers](n)(n)Java546
364364. Nested List Weight Sum II.javaMedium[DFS, NestedInteger]O(n), visit all nodesO(h), depthJava547
4949. Group Anagrams.javaMedium[Hash Table, String]O(nk)O(nk)Java548
720720. Longest Word in Dictionary.javaEasy[Hash Table, Trie]O(nlogn)O(n)Java549
438438. Find All Anagrams in a String.javaMedium[Hash Table, Sliding Window, Two Pointers]O(n)O(1)Java550
632632. Smallest Range Covering Elements from K Lists.javaHard[Hash Table, Sliding Window, Two Pointers]O(nlogn), n = total elementsO(n) to store sorted listJava551
138138. Copy List with Random Pointer.javaMedium[Hash Table, Linked List]O(n)O(n)Java552
159159. Longest Substring with At Most Two Distinct Characters.javaMedium[Hash Table, Sliding Window, String, Two Pointers]O(n)O(1)Java553
10431043. Partition Array for Maximum Sum.javaMedium[DFS, DP, Graph, Memoization]O(n), calc memo[n]O(n)Java554
3333. Search in Rotated Sorted Array.javaMedium[Array, Binary Search]O(logn)O(1)Java555
760760. Find Anagram Mappings.javaEasy[Hash Table]O(n)O(n)Java556
133133. Clone Graph.javaMedium[BFS, DFS, Graph]O(n)O(n)Java557
743743. Network Delay Time.javaMedium[BFS, DFS, Graph, Heap, PQ]O(nlogn)O(n)Java558
636636. Exclusive Time of Functions.javaMedium[Stack]O(n)O(n)Java559
692692. Top K Frequent Words.javaMedium[Hash Table, Heap, MaxHeap, MinHeap, PriorityQueue, Trie]O(n)O(n)Java560
11701170. Compare Strings by Frequency of the Smallest Character.javaEasy[Array, String]O(m + n)O(m + n)Java561
426426. Convert Binary Search Tree to Sorted Doubly Linked List.javaMedium[BST, DFS, Divide and Conquer, Linked List, Tree]O(n)O(1)Java562
745745. Prefix and Suffix Search.javaHard[Trie]O(N + Q)O(N)Java563
88. String to Integer (atoi).javaMedium[Math, String]O(n)O(n)Java564
361361. Bomb Enemy.javaMedium[Coordinate DP, DP]O(mn)O(n) by calculating column sumJava565
9494. Binary Tree Inorder Traversal.javaEasy[Hash Table, Stack, Tree]O(n)O(logn)Java566
402402. Remove K Digits.javaMedium[Greedy, Monotonous Stack, Stack]O(n)O(n)Java567
9898. Validate Binary Search Tree.javaMedium[BST, DFS, Divide and Conquer, Tree]O(n)O(logn)Java568
11231123. Lowest Common Ancestor of Deepest Leaves.javaMedium[BFS, DFS, Tree]O(n)O(n)Java569
921921. Minimum Add to Make Parentheses Valid.javaMedium[]O(n)O(1)Java570
399399. Evaluate Division.javaMedium[BFS, DFS, Graph, Union Find]Java571
785785. Is Graph Bipartite.javaMedium[BFS, DFS, Garph]O(n)O(n)Java572
767767. Reorganize String.javaMedium[Greedy, Hash Table, Heap, Sort, String]O(m), m = # of unique lettersO(nLogm), n = lengthJava573
7171. Simplify Path.javaMedium[Stack, String]O(n)O(n)Java574
3434. Find First and Last Position of Element in Sorted Array.javaMedium[Array, Binary Search]O(logn)O(1)Java575
278278. First Bad Version.javaEasy[Binary Search]O(logN)O(1)Java576
124124. Binary Tree Maximum Path Sum.javaHard[DFS, DP, Tree, Tree DP]O(n)O(logn)Java577
721721. Accounts Merge.javaMedium[DFS, Hash Table, Union Find]Java578
689689. Maximum Sum of 3 Non-Overlapping Subarrays.javaHard[Array, DP]O(n)O(n)Java579
101101. Symmetric Tree.javaEasy[BFS, DFS, Tree]O(n)O(n)Java580
149149. Max Points on a Line.javaHard[Array, Geometry, Hash Table, Math]O(n^2)O()Java581
698698. Partition to K Equal Sum Subsets.javaMedium[DFS, DP, Recursion]O(k^(n-k) * k!)O(n)Java582
5757. Insert Interval.javaHard[Array, PriorityQueue, Sort, Sweep Line]O(n)O(n)Java583
1313. Roman to Integer.javaEasy[Math, String]O(n)O(1)Java584
716716. Max Stack.javaMedium[Design, Doubly Linked List, Stack, TreeMap]avg O(1), [O(logN) peekMax(), TreeMap]; [O(n) popMax(), TwoStack]O(n)Java585
671671. Second Minimum Node In a Binary Tree.javaEasy[BFS, Tree]O(n)O(n) leaf nodesJava586
366366. Find Leaves of Binary Tree.javaMedium[DFS, Tree]O(n)O(h)Java587
235235. Lowest Common Ancestor of a Binary Search Tree.javaEasy[BST, DFS, Tree]O(logn)O(logn)Java588
156156. Binary Tree Upside Down.javaMedium[DFS, Tree]O(n)O(h)Java589
416416. Partition Equal Subset Sum.javaMedium[Backpack, DP]Java590
611611. Valid Triangle Number.javaMedium[Array, Two Pointers]O(n^2)O(logn), sorting spaceJava591
341341. Flatten Nested List Iterator.javaMedium[Design, NestedInteger, Stack]O(n)O(n)Java592
254254. Factor Combinations.javaMedium[BFS, Backtracking, DFS]O(x), x is the # of resultsO(y), y is all ongoing candidates in queueJava593
739739. Daily Temperatures.javaMedium[Hash Table, Monotonous Stack, Stack]O(n)O(n)Java594
373373. Find K Pairs with Smallest Sums.javaMedium[Heap, MaxHeap, MinHeap]O(klogk)O(k)Java595
256256. Paint House.javaEasy[DP, Sequence DP, Status DP]O(nm), m = # of colorsO(nm), or O(1) with rolling arrayJava596
265265. Paint House II.javaHard[DP, Sequence DP, Status DP]O(NK^2):O(K) with rolling arrayJava597
272272. Closest Binary Search Tree Value II.javaHard[Stack, Tree]O(n)O(n)Java598
7272. Edit Distance.javaHard[DP, Double Sequence DP, Sequence DP, String]O(MN)Java599
215215. Kth Largest Element in an Array.javaMedium[Divide and Conquer, Heap, MinHeap, PriorityQueue, Quick Select, Quick Sort]O(nlogk)O(k)Java600