LintCode

by awangdev

awangdev / LintCode

Java Solutions to problems on LintCode/LeetCode

4.0K Stars 1.4K Forks Last release: Not found 348 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Java Algorithm Problems

| Leetcode# | Problem | Level | Tags | Time | Space | Language | Sequence | |:---------:|:------------|:------:|:----:|-----:|------:|:--------:|---------:| |N/A|Jump Game II.java|Hard|[Array, Coordinate DP, DP, Greedy]|O(n)|O(1)|Java|0| |N/A|Majority Number II.java|Medium|[Enumeration, Greedy]|||Java|1| |N/A|Search a 2D Matrix II.java|Medium|[Binary Search, Divide and Conquer]|||Java|2| |N/A|Missing Ranges.java|Medium|[Array]|||Java|3| |N/A|Inorder Successor in BST.java|Medium|[BST, Tree]|||Java|4| |N/A|Convert Integer A to Integer B.java|Easy|[Bit Manipulation]|||Java|5| |N/A|Backpack VI.java|Medium|[Backpack DP, DP]|||Java|6| |N/A|Total Occurrence of Target.java|Medium|[]|||Java|7| |N/A|House Robber III.java|Medium|[DFS, DP, Status DP, Tree]|||Java|8| |N/A|Binary Tree Maximum Path Sum II.java|Medium|[DFS, Tree]|||Java|9| |N/A|Backpack V.java|Medium|[Backpack DP, DP]|||Java|10| |N/A|Closest Number in Sorted Array.java|Easy|[Binary Search]|||Java|11| |N/A|Convert Expression to Polish Notation.java|Hard|[Binary Tree, DFS, Expression Tree, Stack]|||Java|12| |N/A|Missing Number.java|Easy|[Array, Bit Manipulation, Math]|||Java|13| |N/A|Restore IP Addresses.java|Medium|[Backtracking, DFS, String]|||Java|14| |N/A|Linked List Cycle II.java|Medium|[Linked List, Math, Two Pointers]|||Java|15| |N/A|Unique Binary Search Tree.java|Medium|[BST, DP, Tree]|||Java|16| |N/A|Largest Number.java|Medium|[Sort]|||Java|17| |N/A|Reverse String.java|Easy|[String, Two Pointers]|||Java|18| |N/A|Triangles.java|Medium|[Array, Coordinate DP, DFS, DP, Memoization]|||Java|19| |N/A|Frog Jump.java|Hard|[DP, Hash Table]|||Java|20| |N/A|Summary Ranges.java|Medium|[Array]|||Java|21| |N/A|Sliding Window Median.java|Hard|[Design, Heap, MaxHeap, MinHeap, Sliding Window]|||Java|22| |N/A|Single Number III.java|Medium|[Bit Manipulation]|||Java|23| |N/A|Trailing Zeros.java|Easy|[Math]|||Java|24| |N/A|Fast Power.java|Medium|[DFS, Divide and Conquer]|||Java|25| |N/A|Perfect Rectangle.java|Hard|[Design, Geometry, Hash Table]|||Java|26| |N/A|Total Hamming Distance.java|Medium|[Bit Manipulation]|O(n)|O(1), 32-bit array|Java|27| |N/A|Word Pattern.java|Easy|[]|||Java|28| |N/A|Two Sum IV - Input is a BST.java|Easy|[Tree]|||Java|29| |N/A|Count 1 in Binary.java|Easy|[Bit Manipulation]|||Java|30| |N/A|Two Lists Sum.java|Medium|[Linked List]|||Java|31| |N/A|Flatten 2D Vector.java|Medium|[Design]|||Java|32| |N/A|Hamming Distance.java|Easy|[]|||Java|33| |N/A|Find the Weak Connected Component in the Directed Graph.java|Medium|[Union Find]|||Java|34| |N/A|Interval Minimum Number.java|Medium|[Binary Search, Divide and Conquer, Lint, Segment Tree]|||Java|35| |N/A|Stone Game.java|Medium|[DP]|||Java|36| |N/A|Longest Increasing Continuous subsequence II.java|Medium|[Array, Coordinate DP, DP, Memoization]|||Java|37| |N/A|Plus One.java|Easy|[Array, Math]|||Java|38| |N/A|Paint Fence.java|Easy|[DP, Sequence DP]|O(n)|O(n)|Java|39| |N/A|Line Reflection.java|Medium|[Hash Table, Math]|O(n)|O(n)|Java|40| |N/A|Binary Representation.java|Hard|[Bit Manipulation, String]|||Java|41| |N/A|Longest Consecutive Sequence.java|Hard|[Array, Hash Table, Union Find]|||Java|42| |N/A|Find Minimum in Rotated Sorted Array.java|Medium|[Array, Binary Search]|||Java|43| |N/A|Binary Tree Longest Consecutive Sequence II.java|Medium|[DFS, Divide and Conquer, Double Recursive, Tree]|||Java|44| |N/A|Minimum Subarray.java|Easy|[Array, DP, Greedy, Sequence DP, Subarray]|O(m)|O(1)|Java|45| |N/A|Connecting Graph.java|Medium|[Union Find]|||Java|46| |N/A|Count of Smaller Number.java|Medium|[Binary Search, Lint, Segment Tree]|||Java|47| |N/A|Binary Gap.java|Easy|[Bit Manipulation]|O(n), n = # of bits|O(1)|Java|48| |N/A|Flip Game II.java|Medium|[Backtracking, DFS, DP]|||Java|49| |N/A|Subtree of Another Tree.java|Easy|[DFS, Divide and Conquer, Tree]|||Java|50| |N/A|Binary Tree Level Order Traversal II.java|Medium|[BFS, Tree]|||Java|51| |N/A|Maximum Average Subarray I.java|Easy|[Array, Subarray]|O(n)|O(1)|Java|52| |N/A|IndexMatch.java|Easy|[]|||Java|53| |N/A|Walls and Gates.java|Medium|[BFS, DFS]|||Java|54| |N/A|Decode String.java|Medium|[DFS, Divide and Conquer, Stack]|||Java|55| |N/A|The Maze.java|Medium|[BFS, DFS]|||Java|56| |N/A|Palindromic Substrings.java|Medium|[DP, String]|||Java|57| |N/A|Rearrange String k Distance Apart.java|Hard|[Greedy, Hash Table, Heap]|||Java|58| |N/A|Count and Say.java|Easy|[Basic Implementation, String]|||Java|59| |N/A|Median of Two Sorted Arrays.java|Hard|[Array, Binary Search, DFS, Divide and Conquer]|||Java|60| |N/A|Perfect Squares.java|Medium|[BFS, DP, Math, Partition DP]|||Java|61| |N/A|Word Search.java|Medium|[Array, Backtracking, DFS]|||Java|62| |N/A|Backpack II.java|Medium|[Backpack DP, DP]|||Java|63| |N/A|Reshape the Matrix.java|Easy|[]|||Java|64| |N/A|Update Bits.java|Medium|[Bit Manipulation]|||Java|65| |N/A|Triangle Count.java|Medium|[Array]|||Java|66| |N/A|Remove Duplicate Letters.java|Hard|[Greedy, Hash Table, Stack]|||Java|67| |N/A|Permutation Sequence.java|Medium|[Backtracking, Math]|||Java|68| |N/A|House Robber II.java|Medium|[DP, Sequence DP, Status DP]|||Java|69| |N/A|O(1) Check Power of 2.java|Easy|[Bit Manipulation]|||Java|70| |N/A|Letter Combinations of a Phone Number.java|Medium|[Backtracking, String]|||Java|71| |N/A|Backspace String Compare.java|Easy|[Stack, Two Pointers]|||Java|72| |N/A|Minimum Size Subarray Sum.java|Medium|[Array, Binary Search, Subarray, Two Pointers]|O(n)|O(1)|Java|73| |N/A|Implement Stack using Queues.java|Easy|[Design, Stack]|||Java|74| |N/A|Minimum Absolute Difference in BST.java|Easy|[BST]|||Java|75| |N/A|Maximum Binary Tree.java|Medium|[Stack, Tree]|||Java|76| |N/A|ColorGrid.java|Medium|[Design, Hash Table]|||Java|77| |N/A|HashWithArray.java|Easy|[]|||Java|78| |N/A|Flood Fill.java|Easy|[DFS]|||Java|79| |N/A|Construct Binary Tree from Inorder and Postorder Traversal.java|Medium|[Array, DFS, Divide and Conquer, Tree]|||Java|80| |N/A|Backpack.java|Medium|[Backpack DP, DP]|||Java|81| |N/A|Longest Common Subsequence.java|Medium|[DP, Double Sequence DP, Sequence DP]|||Java|82| |N/A|Peeking Iterator.java|Medium|[Design]|||Java|83| |N/A|Orderly Queue.java|Hard|[Math, String]|||Java|84| |N/A|QuickSort.java|Medium|[Quick Sort, Sort]|||Java|85| |N/A|Maximal Rectangle.java|Hard|[Array, DP, Hash Table, Stack]|||Java|86| |N/A|Expression Evaluation.java|Hard|[Binary Tree, DFS, Expression Tree, Minimum Binary Tree, Stack]|||Java|87| |N/A|Subtree.java|Easy|[DFS, Tree]|||Java|88| |N/A|LFU Cache.java|Hard|[Design, Hash Table]|||Java|89| |N/A|Cosine Similarity.java|Easy|[Basic Implementation]|||Java|90| |N/A|Scramble String.java|Hard|[DP, Interval DP, String]|||Java|91| |N/A|Redundant Connection.java|Medium|[BFS, DFS, Graph, Tree, Union Find]|||Java|92| |N/A|Rotate List.java|Medium|[Linked List, Two Pointers]|||Java|93| |N/A|Swap Nodes in Pairs.java|Medium|[Linked List]|||Java|94| |N/A|Longest Increasing Continuous subsequence.java|Easy|[Array, Coordinate DP, DP]|||Java|95| |N/A|K Edit Distance.java|Hard|[DP, Double Sequence DP, Sequence DP, Trie]|||Java|96| |N/A|Combinations.java|Medium|[Backtracking, Combination, DFS]|||Java|97| |N/A|Max Area of Island.java|Easy|[Array, DFS]|||Java|98| |N/A|Sort List.java|Medium|[Divide and Conquer, Linked List, Merge Sort, Sort]|||Java|99| |N/A|Find Peak Element.java|Medium|[Array, Binary Search]|||Java|100| |N/A|Word Search II.java|Hard|[Backtracking, DFS, Trie]|||Java|101| |N/A|K Empty Slots.java|Hard|[Array, BST, TreeSet]|||Java|102| |N/A|Gray Code.java|Medium|[Backtracking]|||Java|103| |N/A|Encode and Decode TinyURL.java|Medium|[Hash Table, Math]|||Java|104| |N/A|Game of Life.java|Medium|[Array]|||Java|105| |N/A|Compare Version Numbers.java|Medium|[String]|||Java|106| |N/A|Singleton.java|Easy|[Design]|||Java|107| |N/A|Ugly Number.java|Medium|[Math]|||Java|108| |N/A|Russian Doll Envelopes.java|Hard|[Binary Search, Coordinate DP, DP]|||Java|109| |N/A|Rehashing.java|Medium|[Hash Table]|||Java|110| |N/A|Kth Smallest Sum In Two Sorted Arrays.java|Hard|[]|||Java|111| |N/A|Longest Common Substring.java|Medium|[DP, Double Sequence DP, Sequence DP, String]|||Java|112| |N/A|Rotate Image.java|Medium|[Array, Enumeration]|||Java|113| |N/A|Backpack III.java|Hard|[Backpack DP, DP]|||Java|114| |N/A|Combination Sum IV.java|Medium|[Array, Backpack DP, DP]|||Java|115| |N/A|Number of Longest Increasing Subsequence.java|Medium|[Coordinate DP, DP]|O(n^2)||Java|116| |N/A|Permutation Index.java|Easy|[]|||Java|117| |N/A|4Sum.java|Medium|[Hash Table]|||Java|118| |N/A|Shortest Palindrome.java|Hard|[KMP, String]|||Java|119| |N/A|Convert Sorted Array to Binary Search Tree.java|Easy|[DFS, Divide and Conquer, Tree]|||Java|120| |N/A|Populating Next Right Pointers in Each Node.java|Medium|[DFS, Divide and Conquer, Tree]|||Java|121| |N/A|Space Replacement.java|Medium|[String]|||Java|122| |N/A|Contiguous Array.java|Medium|[Hash Table]|||Java|123| |N/A|Reverse Linked List II .java|Medium|[Linked List]|||Java|124| |N/A|Palindrome Pairs.java|Hard|[Hash Table, String, Trie]|||Java|125| |N/A|Find Peak Element II.java|Hard|[Binary Search, DFS, Divide and Conquer]|||Java|126| |N/A|Minimum Height Trees.java|Medium|[BFS, Graph]|||Java|127| |N/A|Longest Substring Without Repeating Characters.java|Medium|[Hash Table, String, Two Pointers]|||Java|128| |N/A|Fraction to Recurring Decimal.java|Medium|[Hash Table, Math]|||Java|129| |N/A|Wiggle Sort.java|Medium|[Array, Sort]|||Java|130| |N/A|Reverse Words in a String II.java|Medium|[String]|||Java|131| |N/A|Remove Node in Binary Search Tree.java|Hard|[BST]|||Java|132| |N/A|Reorder List.java|Medium|[Linked List]|||Java|133| |N/A|Redundant Connection II.java|Hard|[DFS, Graph, Tree, Union Find]|||Java|134| |N/A|[tool] Quick Select - Median.java|Easy|[Array, Lint, Quick Select, Quick Sort, Two Pointers]|O(n)|O(logN)|Java|135| |N/A|Swap Bits.java|Easy|[Bit Manipulation]|||Java|136| |N/A|Friends Of Appropriate Ages.java|Medium|[Array, Math]|||Java|137| |N/A|Longest Increasing Subsequence.java|Medium|[Binary Search, Coordinate DP, DP, Memoization]|O(n^2) dp, O(nLogN) binary search|O(n)|Java|138| |N/A|Power of Two.java|Easy|[Bit Manipulation, Math]|||Java|139| |N/A|Min Stack.java|Easy|[Design, Stack]|||Java|140| |N/A|Count of Smaller Number before itself.java|Hard|[]|||Java|141| |N/A|Majority Number III.java|Medium|[Hash Table, Linked List]|||Java|142| |N/A|Number of Digit One.java|Hard|[Math]|||Java|143| |N/A|Tweaked Identical Binary Tree.java|Easy|[DFS, Tree]|||Java|144| |N/A|Search Range in Binary Search Tree .java|Medium|[BST, Binary Tree]|||Java|145| |N/A|Best Time to Buy and Sell Stock III.java|Hard|[Array, DP, Sequence DP]|||Java|146| |N/A|Design Search Autocomplete System.java|Hard|[Design, Hash Table, MinHeap, PriorityQueue, Trie]|input: O(x), where x = possible words, constructor: O(mn) m = max length, n = # of words|O(n^2), n = # of possible words, n = # of trie levels; mainlay saving the

Map
|Java|147| |N/A|Subsets II.java|Medium|[Array, BFS, Backtracking, DFS]|O(2^n)||Java|148| |N/A|One Edit Distance.java|Medium|[String]|||Java|149| |N/A|Segment Tree Modify.java|Medium|[Binary Tree, DFS, Divide and Conquer, Lint, Segment Tree]|||Java|150| |N/A|Distinct Subsequences.java|Hard|[DP, String]|||Java|151| |N/A|Insert Node in a Binary Search Tree .java|Easy|[BST]|||Java|152| |N/A|Container With Most Water.java|Medium|[Array, Two Pointers]|||Java|153| |N/A|Word Ladder.java|Medium|[BFS]|||Java|154| |N/A|Single Number II.java|Medium|[Bit Manipulation]|||Java|155| |N/A|Heaters.java|Easy|[]|||Java|156| |N/A|Kth Smallest Element in a BST.java|Medium|[BST, DFS, Stack, Tree]|||Java|157| |N/A|Robot Room Cleaner.java|Hard|[Backtracking, DFS]|||Java|158| |N/A|Coins in a Line II.java|Medium|[Array, DP, Game Theory, Memoization, MiniMax]|||Java|159| |N/A|Partition List.java|Medium|[Linked List, Two Pointers]|||Java|160| |N/A|Classical Binary Search.java|Easy|[Binary Search]|||Java|161| |N/A|Wood Cut.java|Medium|[Binary Search]|||Java|162| |N/A|Connecting Graph III.java|Medium|[Union Find]|||Java|163| |N/A|Invert Binary Tree.java|Easy|[BFS, DFS, Tree]|||Java|164| |N/A|Remove Duplicates from Unsorted List.java|Medium|[Linked List]|||Java|165| |N/A|Maximum Size Subarray Sum Equals k.java|Medium|[Hash Table, PreSum, Subarray]|O(n)|O(n)|Java|166| |N/A|The Smallest Difference.java|Medium|[Array, Sort, Two Pointers]|||Java|167| |N/A|Unique Binary Search Tree II.java|Medium|[BST, DP, Divide and Conquer, Tree]|||Java|168| |N/A|Encode and Decode Strings.java|Medium|[String]|||Java|169| |N/A|Remove Duplicates from Sorted List II.java|Medium|[Linked List]|||Java|170| |N/A|Subarray Sum II.java|Hard|[Array, Binary Search, Two Pointers]|||Java|171| |N/A|Matrix Zigzag Traversal.java|Easy|[]|||Java|172| |N/A|Ones and Zeroes.java|Hard|[DP]|||Java|173| |N/A|Number of Connected Components in an Undirected Graph.java|Medium|[BFS, DFS, Graph, Union Find]|||Java|174| |N/A|Submatrix Sum.java|Medium|[Array, Hash Table, PreSum]|||Java|175| |N/A|Zigzag Iterator.java|Medium|[BST]|||Java|176| |N/A|Find the Connected Component in the Undirected Graph.java|Medium|[BFS, DFS]|||Java|177| |N/A|Implement Stack.java|Easy|[Stack]|||Java|178| |N/A|Number of Airplane in the sky.java|Medium|[Array, Interval, PriorityQueue, Sort, Sweep Line]|||Java|179| |N/A|Surrounded Regions.java|Medium|[BFS, DFS, Matrix DFS, Union Find]|||Java|180| |N/A|Wildcard Matching.java|Hard|[Backtracking, DP, Double Sequence DP, Greedy, Sequence DP, String]|||Java|181| |N/A|Expression Add Operators.java|Hard|[Backtracking, DFS, Divide and Conquer, String]|O(4^n)|O(4^n)|Java|182| |N/A|Cracking the Safe.java|Hard|[DFS, Greedy, Math]|||Java|183| |N/A|Unique Word Abbreviation.java|Medium|[Design, Hash Table]|||Java|184| |N/A|Best Time to Buy and Sell Stock IV.java|Hard|[DP, Sequence DP]|||Java|185| |N/A|Find Minimum in Rotated Sorted Array II.java|Hard|[Array, Binary Search]|||Java|186| |N/A|Longest Valid Parentheses.java|Hard|[Coordinate DP, Stack, String]|||Java|187| |N/A|Ugly Number II.java|Medium|[DP, Enumeration, Heap, Math, PriorityQueue]|O(n)|O(n)|Java|188| |N/A|Add Two Numbers II.java|Medium|[Linked List]|||Java|189| |N/A|Maximum Average Subarray II.java|Review|[Array, Binary Search, PreSum]|||Java|190| |N/A|Expression Tree Build.java|Hard|[Binary Tree, Expression Tree, Minimum Binary Tree, Stack]|||Java|191| |N/A|Merge Two Binary Trees.java|Easy|[DFS, Tree]|||Java|192| |N/A|Copy Books.java|Hard|[Binary Search, DP, Partition DP]|||Java|193| |N/A|Power of Three.java|Easy|[Math]|||Java|194| |N/A|Sort Colors II.java|Medium|[Partition, Quick Sort, Sort, Two Pointers]|||Java|195| |N/A|Maximum Subarray III.java|Review|[]|||Java|196| |N/A|Path Sum II.java|Easy|[Backtracking, DFS, Tree]|||Java|197| |N/A|Segment Tree Query II.java|Medium|[Binary Tree, DFS, Divide and Conquer, Lint, Segment Tree]|||Java|198| |N/A|Shortest Distance from All Buildings.java|Hard|[BFS]|||Java|199| |N/A|Brick Wall.java|Medium|[Hash Table]|O(mn)|O(X), X = max wall width|Java|200| |N/A|Longest Increasing Path in a Matrix.java|Hard|[Coordinate DP, DFS, DP, Memoization, Topological Sort]|||Java|201| |N/A|Interleaving String.java|Hard|[DP, String]|||Java|202| |N/A|Shuffle an Array.java|Medium|[Permutation]|||Java|203| |N/A|Recover Binary Search Tree.java|Hard|[BST, DFS, Tree]|||Java|204| |N/A|My Calendar I.java|Medium|[Array, TreeMap]|||Java|205| |N/A|Evaluate Reverse Polish Notation.java|Medium|[Stack]|O(n)|O(n)|Java|206| |N/A|Counting Bits.java|Medium|[Bit Manipulation, Bitwise DP, DP]|||Java|207| |N/A|Sort Letters by Case.java|Medium|[Partition, Sort, String, Two Pointers]|||Java|208| |N/A|Two Strings Are Anagrams.java|Easy|[]|||Java|209| |N/A|Two Sum II - Input array is sorted.java|Medium|[Array, Binary Search, Two Pointers]|||Java|210| |N/A|[HackerRank]. Change to Anagram.java|Easy|[String]|||Java|211| |N/A|Implement Queue using Stacks.java|Easy|[Design, Stack]|||Java|212| |N/A|Basic Calculator.java|Hard|[Binary Tree, Expression Tree, Math, Minimum Binary Tree, Stack]|||Java|213| |N/A|Word Squares.java|Hard|[Backtracking, Trie]|||Java|214| |N/A|Insertion Sort List.java|Medium|[Linked List, Sort]|||Java|215| |N/A|Interval Sum.java|Medium|[Binary Search, Lint, Segment Tree]|||Java|216| |N/A|Strobogrammatic Number II.java|Medium|[DFS, Enumeration, Math, Sequence DFS]|||Java|217| |N/A|The Maze II.java|Medium|[BFS, DFS, PriorityQueue]|||Java|218| |N/A|k Sum.java|Hard|[DP]|||Java|219| |N/A|Coins in a Line III.java|Hard|[Array, DP, Game Theory, Interval DP, Memoization]|||Java|220| |N/A|Convert Sorted List to Binary Search Tree.java|Medium|[BST, DFS, Divide and Conquer, Linked List]|||Java|221| |N/A|Guess Number Higher or Lower.java|Easy|[Binary Search]|||Java|222| |N/A|Trapping Rain Water II.java|Hard|[BFS, Heap, MinHeap, PriorityQueue]|||Java|223| |N/A|Bricks Falling When Hit.java|Hard|[Union Find]|||Java|224| |N/A|Subarray Sum Closest.java|Medium|[PreSum, PriorityQueue, Sort, Subarray]|O(nlogn)|O(n)|Java|225| |N/A|Burst Balloons.java|Hard|[DP, Divide and Conquer, Interval DP, Memoization]|||Java|226| |N/A|Partition Array by Odd and Even.java|Easy|[Array, Two Pointers]|||Java|227| |N/A|Best Time to Buy and Sell Stock with Cooldown.java|Medium|[DP]|||Java|228| |N/A|Palindrome Partitioning II.java|Hard|[DP, Partition DP]|||Java|229| |N/A|Convert Binary Search Tree to Sorted Doubly Linked List (extra space).java|Medium|[Linked List, Stack, Tree]|O(n)|O(n)|Java|230| |N/A|Kth Largest Element in an Array.java|Medium|[Divide and Conquer, Heap, MinHeap, PriorityQueue, Quick Sort]|||Java|231| |N/A|Sliding Puzzle.java|Hard|[BFS, Graph]|||Java|232| |N/A|Interval Sum II.java|Hard|[Binary Search, Lint, Segment Tree]|||Java|233| |N/A|Add Digits.java|Easy|[Math]|||Java|234| |N/A|HashWithCustomizedClass(LinkedList).java|Medium|[Hash Table]|||Java|235| |N/A|Maximum Vacation Days.java|Hard|[DP]|||Java|236| |N/A|Smallest Subtree with all the Deepest Nodes.java|Medium|[DFS, Divide and Conquer, Tree]|O(n)|O(n)|Java|237| |N/A|Kth Smallest Element in a Sorted Matrix.java|Medium|[Binary Search, Heap]|O(n + klogn)|O(n)|Java|238| |N/A|Combination Sum III.java|Medium|[Array, Backtracking, Combination, DFS]|||Java|239| |N/A|Last Position of Target.java|Easy|[Binary Search]|||Java|240| |N/A|Path Sum III.java|Easy|[DFS, Double Recursive, Tree]|||Java|241| |N/A|Convert Expression to Reverse Polish Notation.java|Hard|[Binary Tree, DFS, Expression Tree, Stack]|||Java|242| |N/A|Complete Binary Tree.java|Easy|[BFS, Tree]|||Java|243| |N/A|Best Time to Buy and Sell Stock with Transaction Fee.java|Medium|[Array, DP, Greedy, Sequence DP, Status DP]|O(n)|O(n), O(1) rolling array|Java|244| |N/A|Pow(x, n).java|Medium|[Binary Search, Math]|||Java|245| |N/A|Maximum Subarray II.java|Medium|[Array, DP, Greedy, PreSum, Sequence DP, Subarray]|||Java|246| |N/A|Sort Colors.java|Medium|[Array, Partition, Quick Sort, Sort, Two Pointers]|||Java|247| |N/A|Word Ladder II.java|Hard|[Array, BFS, Backtracking, DFS, Hash Table, String]|||Java|248| |N/A|Sum of Two Integers.java|Easy|[Bit Manipulation]|||Java|249| |N/A|Predict the Winner.java|Medium|[DP, MiniMax]|||Java|250| |N/A|Connecting Graph II.java|Medium|[Union Find]|||Java|251| |N/A|Search Insert Position.java|Easy|[]|||Java|252| |N/A|Longest Univalue Path.java|Easy|[]|||Java|253| |N/A|Contains Duplicate III.java|Medium|[BST]|||Java|254| |N/A|Spiral Matrix.java|Medium|[Array, Enumeration]|||Java|255| |N/A|Next Closest Time.java|Medium|[Basic Implementation, Enumeration, String]|||Java|256| |N/A|Group Shifted Strings.java|Medium|[Hash Table, String]|||Java|257| |N/A|The Maze III.java|Hard|[BFS, DFS, PriorityQueue]|||Java|258| |N/A|Coins in a Line.java|Medium|[DP, Game Theory, Greedy]|||Java|259| |N/A|Binary Tree Longest Consecutive Sequence.java|Medium|[DFS, Divide and Conquer, Tree]|||Java|260| |N/A|The Spiral Matrix II.java|Medium|[Array]|||Java|261| |N/A|Trim a Binary Search Tree.java|Easy|[BST, Tree]|||Java|262| |N/A|Number Of Corner Rectangles.java|Medium|[DP, Math]|||Java|263| |N/A|Queue Reconstruction by Height.java|Medium|[Greedy]|||Java|264| |N/A|Minimum Swaps To Make Sequences Increasing.java|Medium|[Coordinate DP, DP, Status DP]|||Java|265| |N/A|Interleaving Positive and Negative Numbers.java|Medium|[Two Pointers]|||Java|266| |N/A|Path Sum IV.java|Medium|[DFS, Hash Table, Tree]|||Java|267| |N/A|Excel Sheet Column Number.java|Easy|[Math]|||Java|268| |N/A|Target Sum.java|Medium|[DFS, DP]|||Java|269| |N/A|Partition Array.java|Medium|[Array, Quick Sort, Sort, Two Pointers]|||Java|270| |N/A|Bus Routes.java|Hard|[BFS]|||Java|271| |N/A|Max Sum of Rectangle No Larger Than K.java|Hard|[Array, BST, Binary Search, DP, Queue, TreeSet]|||Java|272| |N/A|String Permutation.java|Easy|[]|||Java|273| |N/A|Maximum XOR of Two Numbers in an Array.java|Medium|[Bit Manipulation, Trie]|||Java|274| |N/A|Search for a Range.java|Medium|[Array, Binary Search]|||Java|275| |N/A|Palindrome Permutation II.java|Medium|[Backtracking, Permutation]|||Java|276| |N/A|Populating Next Right Pointers in Each Node II.java|Medium|[DFS, Tree]|O(n)|O(1)|Java|277| |N/A|Nim Game.java|Easy|[Brainteaser, DP, Game Theory]|||Java|278| |N/A|Search a 2D Matrix.java|Medium|[Array, Binary Search]|||Java|279| |N/A|Largest Rectangle in Histogram.java|Hard|[Array, Monotonous Stack, Stack]|||Java|280| |[lint]|[lint]. Merge k Sorted Arrays.java|Medium|[Heap, MinHeap, PriorityQueue]|O(nlogk)|O(k)|Java|281| |[lint]|[lint]. Segment Tree Build II.java|Medium|[Binary Tree, Divide and Conquer, Lint, Segment Tree]|||Java|282| |[lint]|[lint]. Nth to Last Node in List.java|Easy|[Linked List, Lint]|||Java|283| |[lint]|[lint]. Product of Array Exclude Itself.java|Medium|[Array, Lint]|||Java|284| |[lint]|[lint]. Compare Strings.java|Easy|[Lint, String]|||Java|285| |[lint]|[lint]. Segment Tree Query.java|Medium|[Binary Tree, DFS, Divide and Conquer, Lint, Segment Tree]|||Java|286| |[lint]|[lint]. HashHeap.java|Hard|[HashHeap, Heap, Lint]|||Java|287| |[lint]|[lint]. Longest Words.java|Easy|[Hash Table, Lint, String]|||Java|288| |[lint]|[lint]. Anagrams.java|Medium|[Array, Hash Table, Lint]|O(n)|O(n)|Java|289| |[lint]|[lint]. 3 Sum Closest.java|Medium|[Array, Lint, Two Pointers]|||Java|290| |[lint]|[lint]. Unique Characters.java|Easy|[Array, Lint, String]|||Java|291| |[lint]|[lint]. Lowest Common Ancestor II.java|Easy|[Hash Table, Lint, Tree]|||Java|292| |[lint]|[lint]. Heapify.java|Medium|[HashHeap, Heap, Lint, MinHeap]|||Java|293| |[lint]|[lint]. Subarray Sum.java|Easy|[Array, Hash Table, Lint, PreSum, Subarray]|O(n)|O(n)|Java|294| |[lint]|[lint]. Recover Rotated Sorted Array.java|Easy|[Array, Lint]|||Java|295| |[lint]|[lint]. 2 Sum II.java|Medium|[Array, Binary Search, Lint, Two Pointers]|||Java|296| |[lint]|[lint]. Segment Tree Build.java|Medium|[Binary Tree, Divide and Conquer, Lint, Segment Tree]|||Java|297| |[tool]|[tool]. MergeSort.java|Medium|[Lint, Merge Sort, Sort]|O(mlogn)|O(n)|Java|298| |[tool]|[tool]. Hash Function.java|Easy|[Hash Table, Lint]|O(1) get|O(n) store map|Java|299| |[tool]|[tool]. UnionFind.java|Medium|[Lint, Union Find]|O(n), with Path Compression O(mN), with Union by Rank O(logN)|O(n)|Java|300| |[tool]|[tool]. Topological Sorting.java|Medium|[BFS, DFS, Lint, Topological Sort]|O(V + E)|O(V + E)|Java|301| |36|36. Valid Sudoku.java|Easy|[Enumeration, Hash Table]|(mn)|(mn)|Java|302| |359|359. Logger Rate Limiter.java|Easy|[Design, Hash Table]|O(1)|O(n)|Java|303| |198|198. House Robber.java|Easy|[DP, Sequence DP, Status DP]|O(n)|O(n) or rolling array O(1)|Java|304| |21|21. Merge Two Sorted Lists.java|Easy|[Linked List]|O(n)|O(1)|Java|305| |102|102. Binary Tree Level Order Traversal.java|Medium|[BFS, DFS, Tree]|O(n)|O(n)|Java|306| |788|788. Rotated Digits.java|Easy|[Basic Implementation, String]|O(n)|O(n)|Java|307| |42|42. Trapping Rain Water.java|Hard|[Array, Stack, Two Pointers]|O(n)|O(1)|Java|308| |347|347. Top K Frequent Elements.java|Medium|[Hash Table, Heap, MaxHeap, MinHeap, PriorityQueue]|O(n)|O(n)|Java|309| |269|269. Alien Dictionary.java|Hard|[BFS, Backtracking, DFS, Graph, Topological Sort]|O(n), n = # of graph edges|O(n)|Java|310| |237|237. Delete Node in a Linked List.java|Easy|[Linked List]|||Java|311| |142|142. Linked List Cycle II.java|Medium|[Cycle Detection, Linked List, Slow Fast Pointer, Two Pointers]|O(n)|O(1)|Java|312| |448|448. Find All Numbers Disappeared in an Array.java|Easy|[Array, Bucket Sort]|O(n)|O(1)|Java|313| |360|360. Sort Transformed Array.java|Medium|[Math, Two Pointers]|O(n)|O(n) store result|Java|314| |22|22. Generate Parentheses.java|Medium|[Backtracking, DFS, Sequence DFS, String]|O(2^n)|O(2^n)|Java|315| |849|849. Maximize Distance to Closest Person.java|Easy|[Array, Basic Implementation, Two Pointers]|O(n)|O(1)|Java|316| |408|408. Valid Word Abbreviation.java|Easy|[Basic Implementation, String]|||Java|317| |415|415. Add Strings.java|Easy|[Basic Implementation, Math, String]|O(n)|O(n)|Java|318| |83|83. Remove Duplicates from Sorted List.java|Easy|[Linked List]|||Java|319| |1108|1108. Defanging an IP Address.java|Easy|[Basic Implementation, String]|||Java|320| |1021|1021. Remove Outermost Parentheses.java|Easy|[Stack]|||Java|321| |236|236. Lowest Common Ancestor of a Binary Tree.java|Medium|[DFS, Tree]|O(n)|O(n)|Java|322| |766|766. Toeplitz Matrix.java|Easy|[Array]|O(mn)|O(1)|Java|323| |953|953. Verifying an Alien Dictionary.java|Easy|[Hash Table]|O(nm)|O(1)|Java|324| |1053|1053. Previous Permutation With One Swap.java|Medium|[Array, Greedy, Permutation]|O(n)|O(1)|Java|325| |1213|1213. Intersection of Three Sorted Arrays.java|Easy|[Hash Table, Two Pointers]|O(m + n + h) two pointers approach|O(1)|Java|326| |383|383. Ransom Note.java|Easy|[Basic Implementation, String]|||Java|327| |56|56. Merge Intervals.java|Medium|[Array, PriorityQueue, Sort, Sweep Line]|O(nlogn)|O(n)|Java|328| |252|252. Meeting Rooms.java|Easy|[PriorityQueue, Sort, Sweep Line]|O(nlogn)|O(1)|Java|329| |665|665. Non-decreasing Array.java|Easy|[Array]|O(n)|O(1)|Java|330| |843|843. Guess the Word.java|Hard|[MiniMax]|TODO|TODO|Java|331| |986|986. Interval List Intersections.java|Medium|[Two Pointers]|O(n)|O(1)|Java|332| |76|76. Minimum Window Substring.java|Hard|[Hash Table, Sliding Window, String, Two Pointers]|O(n)|O(1)|Java|333| |293|293. Flip Game.java|Easy|[String]|||Java|334| |244|244. Shortest Word Distance II.java|Medium|[Array, Design, Hash Table, Two Pointers]|O(n) to build map, O(a + b) to query|O(n)|Java|335| |686|686. Repeated String Match.java|Easy|[Basic Implementation, Edge Case, String]|||Java|336| |80|80.Remove Duplicates from Sorted Array II.java|Medium|[Array, Two Pointers]|||Java|337| |301|301. Remove Invalid Parentheses.java|Hard|[BFS, DFS, DP]|||Java|338| |111|111. Minimum Depth of Binary Tree.java|Easy|[BFS, DFS, Tree]|O(n)|O(n)|Java|339| |1216|1216. Valid Palindrome III.java|Hard|[DFS, DP, Memoization, String]|O(n^2)|O(n^2)|Java|340| |7|7. Reverse Integer.java|Easy|[Math]|O(n)|O(1)|Java|341| |5|5. Longest Palindromic Substring.java|Medium|[DP, String]|O(n^2)|O(n^2)|Java|342| |303|303. Range Sum Query - Immutable.java|Easy|[DP, PreSum]|O(1) query, O(n) setup|O(n)|Java|343| |674|674. Longest Continuous Increasing Subsequence.java|Easy|[Array, Coordinate DP, DP, Sliding Window]|O(n)|O(1)|Java|344| |1007|1007. Minimum Domino Rotations For Equal Row.java|Medium|[Array, Greedy]|O(n)|O(1)|Java|345| |485|485. Max Consecutive Ones.java|Easy|[Array, Basic Implementation]|O(n)|O(1)|Java|346| |896|896. Monotonic Array.java|Easy|[Array]|||Java|347| |207|207. Course Schedule.java|Medium|[BFS, Backtracking, DFS, Graph, Topological Sort]|O(n)|O(n)|Java|348| |327|327. Count of Range Sum.java|Hard|[BIT, Divide and Conquer, Merge Sort, PreSum, Segment Tree]|O(nlogn)|O(n)|Java|349| |987|987. Vertical Order Traversal of a Binary Tree.java|Medium|[BFS, Binary Tree, DFS, Hash Table, Tree]|||Java|350| |26|26.Remove Duplicates from Sorted Array.java|Easy|[Array, Two Pointers]|||Java|351| |429|429. N-ary Tree Level Order Traversal.java|Medium|[BFS, Tree]|O(n)|O(n)|Java|352| |275|275. H-Index II.java|Medium|[Binary Search]|O(logN)|O(1) extra|Java|353| |204|204. Count Primes.java|Easy|[Hash Table, Math]|||Java|354| |58|58. Length of Last Word.java|Easy|[String]|||Java|355| |496|496. Next Greater Element I.java|Easy|[Hash Table, Stack]|O(n)|O(n)|Java|356| |41|41. First Missing Positive.java|Hard|[Analysis, Array, Edge Case]|O(n)|O(1)|Java|357| |694|694. Number of Distinct Islands.java|Medium|[DFS, Hash Table]|O(n)|O(n)|Java|358| |717|717. 1-bit and 2-bit Characters.java|Easy|[Array]|||Java|359| |53|53. Maximum Subarray.java|Easy|[Array, DFS, DP, Divide and Conquer, PreSum, Sequence DP, Subarray]|O(n)|O(n), O(1) rolling array|Java|360| |152|152. Maximum Product Subarray.java|Medium|[Array, DP, PreProduct, Subarray]|O(n)|O(1)|Java|361| |199|199. Binary Tree Right Side View.java|Medium|[BFS, DFS, Tree]|O(n)|O(n)|Java|362| |259|259. 3Sum Smaller.java|Medium|[Array, Sort, Two Pointers]|||Java|363| |977|977. Squares of a Sorted Array.java|Easy|[Array, Two Pointers]|O(n)|O(n)|Java|364| |824|824. Goat Latin.java|Easy|[Basic Implementation, String]|O(n)|O(1)|Java|365| |308|308. Range Sum Query 2D - Mutable.java|Hard|[Binary Indexed Tree, Segment Tree]|build(n), update(logn), rangeRuery(logn + k)|O(n)|Java|366| |1203|1203. Sort Items by Groups Respecting Dependencies.java|Hard|[BFS, DFS, Graph, Topological Sort]|O(V + E) to traverse the graph, #nodes + #edges|O(V + E)|Java|367| |1153|1153. String Transforms Into Another String.java|Hard|[Graph]|O(n)|O(n)|Java|368| |1008|1008. Construct Binary Search Tree from Preorder Traversal.java|Medium|[DFS, Tree]|O(n)|O(n)|Java|369| |151|151. Reverse Words in a String.java|Medium|[String]|O(n)||Java|370| |855|855. Exam Room.java|Medium|[PriorityQueue, Sort, TreeMap, TreeSet]|O(logn)|O(n)|Java|371| |31|31. Next Permutation.java|Medium|[Array, Permutation]|O(n)|O(1)|Java|372| |518|518. Coin Change 2.java|Medium|[Backpack DP, DP]|O(n)|O(n)|Java|373| |405|405. Convert a Number to Hexadecimal.java|Easy|[Bit Manipulation]|||Java|374| |850|850. Rectangle Area II.java|Hard|[Segment Tree, Sweep Line]|O(n^2)|O(n)|Java|375| |515|515. Find Largest Value in Each Tree Row.java|Medium|[BFS, DFS, Tree]|O(n)|O(n)|Java|376| |253|253. Meeting Rooms II.java|Medium|[Greedy, Heap, PriorityQueue, Sort, Sweep Line]|O(nlogn)|O(n)|Java|377| |1161|1161. Maximum Level Sum of a Binary Tree.java|Medium|[BFS, DFS, Graph]|O(n) visit all nodes|O(n)|Java|378| |509|509. Fibonacci Number.java|Easy|[DP, Math, Memoization]|||Java|379| |221|221. Maximal Square.java|Medium|[Coordinate DP, DP]|O(mn)|O(mn)|Java|380| |131|131. Palindrome Partitioning.java|Medium|[Backtracking, DFS]|O(2^n)|O(n^2)|Java|381| |136|136. Single Number.java|Easy|[Bit Manipulation, Hash Table]|||Java|382| |222|222. Count Complete Tree Nodes.java|Medium|[Binary Search, DFS, Tree]|O(n)|O(h)|Java|383| |257|257. Binary Tree Paths.java|Easy|[Backtracking, Binary Tree, DFS]|O(n)|O(nlogn)|Java|384| |543|543. Diameter of Binary Tree.java|Easy|[Tree]|O(n) when non-balanced|O(n) when non-balanced|Java|385| |398|398. Random Pick Index.java|Medium|[Reservior Sampling]|O(n)|O(n) for input int[], O(1) extra space used|Java|386| |238|238. Product of Array Except Self.java|Medium|[Array, PreProduct]|O(n)|O(1)|Java|387| |1060|1060. Missing Element in Sorted Array.java|Medium|[Binary Search]|O(logn)|O(1)|Java|388| |1048|1048. Longest String Chain.java|Medium|[Bucket Sort, DP, Hash Table, Sort]|O(n)|O(n)|Java|389| |67|67. Add Binary.java|Easy|[Math, String, Two Pointers]|||Java|390| |299|299. Bulls and Cows.java|Medium|[Hash Table]|O(n)|O(n)|Java|391| |557|557. Reverse Words in a String III.java|Easy|[String]|||Java|392| |203|203. Remove Linked List Elements.java|Easy|[Linked List]|||Java|393| |1219|1219. Path with Maximum Gold.java|Medium|[Backtracking, DFS]|O(n^2)|O(n) recursive depth|Java|394| |266|266. Palindrome Permutation.java|Easy|[Hash Table]|O(n)|O(n)|Java|395| |62|62. Unique Path.java|Medium|[Array, Coordinate DP, DP]|O(mn)|O(mn), rolling array O(n)|Java|396| |1091|1091. Shortest Path in Binary Matrix.java|Medium|[BFS]|O(n^2)||Java|397| |1110|1110. Delete Nodes And Return Forest.java|Medium|[DFS, Divide and Conquer, Tree]|O(n)|O(logn)|Java|398| |1249|1249. Minimum Remove to Make Valid Parentheses.java|Medium|[Stack, String]|O(n)|O(n)|Java|399| |15|15. 3Sum.java|Medium|[Array, Sort, Two Pointers]|O(n^2)||Java|400| |311|311. Sparse Matrix Multiplication.java|Medium|[Hash Table]|O(mnk), where
m = A.row
,
n = B.col
,
k = A.col = B.row
|O(1) extra|Java|401| |339|339. Nested List Weight Sum.java|Easy|[BFS, DFS, NestedInteger]|O(n)|O(h), h = levels|Java|402| |322|322. Coin Change.java|Medium|[Backpack DP, DFS, DP, Memoization]|O(n * S)|O(S)|Java|403| |55|55. Jump Game.java|Medium|[Array, DP, Greedy]|O(n)|O(1)|Java|404| |173|173. Binary Search Tree Iterator.java|Medium|[BST, Design, Stack, Tree]|O(1) average|O(h)|Java|405| |140|140. Word Break II.java|Hard|[Backtracking, DFS, DP, Hash Table, Memoization]|O(n!)|O(n!)|Java|406| |51|51. N-Queens.java|Hard|[Backtracking]|O(n!)|O(n^2)|Java|407| |875|875. Koko Eating Bananas.java|Medium|[Binary Search]|O(n*logM)|O(1)|Java|408| |189|189. Rotate Array.java|Easy|[Array, Rotation]|||Java|409| |19|19. Remove Nth Node From End of List.java|Medium|[Linked List, Two Pointers]|O(n)|O(1)|Java|410| |134|134. Gas Station.java|Medium|[Greedy]|O(n)|O(1)|Java|411| |119|119. Pascal's Triangle II.java|Easy|[Array, Basic Implementation]|O(k^2), pascal triangle size|O(k^2)|Java|412| |1197|1197. Minimum Knight Moves.java|Medium|[BFS]|O(8^n)|O(8^n)|Java|413| |493|493. Reverse Pairs.java|Medium|[BST, Binary Indexed Tree, Divide and Conquer, Merge Sort, Segment Tree]|||Java|414| |1306|1306. Jump Game III.java|Medium|[BFS, Graph]|O(n)|O(n)|Java|415| |305|305. Number of Islands II.java|Hard|[Union Find]|O(k * log(mn))|O(mn)|Java|416| |206|206. Reverse Linked List.java|Easy|[Linked List]|||Java|417| |277|277. Find the Celebrity.java|Medium|[Adjacency Matrix, Array, Graph, Greedy, Pruning]|O(n)|O(1)|Java|418| |741|741. Cherry Pickup.java|Hard|[DFS, DP]|O(n^3)|O(n^3), memo size|Java|419| |168|168. Excel Sheet Column Title.java|Easy|[Math]|O(n)|O(1)|Java|420| |104|104. Maximum Depth of Binary Tree.java|Easy|[DFS, Tree]|||Java|421| |349|349. Intersection of Two Arrays.java|Easy|[Binary Search, Hash Table, Sort, Two Pointers]|O(m + n)|O(m + n)|Java|422| |443|443. String Compression.java|Easy|[Basic Implementation, String]|||Java|423| |297|297. Serialize and Deserialize Binary Tree.java|Hard|[BFS, DFS, Deque, Design, Divide and Conquer, Tree]|O(n)|O(n)|Java|424| |46|46. Permutations.java|Medium|[BFS, Backtracking, DFS, Permutation]|O(n!)|O(n!)|Java|425| |844|844. Backspace String Compare.java|Easy|[Stack, Two Pointers]|O(n)|O(1)|Java|426| |9|9. Palindrome Number.java|Easy|[Math]|||Java|427| |1094|1094. Car Pooling.java|Medium|[Greedy, Heap, PriorityQueue, Sort]|O(n)|O(1) only use bucket size 1000|Java|428| |245|245. Shortest Word Distance III.java|Medium|[Array, Design, Hash Table, Two Pointers]|O(n)|O(1)|Java|429| |1117|1117. Building H2O.java|Medium|[Lock, Semaphore, Thread]|||Java|430| |973|973. K Closest Points to Origin.java|Medium|[Divide and Conquer, Heap, Sort]|O(klogk)|O(k)|Java|431| |771|771. Jewels and Stones.java|Easy|[Hash Table]|O(n)|O(n)|Java|432| |200|200. Number of Islands.java|Medium|[BFS, DFS, Matrix DFS, Union Find]|O(n)|O(n)|Java|433| |141|141. Linked List Cycle.java|Easy|[Cycle Detection, Linked List, Slow Fast Pointer, Two Pointers]|O(n)|O(1)|Java|434| |567|567. Permutation in String.java|Medium|[Sliding Window, Two Pointers]|O(m + n)|O(1)|Java|435| |727|727. Minimum Window Subsequence.java|Hard|[DP, Hash Table, Sliding Window, String, Two Pointers]|O(n^2)|O(1)|Java|436| |158|158. Read N Characters Given Read4 II - Call multiple times.java|Hard|[Enumeration, String]|O(n)|O(n)|Java|437| |369|369. Plus One Linked List.java|Medium|[Linked List]|O(n)|O(1)|Java|438| |211|211. Add and Search Word - Data structure design.java|Medium|[Backtracking, Design, Trie]|O(n) to search and to add word|< O(mn), depends on the input. m = # of words|Java|439| |43|43. Multiply Strings.java|Medium|[Math, String]|O(mn)|O(mn)|Java|440| |621|621. Task Scheduler.java|Medium|[Array, Enumeration, Greedy, PriorityQueue, Queue]|O(n)|O(1)|Java|441| |680|680. Valid Palindrome II.java|Easy|[String]|||Java|442| |295|295. Find Median from Data Stream.java|Hard|[Design, Heap, MaxHeap, MinHeap]|O(1) get, O(logn) addNum|O(n)|Java|443| |70|70. Climbing Stairs.java|Easy|[DP, Memoization, Sequence DP]|||Java|444| |747|747. Largest Number At Least Twice of Others.java|Easy|[Array]|||Java|445| |315|315. Count of Smaller Numbers After Self.java|Hard|[BST, Binary Indexed Tree, Binary Search, Divide and Conquer, Segment Tree]|O(nlogn)|O(n)|Java|446| |239|239. Sliding Window Maximum.java|Hard|[Deque, Heap, Sliding Window]|O(n)|O(n)|Java|447| |47|47. Permutations II.java|Medium|[Backtracking, DFS]|||Java|448| |332|332. Reconstruct Itinerary.java|Medium|[Backtracking, DFS, Graph]|O(n^n)|O(m)|Java|449| |88|88. Search in Rotated Sorted Array II.java|Medium|[Array, Binary Search]|O(logn), worst O(n)|O(1)|Java|450| |561|561. Array Partition I.java|Easy|[Array]|O(nlogn)|O(1)|Java|451| |387|387. First Unique Character in a String.java|Easy|[Hash Table, String]|O(n)|O(256) = O(1)|Java|452| |345|345. Reverse Vowels of a String.java|Easy|[String, Two Pointers]|||Java|453| |39|39. Combination Sum.java|Medium|[Array, Backtracking, Combination, DFS]|O(k * 2^n), k = avg rst length|O(k) stack depth, if not counting result size|Java|454| |10|10. Regular Expression Matching.java|Hard|[Backtracking, DP, Double Sequence DP, Sequence DP, String]|||Java|455| |367|367. Valid Perfect Square.java|Easy|[Binary Search, Math]|O(logN)|O(1)|Java|456| |270|270. Closest Binary Search Tree Value.java|Easy|[BST, Binary Search, Tree]|O(logn)|O(1)|Java|457| |28|28. Implement strStr().java|Easy|[String, Two Pointers]|||Java|458| |1106|1106. Parsing A Boolean Expression.java|Hard|[DFS, Stack, String]|||Java|459| |144|144. Binary Tree Preorder Traversal.java|Medium|[BFS, DFS, Stack, Tree]|O(n)|O(n)|Java|460| |852|852. Peak Index in a Mountain Array.java|Easy|[Binary Search]|O(logn)|O(1)|Java|461| |146|146. LRU Cache.java|Medium|[Design, Doubly Linked List, Hash Table, Linked List]|O(1)|O(1)|Java|462| |110|110. Balanced Binary Tree.java|Easy|[DFS, Tree]|||Java|463| |1040|1040. Moving Stones Until Consecutive II.java|Medium|[Array, Sliding Window]|O(nlogn)|O(n)|Java|464| |246|246. Strobogrammatic Number.java|Easy|[Enumeration, Hash Table, Math, Two Pointers]|O(n)|O(1)|Java|465| |100|100. Same Tree.java|Easy|[BFS, DFS, Tree]|O(n)|O(logn)|Java|466| |307|307. Range Sum Query - Mutable.java|Medium|[Binary Indexed Tree, Segment Tree]|build O(n), query (logn +k), update O(logn)|O(n)|Java|467| |88|88. Merge Sorted Array.java|Easy|[Array, Two Pointers]|O(n)|O(1)|Java|468| |319|319. Bulb Switcher.java|Medium|[Brainteaser, Math]|O(1)|O(1)|Java|469| |112|112. Path Sum.java|Easy|[DFS, Tree]|||Java|470| |463|463. Island Perimeter.java|Easy|[Hash Table]|O(n)||Java|471| |170|170. Two Sum III - Data structure design.java|Easy|[Design, Hash Table, Memoization]|O(n)|O(n)|Java|472| |122|122. Best Time to Buy and Sell Stock II.java|Easy|[Array, DP, Greedy, Sequence DP, Status DP]|O(n)|O(1) greedy, O(n) dp|Java|473| |715|715. Range Module.java|Hard|[Segment Tree, TreeSet]|query O(logn), update O(n)|O(n)|Java|474| |12|12. Integer to Roman.java|Medium|[Basic Implementation, Math, String]|O(n)|O(n)|Java|475| |14|14. Longest Common Prefix.java|Easy|[String]|||Java|476| |243|243. Shortest Word Distance.java|Easy|[Array, Two Pointers]|O(n)|O(1)|Java|477| |414|414. Third Maximum Number.java|Easy|[Array, PriorityQueue]|||Java|478| |1267|1267. Count Servers that Communicate.java|Medium|[Array, Graph]|O(mn)|O(m + n)|Java|479| |20|20. Valid Parentheses.java|Easy|[Stack, String]|O(n)|O(n)|Java|480| |893|893. Groups of Special-Equivalent Strings.java|Easy|[Basic Implementation, String]|||Java|481| |427|427. Construct Quad Tree.java|Medium|[Tree]|O(n^2)|O(n^2)|Java|482| |981|981. Time Based Key-Value Store.java|Medium|[Binary Search, Hash Table, TreeMap]|set O(1), get(logn)|O(n)|Java|483| |169|169. Majority Element.java|Easy|[Array, Bit Manipulation, Divide and Conquer, Moore Voting, Sort]|O(n)|O(1)|Java|484| |234|234. Palindrome Linked List.java|Easy|[Linked List, Two Pointers]|O(n)|O(1)|Java|485| |202|202. Happy Number.java|Easy|[Hash Table, Math]|O(m), m iterations|O(m), m number in set|Java|486| |69|69. Sqrt(x).java|Easy|[Binary Search, Math]|||Java|487| |876|876. Middle of Linked List.java|Easy|[Linked List]|||Java|488| |1026|1026. Maximum Difference Between Node and Ancestor.java|Medium|[DFS, Tree]|O(n)|O(logn)|Java|489| |78|78. Subsets.java|Medium|[Array, BFS, Backtracking, Bit Manipulation, DFS]|O(2^n)|O(2^n)|Java|490| |432|432. All One Data Structure.java|Hard|[Design, Doubly Linked List]|O(1)|O(n)|Java|491| |380|380. Insert Delete GetRandom O(1).java|Medium|[Array, Design, Hash Table]|O(1) avg|O(n)|Java|492| |560|560. Subarray Sum Equals K.java|Medium|[Array, Hash Table, PreSum, Subarray]|O(n)|O(n)|Java|493| |219|219. Contains Duplicate II.java|Easy|[Array, Hash Table]|O(n)|O(n)|Java|494| |91|91. Decode Ways.java|Medium|[DP, Partition DP, String]|O(n)|O(n)|Java|495| |205|205. Isomorphic Strings.java|Easy|[Hash Table]|O(n)|O(n)|Java|496| |639|639. Decode Ways II.java|Hard|[DP, Enumeration, Partition DP]|O(n)|O(n)|Java|497| |346|346. Moving Average from Data Stream.java|Easy|[Design, Queue, Sliding Window]|O(1) for
next()
|O(size) for fixed storage|Java|498| |145|145. Binary Tree Postorder Traversal.java|Medium|[Stack, Tree, Two Stacks]|O(n)|O(n)|Java|499| |938|938. Range Sum of BST.java|Easy|[BST, Recursion, Tree]|||Java|500| |210|210. Course Schedule II.java|Medium|[BFS, DFS, Graph, Topological Sort]|O(n)|O(n)|Java|501| |68|68. Text Justification.java|Hard|[Enumeration, String]|O(n) go over words|O(maxLength) buffer list|Java|502| |314|314. Binary Tree Vertical Order Traversal.java|Medium|[BFS, DFS, Hash Table, Tree]|O(n)|O(n)|Java|503| |287|287. Find the Duplicate Number.java|Medium|[Array, Binary Search, Binary Search on Value, Cycle Detection, Slow Fast Pointer, Two Pointers]|O(n)|O(1)|Java|504| |242|242. Valid Anagram.java|Easy|[Hash Table, Sort]|O(n)|O(1), unique chars|Java|505| |340|340. Longest Substring with At Most K Distinct Characters.java|Hard|[Hash Table, LinkedHashMap, Sliding Window, String, Two Pointers]|O(n)|O(k)|Java|506| |217|217. Contains Duplicate.java|Easy|[Array, Hash Table]|O(n)|O(1)|Java|507| |103|103. Binary Tree Zigzag Level Order Traversal.java|Medium|[BFS, Stack, Tree]|O(n)|O(n)|Java|508| |1057|1057. Campus Bikes.java|Medium|[Bucket Sort, Greedy, PriorityQueue, Sort]|O(mn)|O(mn)|Java|509| |261|261. Graph Valid Tree.java|Medium|[BFS, DFS, Graph, Union Find]|||Java|510| |64|64. Minimum Path Sum.java|Medium|[Array, Coordinate DP, DP]|O(mn)|O(n) rolling array|Java|511| |796|796. Rotate String.java|Easy|[String]|||Java|512| |229|229. Majority Element II.java|Medium|[Array, Moore Voting]|O(n)|(1)|Java|513| |1041|1041. Robot Bounded In Circle.java|Easy|[String]|||Java|514| |2|2. Add Two Numbers.java|Medium|[Linked List, Math]|O(max(m,n))|O(max(m,n))|Java|515| |157|157. Read N Characters Given Read4.java|Easy|[Enumeration, String]|||Java|516| |114|114. Flatten Binary Tree to Linked List.java|Medium|[Binary Tree, DFS]|O(n)|O(n), stacks|Java|517| |121|121. Best Time to Buy and Sell Stock.java|Easy|[Array, DP, Sequence DP]|||Java|518| |1004|1004. Max Consecutive Ones III.java|Medium|[Sliding Window, Two Pointers]|O(n)|O(1)|Java|519| |1146|1146. Snapshot Array.java|Medium|[Array, Hash Table, TreeMap]|O(1) set, O(logn) get, O(x) snap, x = # of changes|O(n * m), n = array size, m = # of snaps|Java|520| |273|273. Integer to English Words.java|Hard|[Enumeration, Math, String]|O(n)|O(1)|Java|521| |304|304. Range Sum Query 2D - Immutable.java|Medium|[DP, PreSum]|O(mn) build, O(1) query|O(mn)|Java|522| |605|605. Can Place Flowers.java|Easy|[Array, Greedy]|O(n)|O(1)|Java|523| |1|1. Two Sum.java|Easy|[Array, Hash Table]|O(n)|O(n)|Java|524| |118|118. Pascal's Triangle.java|Easy|[Array, Basic Implementation, List]|O(n^2) based on pascal triangle size|O(n^2)|Java|525| |23|23. Merge k Sorted Lists.java|Medium|[Divide and Conquer, Heap, Linked List, Merge Sort, PriorityQueue]|O(nlogk)|O(logk)|Java|526| |283|283. Move Zeroes.java|Easy|[Array, Two Pointers]|O(n)|O(1)|Java|527| |208|208. Implement Trie (Prefix Tree).java|Medium|[Design, Trie]|||Java|528| |516|516. Longest Palindromic Subsequence.java|Medium|[DFS, DP, Interval DP, Memoization]|O(n^2)|O(n^2)|Java|529| |218|218. The Skyline Problem.java|Hard|[BIT, Divide and Conquer, HashHeap, Heap, PriorityQueue, Segment Tree, Sweep Line]|O(n^2logn)|O(n)|Java|530| |430|430. Flatten a Multilevel Doubly Linked List.java|Medium|[DFS, Linked List]|O(n)|O(1)|Java|531| |63|63. Unique Paths II.java|Medium|[Array, Coordinate DP, DP]|O(mn)|O(mn)|Java|532| |52|52. N-Queens II.java|Hard|[Backtracking]|O(n!)|O(n)|Java|533| |1033|1033. Moving Stones Until Consecutive.java|Easy|[Basic Implementation, Sort]|O(1), only 3 elements|O(1)|Java|534| |139|139. Word Break.java|Medium|[DP, Hash Table, Sequence DP]|O(n^2)|O(n)|Java|535| |105|105. Construct Binary Tree from Preorder and Inorder Traversal.java|Medium|[Array, DFS, Divide and Conquer, Hash Table, Tree]|O(n)|O(n)|Java|536| |125|125. Valid Palindrome.java|Easy|[String, Two Pointers]|||Java|537| |449|449. Serialize and Deserialize BST.java|Medium|[Tree]|O(n)|O(n)|Java|538| |274|274.H-Index.java|Medium|[Bucket Sort, Hash Table, Sort]|O(n)|O(n)|Java|539| |160|160. Intersection of Two Linked Lists.java|Easy|[Linked List]|||Java|540| |40|40. Combination Sum II.java|Medium|[Array, Backtracking, Combination, DFS]|O(k * 2^n), k = avg rst length|O(n) stack depth, if not counting result size|Java|541| |410|410. Split Array Largest Sum.java|N/A|[]|||Java|542| |724|724. Find Pivot Index.java|Easy|[Array, PreSum]|O(n)|O(1)|Java|543| |523|523. Continuous Subarray Sum.java|Medium|[Coordinate DP, DP, Math, PreSum, Subarray]|O(n)|O(k)|Java|544| |65|65. Valid Number.java|Hard|[Enumeration, Math, String]|O(n)|O(1)|Java|545| |350|350. Intersection of Two Arrays II.java|Easy|[Binary Search, Hash Table, Sort, Two Pointers]|(n)|(n)|Java|546| |364|364. Nested List Weight Sum II.java|Medium|[DFS, NestedInteger]|O(n), visit all nodes|O(h), depth|Java|547| |49|49. Group Anagrams.java|Medium|[Hash Table, String]|O(nk)|O(nk)|Java|548| |720|720. Longest Word in Dictionary.java|Easy|[Hash Table, Trie]|O(nlogn)|O(n)|Java|549| |438|438. Find All Anagrams in a String.java|Medium|[Hash Table, Sliding Window, Two Pointers]|O(n)|O(1)|Java|550| |632|632. Smallest Range Covering Elements from K Lists.java|Hard|[Hash Table, Sliding Window, Two Pointers]|O(nlogn), n = total elements|O(n) to store sorted list|Java|551| |138|138. Copy List with Random Pointer.java|Medium|[Hash Table, Linked List]|O(n)|O(n)|Java|552| |159|159. Longest Substring with At Most Two Distinct Characters.java|Medium|[Hash Table, Sliding Window, String, Two Pointers]|O(n)|O(1)|Java|553| |1043|1043. Partition Array for Maximum Sum.java|Medium|[DFS, DP, Graph, Memoization]|O(n), calc memo[n]|O(n)|Java|554| |33|33. Search in Rotated Sorted Array.java|Medium|[Array, Binary Search]|O(logn)|O(1)|Java|555| |760|760. Find Anagram Mappings.java|Easy|[Hash Table]|O(n)|O(n)|Java|556| |133|133. Clone Graph.java|Medium|[BFS, DFS, Graph]|O(n)|O(n)|Java|557| |743|743. Network Delay Time.java|Medium|[BFS, DFS, Graph, Heap, PQ]|O(nlogn)|O(n)|Java|558| |636|636. Exclusive Time of Functions.java|Medium|[Stack]|O(n)|O(n)|Java|559| |692|692. Top K Frequent Words.java|Medium|[Hash Table, Heap, MaxHeap, MinHeap, PriorityQueue, Trie]|O(n)|O(n)|Java|560| |1170|1170. Compare Strings by Frequency of the Smallest Character.java|Easy|[Array, String]|O(m + n)|O(m + n)|Java|561| |426|426. Convert Binary Search Tree to Sorted Doubly Linked List.java|Medium|[BST, DFS, Divide and Conquer, Linked List, Tree]|O(n)|O(1)|Java|562| |745|745. Prefix and Suffix Search.java|Hard|[Trie]|O(N + Q)|O(N)|Java|563| |8|8. String to Integer (atoi).java|Medium|[Math, String]|O(n)|O(n)|Java|564| |361|361. Bomb Enemy.java|Medium|[Coordinate DP, DP]|O(mn)|O(n) by calculating column sum|Java|565| |94|94. Binary Tree Inorder Traversal.java|Easy|[Hash Table, Stack, Tree]|O(n)|O(logn)|Java|566| |402|402. Remove K Digits.java|Medium|[Greedy, Monotonous Stack, Stack]|O(n)|O(n)|Java|567| |98|98. Validate Binary Search Tree.java|Medium|[BST, DFS, Divide and Conquer, Tree]|O(n)|O(logn)|Java|568| |1123|1123. Lowest Common Ancestor of Deepest Leaves.java|Medium|[BFS, DFS, Tree]|O(n)|O(n)|Java|569| |921|921. Minimum Add to Make Parentheses Valid.java|Medium|[]|O(n)|O(1)|Java|570| |399|399. Evaluate Division.java|Medium|[BFS, DFS, Graph, Union Find]|||Java|571| |785|785. Is Graph Bipartite.java|Medium|[BFS, DFS, Garph]|O(n)|O(n)|Java|572| |767|767. Reorganize String.java|Medium|[Greedy, Hash Table, Heap, Sort, String]|O(m), m = # of unique letters|O(nLogm), n = length|Java|573| |71|71. Simplify Path.java|Medium|[Stack, String]|O(n)|O(n)|Java|574| |34|34. Find First and Last Position of Element in Sorted Array.java|Medium|[Array, Binary Search]|O(logn)|O(1)|Java|575| |278|278. First Bad Version.java|Easy|[Binary Search]|O(logN)|O(1)|Java|576| |124|124. Binary Tree Maximum Path Sum.java|Hard|[DFS, DP, Tree, Tree DP]|O(n)|O(logn)|Java|577| |721|721. Accounts Merge.java|Medium|[DFS, Hash Table, Union Find]|||Java|578| |689|689. Maximum Sum of 3 Non-Overlapping Subarrays.java|Hard|[Array, DP]|O(n)|O(n)|Java|579| |101|101. Symmetric Tree.java|Easy|[BFS, DFS, Tree]|O(n)|O(n)|Java|580| |149|149. Max Points on a Line.java|Hard|[Array, Geometry, Hash Table, Math]|O(n^2)|O()|Java|581| |698|698. Partition to K Equal Sum Subsets.java|Medium|[DFS, DP, Recursion]|O(k^(n-k) * k!)|O(n)|Java|582| |57|57. Insert Interval.java|Hard|[Array, PriorityQueue, Sort, Sweep Line]|O(n)|O(n)|Java|583| |13|13. Roman to Integer.java|Easy|[Math, String]|O(n)|O(1)|Java|584| |716|716. Max Stack.java|Medium|[Design, Doubly Linked List, Stack, TreeMap]|avg O(1), [O(logN) peekMax(), TreeMap]; [O(n) popMax(), TwoStack]|O(n)|Java|585| |671|671. Second Minimum Node In a Binary Tree.java|Easy|[BFS, Tree]|O(n)|O(n) leaf nodes|Java|586| |366|366. Find Leaves of Binary Tree.java|Medium|[DFS, Tree]|O(n)|O(h)|Java|587| |235|235. Lowest Common Ancestor of a Binary Search Tree.java|Easy|[BST, DFS, Tree]|O(logn)|O(logn)|Java|588| |156|156. Binary Tree Upside Down.java|Medium|[DFS, Tree]|O(n)|O(h)|Java|589| |416|416. Partition Equal Subset Sum.java|Medium|[Backpack, DP]|||Java|590| |611|611. Valid Triangle Number.java|Medium|[Array, Two Pointers]|O(n^2)|O(logn), sorting space|Java|591| |341|341. Flatten Nested List Iterator.java|Medium|[Design, NestedInteger, Stack]|O(n)|O(n)|Java|592| |254|254. Factor Combinations.java|Medium|[BFS, Backtracking, DFS]|O(x), x is the # of results|O(y), y is all ongoing candidates in queue|Java|593| |739|739. Daily Temperatures.java|Medium|[Hash Table, Monotonous Stack, Stack]|O(n)|O(n)|Java|594| |373|373. Find K Pairs with Smallest Sums.java|Medium|[Heap, MaxHeap, MinHeap]|O(klogk)|O(k)|Java|595| |256|256. Paint House.java|Easy|[DP, Sequence DP, Status DP]|O(nm), m = # of colors|O(nm), or O(1) with rolling array|Java|596| |265|265. Paint House II.java|Hard|[DP, Sequence DP, Status DP]|O(NK^2):|O(K) with rolling array|Java|597| |272|272. Closest Binary Search Tree Value II.java|Hard|[Stack, Tree]|O(n)|O(n)|Java|598| |72|72. Edit Distance.java|Hard|[DP, Double Sequence DP, Sequence DP, String]|O(MN)||Java|599| |215|215. Kth Largest Element in an Array.java|Medium|[Divide and Conquer, Heap, MinHeap, PriorityQueue, Quick Select, Quick Sort]|O(nlogk)|O(k)|Java|600|

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.