Skip to content

lydxlx1/LeetCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode

Below is a summary of my solutions to the problems on LeetCode. The main idea of each problem can usually be found at the beginning of the corresponding source file. I will keep updating the list and feel free to share any of your thoughts!

# Title Solutions
2565 Subsequence With the Minimum Score [ Greedy + DP ]
2564 Substring XOR Queries [ Hashmap ]
2563 Count the Number of Fair Pairs [ TreeSet + 2-sum ]
2562 Find the Array Concatenation Value [ Simulation ]
2561 Rearranging Fruits [ Greedy ]
2560 House Robber IV [ Bisect ]
2559 Count Vowel Strings in Ranges [ Prefix-Sum ]
2558 Take Gifts From the Richest Pile [ Simulation ]
2556 Disconnect Path in a Binary Matrix by at Most One Flip [ DP ]
2555 Maximize Win From Two Segments [ Sliding-window ]
2554 Maximum Number of Integers to Choose From a Range I [ Simulation ]
2553 Separate the Digits in an Array [ 1-Liner ]
2552 Count Increasing Quadruplets [ Counting + BIT ]
2551 Put Marbles in Bags [ Sorting ]
2550 Count Collisions of Monkeys on a Polygon [ Quick Power ]
2549 Count Distinct Numbers on Board [ Simulation | 1-Liner Math]
2547 Minimum Cost to Split an Array [ 2D-DP ]
2546 Apply Bitwise Operations to Make Strings Equal [ Solution ]
2545 Sort the Students by Their Kth Score [ 1-Liner ]
2544 Alternating Digit Sum [ Solution ]
2543 Check if Point Is Reachable [ Number Theory ]
2542 Maximum Subsequence Score [ Sorting + PriorityQueue ]
2540 Minimum Common Value [ Solution ]
2537 Count the Number of Good Subarrays [ Sliding-window ]
2536 Increment Submatrices by One [ 2D Prefix Sum ]
2535 Difference Between Element Sum and Digit Sum of an Array [ Solution ]
Maximum Performance of a Team [ Sorting + Heap ]
Balance a Binary Search Tree [ In-order Traversal + Divide-and-Conquer ]
Design a Stack With Increment Operation [ Lazy Increment ]
Lucky Numbers in a Matrix [ Solution ]
Minimum Cost to Make at Least One Valid Path in a Grid [ SSSP ]
Linked List in Binary Tree [ DFS ]
Rank Teams by Votes [ Radix Sort ]
How Many Numbers Are Smaller Than the Current Number [ Counting Sort ]
Largest Multiple of Three [ Math ]
Closest Divisors [ Enumeration ]
Validate Binary Tree Nodes [ DFS ]
Number of Days Between Two Dates [ Datetime ]
Construct Target Array With Multiple Sums [ Backtracking ]
Maximum Number of Events That Can Be Attended [ Greedy + Heap/BST ]
Product of the Last K Numbers [ Compact Array ]
Count Negative Numbers in a Sorted Matrix [ Young Tableau ]
Path with Maximum Gold [ Backtracking ]
Count Vowels Permutation [ Counting ]
Longest Arithmetic Subsequence of Given Difference [ DP ]
Play with Chips [ Math ]
Minimum Moves to Reach Target with Rotations [ BFS ]
Remove All Adjacent Duplicates in String II [ Stack ]
Get Equal Substrings Within Budget [ Sliding Window ]
Unique Number of Occurrences [ Solution ]
Smallest String With Swaps [ Union-Find Set + Sorting ]
Ugly Number III [ Bisection + Inclusion-Exclusion ]
Minimum Absolute Difference [ Solution ]
Sort Items by Groups Respecting Dependencies [ Topological Sort ]
Critical Connections in a Network [ Find All Bridges via DFS ]
K-Concatenation Maximum Sum [ DP + Prefix Sum ]
Reverse Substrings Between Each Pair of Parentheses [ Stack ]
Maximum Number of Balloons [ Solution ]
Make Array Strictly Increasing [ DP ]
Maximum Subarray Sum with One Deletion [ DP ]
Day of the Week [ Solution ]
Distance Between Bus Stops [ Solution ]
Prime Arrangements [ Math ]
Diet Plan Performance [ Sliding Window ]
Can Make Palindrome from Substring [ Greedy ]
Number of Valid Words for Each Puzzle [ Bit Manipulation ]
Invalid Transactions [ Brute-force ]
Compare Strings by Frequency of the Smallest Character [ Binary Search ]
Remove Zero Sum Consecutive Nodes from Linked List [ Prefix Sum ]
Dinner Plate Stacks [ Stack + TreeSet ]
Find Words That Can Be Formed by Characters [ Solution ]
Maximum Level Sum of a Binary Tree [ DFS ]
As Far from Land as Possible [ BFS ]
Last Substring in Lexicographical Order [ Suffix Array ]
Online Majority Element In Subarray [ Randomization + Bisect ]
Swap For Longest Repeated Character Substring [ Greedy ]
Number of Dice Rolls With Target Sum [ Counting ]
Day of the Year [ Math ]
Longest Chunked Palindrome Decomposition [ DP ]
Snapshot Array [ Binary Search ]
Binary Tree Coloring Game [ Solution ]
Decrease Elements To Make Array Zigzag [ Greedy ]
Stone Game II [ Game Theory + DP ]
Largest 1-Bordered Square [ Counting ]
Alphabet Board Path [ Solution ]
N-th Tribonacci Number [ Math ]
Minimum Cost Tree From Leaf Values [ DP ]
Shortest Path with Alternating Colors [ SSSP ]
Number of Equivalent Domino Pairs [ Counting ]
Maximum of Absolute Value Expression [ Math ]
Smallest Sufficient Team [ DP ]
Longest Well-Performing Interval [ BIT ]
Lowest Common Ancestor of Deepest Leaves [ Tree-DP ]
Relative Sort Array [ Sorting ]
Parsing A Boolean Expression [ DFS ]
Filling Bookcase Shelves [ DP ]
Path In Zigzag Labelled Binary Tree [ Math ]
Distribute Candies to People [ Solution ]
Brace Expansion II [ Stack ]
Find in Mountain Array [ Binary Search ]
Car Pooling [ Sweep-line Algorithm ]
Statistics from a Large Sample [ Solution ]
Shortest Common Supersequence [ DP + Backtracking ]
Shortest Path in Binary Matrix [ BFS ]
Largest Values From Labels [ Greedy ]
Duplicate Zeros [ In-place Solution ]
Smallest Subsequence of Distinct Characters [ Greedy + Stack ]
Letter Tile Possibilities [ Solution ]
Occurrences After Bigram [ Solution ]
1074 Number of Submatrices That Sum to Target [ Solution ]
1073 Adding Two Negabinary Numbers [ Solution ]
1072 Flip Columns For Maximum Number of Equal Rows [ Bitmask ]
1071 Greatest Common Divisor of Strings [ Solution ]
1066 Campus Bikes II [ Optimal Bipartite Graph Matching ]
1065 Index Pairs of a String [ Trie ]
1064 Fixed Point [ Solution ]
1054 Distant Barcodes [ Distant Barcodes ]
1053 Previous Permutation With One Swap [ Math ]
1052 Grumpy Bookstore Owner [ Sliding Window ]
1051 Height Checker [ Sorting ]
1049 Last Stone Weight II [ DP ]
1048 Longest String Chain [ DP ]
1047 Remove All Adjacent Duplicates In String [ Brute-force ]
1046 Last Stone Weight [ Heap ]
1044 Longest Duplicate Substring [ Bisection + Sliding Window + Rolling Hash ]
1043 Partition Array for Maximum Sum [ DP ]
1042 Flower Planting With No Adjacent [ Pigeonhole Principle ]
1041 Robot Bounded In Circle [ Solution ]
1040 Moving Stones Until Consecutive II [ Math ]
1039 Minimum Score Triangulation of Polygon [ DP ]
1038 Binary Search Tree to Greater Sum Tree [ In-order Traversal ]
1037 Valid Boomerang [ Cross Produce ]
1036 Escape a Large Maze [ DFS ]
1035 Uncrossed Lines [ DP ]
1034 Coloring a Border [ DFS ]
1033 Moving Stones Until Consecutive [ Math ]
1032 Stream of Characters [ Trie ]
1031 Maximum Sum of Two Non-Overlapping Subarrays [ Brute-force ]
1030 Matrix Cells in Distance Order [ BFS ]
1029 Two City Scheduling [ DP ]
1028 Recover a Tree From Preorder Traversal [ Stack ]
1027 Longest Arithmetic Sequence [ DP ]
1026 Maximum Difference Between Node and Ancestor [ DFS ]
1025 Divisor Game [ Game Theory ]
1024 Video Stitching [ DP ]
1023 Camelcase Matching [ Brute-force ]
1022 Sum of Root To Leaf Binary Numbers [ DFS ]
1021 Best Sightseeing Pair [ Greedy ]
1020 Number of Enclaves [ DFS ]
1019 Next Greater Node In Linked List [ Greedy + TreeMap ]
1018 Binary Prefix Divisible By 5 [ Math ]
1017 Convert to Base -2 [ Math ]
1016 Binary String With Substrings Representing 1 To N [ Brute-force ]
1015 Smallest Integer Divisible by K [ Math ]
1014 Capacity To Ship Packages Within D Days [ Bisect ]
1013 Partition Array Into Three Parts With Equal Sum [ Brute-force ]
1012 Numbers With Repeated Digits [ Backtracking | Digit+Mask DP]
1010 Pairs of Songs With Total Durations Divisible by 60 [ Counting ]
1009 Complement of Base 10 Integer [ Bit Manipulation ]
1008 Construct Binary Search Tree from Preorder Traversal [ DFS ]
1007 Minimum Domino Rotations For Equal Row [ Brute-force ]
1006 Clumsy Factorial [ Stack ]
1005 Maximize Sum of Array After K Negations [ Greedy ]
1004 Max Consecutive Ones III [ Sliding Window ]
1003 Check If Word Is Valid After Substitutions [ Greedy | Java Solution ]
1002 Find Common Characters [ Counter | Java Solution ]
1001 Grid Illumination [ 8-queen ]
1000 Minimum Cost to Merge Stones [ DP ]
999 Available Captures for Rook [ Solution ]
998 Maximum Binary Tree II [ DFS ]
997 Find the Town Judge [ Universal Sink ]
996 Number Squareful Arrays [ Hamiltonian Path ]
995 Minimum Number of K Consecutive Bit Flips [ Greedy ]
994 Rotting Oranges [ BFS ]
993 Cousins in Binary Tree [ DFS ]
992 Subarrays with K Different Integers [ Two Sliding-windows ]
991 Broken Calculator [ Math ]
990 Satisfiability of equality equations [ Union-Find Set ]
989 Add to Array-Form of Integer [ Arithmetic Addition ]
988 Smallest String Starting from Leaf [ Solution ]
987 Vertical Order Traversal of a Binary Tree [ DFS + Stream ]
986 Interval List Intersections [ Linear-time Solution ]
985 Sum of Even Numbers After Queries [ Solution ]
984 String without AAA or BBB [ Greedy ]
983 Minimum Cost for Tickets [ DP ]
982 Triples with Bitwise AND Equal to Zero [ DP + Lazy Evaluation ]
981 Time Based Key-Value Store [ HashMap + TreeMap ]
980 Unique Paths III [ DP + Bit-compression ]
979 Distribute Coins in Binary Tree [ Bottom-up Solution | Top-down Solution ]
978 Longest Turbulent Subarray [ Solution ]
977 Squares of a Sorted Array [ 1-Liner | O(n)-time Solution ]
976 Largest Perimeter Triangle [ Greedy ]
975 Odd Even Jump [ DP ]
974 Subarray Sums Divisible by K [ Prefix-sum ]
973 K Closest Points to Origin [ 1-Liner ]
968 Binary Tree Cameras [ Tree-DP | Greedy ]
967 Numbers with Same Consecutive Differences [ Backtracking ]
966 Vowel Spellchecker [ Mapper ]
965 Univalued Binary Tree [ DFS ]
964 Least Operators to Express Number [ Math ]
963 Minimum Area Rectangle II [ Geometry ]
962 Maximum Width Ramp [ Sweepline + BIT | Divide-and-Conquer | Just Sort ]
961 N-Repeated-Element in Size 2N Array [ Partition ]
960 Delete Columns to Make Sorted III [ DP ]
959 Regions Cut By Slashes [ Union-find-set | Anti-aliasing ]
958 Check the Completeness of a Binary Tree [ BFS ]
957 Prison Cells After N Days [ Math ]
956 Tallest Billboard [ DP ]
955 Delete Columns to Make Sorted II [ Solution with Strong Prunings | Short Solution ]
954 Array of Doubled Pairs [ Greedy ]
953 Verifying an Alien Dictionary [ Solution ]
952 Largest Component Size by Common Factor [ Math + Union-find Set ]
951 Flip Equivalent Binary Trees [ DFS ]
950 Reveal Cards in Increasing Order [ Simulation ]
949 Largest Time for Given Digits [ Brute-force ]
948 Bag of Tokens [ Greedy ]
947 Most Stones Removed with Same Row or Column [ Union-Find Set ]
946 Validate Stack Sequences [ Stack ]
945 Minimum Increment to Make Array Unique [ Counting ]
944 Delete Columns to Make Sorted [ Solution ]
943 Find the Shortest Superstring [ DP ]
942 DI String Match [ Construction ]
941 Valid Mountain Array [ Two-pointer ]
940 Distinct Subsequences II [ DP ]
939 Minimum Area Rectangle [ Solution ]
938 Range Sum of BST [ DFS ]
937 Reorder Log Files [ Sorting ]
936 Stamping the Sequence [ Thinking Reversely ]
935 Knight Dialer [ DP ]
934 Shortest Bridge [ DFS + BFS ]
933 Number of Recent Calls [ Monotone Queue ]
924 Minimize Malware Spread [ DFS ]
923 3Sum with Multiplicity [ Counting | Two-pointer ]
922 Sort Array by Parity II [ Solution]
921 Minimum Add to Make Parentheses Valid [ Solution]
920 Number of Music Playlists [ DP]
919 Complete Binary Tree Inserter [ Solution]
918 Maximum Sum Circular Subarray [ Divide-and-Conquer | Sliding-Window + TreeMap | Sliding-Window + Monotonic-Queue ]
917 Reverse Only Letters [ Two-Pointer ]
916 Word Subsets [ Counting ]
915 Partition Array into Disjoint Intervals [ Solution ]
914 X of a Kind in a Deck of Cards [ Math ]
913 Cat and Mouse [ Game Theory ]
911 Online Election [ Binary Search ]
910 Smallest Range II [ Math ]
909 Snakes and Ladders [ BFS ]
908 Smallest Range I [ Greedy ]
907 Sum of Subarray Minimums [ Divide-and-Conquer | Stack ]
906 Super Palindromes [ Solution ]
905 Sort Array By Parity [ 1-Liner ]
904 Fruit Into Baskets [ Sliding-window ]
903 Valid Permutations for DI Sequence [ DP ]
902 Numbers At Most N Given Digit Set [ Math ]
901 Online Stock Span [ Monotone-Stack ]
900 RLE Iterator [ Solution ]
899 Orderly Queue [ Math ]
898 Bitwise ORs of Subarrays [ Divide-and-Conquer | Another Solution ]
897 Increasing Order Search Tree [ In-order Traversal ]
896 Monotonic Array [ 1-Liner ]
891 Sum of Subsequences Widths [ Math ]
890 Find and Replace Pattern [ Greedy ]
889 Construct Binary Tree from Preorder and Postorder Traversal [ DP | Easy Solution ]
888 Fair Candy Swap [ Solution ]
887 Super Egg Drop [ DP with Binary Search Optimization ]
886 Possible Bipartition [ DFS ]
885 Spiral Matrix III [ Solution ]
884 Uncommon Words from Two Sentences [ Solution ]
883 Projection Area of 3D Shapes [ Solution ]
882 Reachable Nodes in Subdivided Graph [ Shortest Path + Greedy ]
881 Boats to Save People [ Greedy ]
880 Decoded String at Index [ DP ]
879 Profitable Schemes [ DP ]
878 Nth Magical Number [ Binary Search ]
877 Stone Game [ DP ]
876 Middle of the Linked List [ Fast-and-slow Pointers ]
875 Koko Eating Bananas [ Binary Search ]
874 Walking Robot Simulation [ Solution ]
873 Length of Longest Fibonacci Subsequence [ DP ]
872 Leaf-Similar Trees [ DFS ]
871 Minimum Number of Refueling Stops [ Greedy ]
870 Advantage Shuffle [ Greedy + Merge-sort ]
869 Reordered Power of 2 [ Solution ]
868 Binary Gap [ Solution ]
867 Transpose Matrix [ Solution ]
866 Prime Palindrome [ Fast Primality Test ]
865 Smallest Subtree with All the Deepest Nodes [ Tree-DP ]
864 Shortest Path to Get All Keys [ SPFA ]
863 All Nodes Distance K in Binary Tree [ DFS ]
862 Shortest Subarray with Sum at Least K [ Augmented-BST ]
861 Score After Flipping Matrix [ Greedy+Math ]
860 Lemonade Change [ Greedy ]
859 Buddy Strings [ Solution ]
856 Score of Parentheses [ Divide-and-conquer ]
855 Exam Room [ TreeSet + PriorityQueue ]
853 Car Fleet [ Math ]
852 Peak Index in a Mountain Array [ Binary Search ]
851 Loud and Rich [ DAG ]
850 Rectangle Area II [ Rectangle Cutting | Index Compressing ]
849 Maximize Distance to Closest Person [ Solution ]
848 Shifting Letters [ Suffix-sum ]
847 Shortest Path Visiting All Nodes [ Hamiltonian-path ]
846 Hand of Straights [ Solution ]
845 Longest Mountain in Array [ Solution ]
844 Backspace String Compare [ Solution ]
843 Guess the Word [ Min-max Greedy ]
842 Split Array into Fibonacci Sequence [ Brute-force ]
841 Keys and Rooms [ DFS ]
840 Magic Squares in Grid [ Solution ]
838 Push Dominoes [ Solution ]
837 Sliding Window [ DP + Sliding Window ]
836 Rectangle Overlap [ Solution ]
835 Image Overlap [ Math ]
834 Sum of Distances in Tree [ Tree DP ]
833 Find and replace in String [ Solution ]
832 Flipping an Image [ Solution ]
831 Masking Personal Information [ Solution ]
830 Positions of Large Groups [ Solution ]
829 Consecutive Numbers Sum [ Math ]
828 Unique Number String [ Counting ]
827 Making a Large Island [ Union-Find Set ]
826 Most Profit Assigning Work [ Greedy | BIT ]
825 Friends of Appropriate Ages [ Solution ]
824 Goat Latin [ Solution ]
823 Binary Trees with Factors [ DP + Two-pointers ]
822 Card Flipping Game [ Solution ]
821 Shortest Distance to a Character [ Brute-force | Linear-time Solution ]
820 Short Encoding of Words [ Greedy ]
815 Bus Routes [ BFS ]
814 Binary Tree Pruning [ DFS ]
813 Largest Sum of Averages [ DP ]
812 Largest Triangle Area [ Brute-force ]
811 Subdomain Visit Count [ HashMap ]
810 Chalkboard XOR game [ Game Theory ]
809 Expressive Words [ Solution ]
808 Soup Servings [ DP + Math ]
807 Max Increase to Keep City Skyline [ Solution ]
806 Number of Lines To Write String [ Solution ]
805 Split Array with Same Average [ Pruning + DP | Pruning + DFS ]
804 Unique Morse Code Words [ Solution ]
799 Champagne Tower [ Solution ]
798 Smallest Rotation with Highest Score [ Sliding Window ]
797 All Paths from Source to Target [ Backtracking ]
796 Rotate String [ Solution ]
795 Number of Subarrays with Bounded Maximum [ Divide-and-Conquer | O(n)-time Solution ]
794 Valid Tic-Tac-Toe State [ Solution ]
793 Preimage Size of Factorial Zeroes Function [ Binary Search + Math ]
792 Number of Matching Subsequences [ Linear-time Solution ]
791 Custom Sort String [ Quick-sort | Counting-sort ]
790 Domino and Tromino Tiling [ DP ]
789 Escape the Ghosts [ Math ]
788 Rotated Digits [ Solution ]
787 Cheapest Flights Within K Stops [ DP ]
786 K-th Smallest Prime Fraction [ Partition | Young Tableau ]
785 Is Graph Bipartite? [ DFS ]
784 Letter Case Permutation [ Solution ]
783 Minimum Distance Between BST Nodes [ In-order Traversal ]
781 Rabbits in Forest [ Math ]
780 Reaching Points [ Math ]
779 K-th Symbol in Grammar [ Recursion ]
778 Swim in Rising Water [ Binary Search + DFS | Dijkstra ]
777 Swap Adjacent in LR String [ Greedy ]
776 Split BST [ Recursion ]
775 Global and Local Inversions [ BIT ]
774 Minimize Max Distance to Gas Station [ Binary Search ]
773 Sliding Puzzle [ BFS ]
771 Jewels and Stones [ Solution ]
769 Max Chunks To Make Sorted [ Greedy ]
768 Max Chunks To Make Sorted II [ Greedy | HashMap ]
767 Reorganize String [ Greedy ]
766 Toeplitz Matrix [ Solution ]
761 Special Binary String [ Greedy + Stack ]
760 Find Anagram Mappings [ Solution ]
759 Employee Free Time [ Segment Tree ]
758 Bold Words in String [ Greedy ]
757 Set Intersection Size At Least Two [ Sweepline + Greedy ]
756 Pyramid Transition Matrix [ DP ]
755 Pour Water [ Solution ]
754 Reach a Number [ Math ]
753 Cracking the Safe [ Eulerian Circuit ]
752 Open the Lock [ BFS ]
751 IP to CIDR [ Greedy + Bit Manipulation ]
750 Number of Corner Rectangles [ Solution ]
749 Contain Virus [ DFS ]
748 Shortest Completing Word [ Solution ]
747 Largest Number Greater Than Twice of Others [ Solution ]
746 Min Cost Climbing Stairs [ DP ]
745 Prefix and Suffix Search [ Solution1 | Solution2 ]
744 Find Smallest Letter Greater Than Target [ Solution ]
743 Network Delay Time [ Floyd | SPFA ]
742 Closest Leaf in a Binary Tree [ DFS ]
741 Cherry Pickup [ DP ]
740 Delete and Earn [ DP ]
739 Daily Temperatures [ Stack ]
738 Monotone Increasing Digits [ Greedy ]
737 Sentence Similarity II [ Union-find Set ]
736 Parse Lisp Expression [ Parser ]
735 Asteroid Collision [ Stack ]
734 Sentence Similarity [ Solution ]
733 Flood Fill [ DFS ]
731 My Calendar II [ Sweepline | Segment Tree ]
730 Count Different Palindromic Subsequences [ DP ]
729 My Calendar I [ Sweepline | Segment Tree ]
728 Self Dividing Numbers [ Solution ]
727 Minimum Window Subsequence [ DP ]
726 Number of Atoms [ LL-Parser | Python Solution | Non-recursive Solution ]
725 Split Linked List in Parts [ Greedy ]
724 Find Pivot Index [ Prefix-Sum ]
723 Candy Crush [ Solution ]
722 Remove Comments [ Solution ]
721 Accounts Merge [ Disjoint Set + Hashset ]
720 Longest Word in Dictionary [ Sorting + DP ]
719 Find K-th Smallest Pair Distance [ Binary Search + Sliding Window ]
718 Maximum Length of Repeated Subarray [ DP | Binary Search + Rolling Hash ]
717 1-bit and 2-bit Characters [ Solution ]
715 Range Module [ O(n log q)-time Solution via Dynamic Segment Tree ]
714 Best Time to Buy and Sell Stock with Transaction Fee [ O(n)-time DP ]
713 Subarray Product Less Than K [ O(n)-time sliding window ]
712 Minimum ASCII Delete Sum for Two Strings [ DP ]
699 Falling Squares [ Simple O(n^2)-time Solution | O(n log n)-time Solution via Segment Tree ]
698 Partition to K Equal Sum Subsets [ Bit-DP ]
697 Degree of an Array [ HashMap ]
696 Count Binary Substrings [ DP | Linear Scan ]
695 Max Area of Island [ DFS ]
694 Number of Distinct Islands [ DFS + Sorting + Hashing ]
693 Binary Number with Alternating Bits [ Solution ]
693 Stickers to Spell Word [ DP + Optimization ]
689 Maximum Sum of 3 Non-overlapping Subarrays [ DP + Solution Finding ]
688 Knight Probability in Chessboard [ DP ]
687 Longest Univalue Path [ Tree-DP ]
686 Repeated String Match [ Brute-force | KMP ]
685 Redundant Connection II [ DFS ]
683 K Empty Slots [ BST ]
682 Baseball Game [ Implementation ]
681 Next Closest Time [ Brute-force ]
680 Valid Palindrome II [ Greedy ]
679 24 Game [ Backtracking ]
678 Valid Parenthesis String [ DP ]
677 Map Sum Pairs [ Trie ]
676 Implement Magic Dictionary [ Brute-force | Trie + Fuzzy Search ]
675 Cut Off Trees for Golf Event [ BFS ]
674 Longest Continuous Increasing Subsequence [ O(n)-time Solution ]
673 Number of Longest Increasing Subsequence [ O(n^2)-time DP | O(n log n)-time DP via Treap ]
672 Bulb Switcher II [ Brute-force + Math ]
671 Second Minimum Node in a Binary Tree [ DFS ]
670 Maximum Swap [ Brute-force ]
669 Trim a Binary Search Tree [ DFS ]
668 Kth Smallest Number in Multiplication Table [ Binary Search ]
667 Beautiful Arrangement II [ Constructive Approach ]
666 Path Sum IV [ DFS ]
665 Non-decreasing Array [ Greedy ]
664 Strange Printer [ DP ]
663 Equal Tree Partition [ DFS ]
662 Maximum Width of Binary Tree [ DFS "Solution" | BFS Solution ]
661 Image Smoother [ Solution ]
660 Remove 9 [ Base-9 ]
656 Coin Path [ DP + Printing Solution ]
655 Print Binary Tree [ DFS + Math ]
654 Maximum Binary Tree [ DFS ]
653 Two Sum IV - Input is a BST [ Solution ]
652 Find Duplicate Subtrees [ Tree-DP | Tree Encoding ]
651 4 Keys Keyboard [ DP ]
650 2 Keys Keyboard [ O(n log n)-time DP ]
649 Dota2 Senate [ Greedy + Queue ]
648 Replace Words [ Trie ]
647 Palindromic Substrings [ DP ]
646 Maximum Length of Pair Chain [ Sweepline ]
645 Set Mismatch [ Counting Sort ]
644 Maximum Average Subarray II [ Binary Search + Sliding Window ]
643 Maximum Average Subarray I [ Sliding Window ]
642 Design Search Autocomplete System [ Brute-force | Trie ]
640 Solve the Equation [ Parser ]
639 Decode Ways II [ Counting ]
638 Shopping Offers [ DP | Search + Pruning ]
637 Average of Levels in Binary Tree [ DFS ]
636 Exclusive Time of Functions [ Stack ]
635 Design Log Storage System [ Brute-force + Lexicographical Order ]
634 Find the Derangement of an Array [ Combinatorics ]
633 Sum of Square Numbers [ Solution | Another Solution ]
632 Smallest Range [ Greedy + BST ]
631 Design Excel Sum Formula [ DAG + Implementation ]
630 Course Schedule III [ Sweep Line + Greedy ]
629 K Inverse Pairs Array [ Counting ]
628 Maximum Product of Three Numbers [ Math ]
625 Minimum Factorization [ Greedy | DP ]
624 Maximum Distance in Arrays [ Solution ]
623 Add One Row to Tree [ DFS ]
621 Task Scheduler [ Simulation + Greedy ]
617 Merge Two Binary Trees [ DFS ]
616 Add Bold Tag in String [ O(1000^2)-time Solution ]
611 Valid Triangle Number [ Three-sum ]
609 Find Duplicate File in System [ Solution ]
606 Construct String from Binary Tree [ DFS ]
605 Can Place Flowers [ Greedy ]
604 Design Compressed String Iterator [ Lazy Solution ]
600 Non-negative Integers without Consecutive Ones [ Counting | Digit-DP ]
599 Minimum Index Sum of Two Lists [ Brute-force ]
598 Range Addition II [ Solution ]
594 Longest Harmonious Subsequence [ Brute-force ]
593 Valid Square [ Elegant Solution ]
592 Fraction Addition and Subtraction [ Solution ]
591 Tag Validator [ Recursive Solution ]
588 Design In-memory File System [ Trie ]
583 Delete Operation for Two Strings [ LCS ]
582 Kill Process [ Tree Traversal | Union-find-set-like Solution ]
581 Shortest Unsorted Continuous Subarray [ Sorting ]
576 Out of Boundary Paths [ DP ]
575 Distribute Candies [ Greedy ]
573 Squirrel Simulation [ Greedy ]
572 Subtree of Another Tree [ O(n^2)-time Brute-force | O(n)-time Solution | Tree Encoding ]
568 Maximum Vacation Days [ DP ]
567 Permutation in String [ Sliding-window ]
566 Reshape the Matrix [ Brute-force ]
565 Array Nesting [ Solution ]
564 Find the Closest Palindrome [ Greedy ]
563 Binary Tree Tilt [ DFS ]
562 Longest Line of Consecutive One in Matrix [ Brute-force ]
561 Array Partition I [ Greedy ]
560 Subarray Sum Equals K [ Prefix-sum ]
555 Split Assembled Strings [ Brute-force ]
553 Optimal Division [ Greedy ]
552 Student Attendance Record II [ Counting | More Elegant Solution | O(log n)-time Solution | O(log n)-time Solution with Shorter Code ]
551 Student Attendance Record I [ 1-Liner ]
546 Remove Boxes [ O(n^4)-time DP ]
545 Boundary of Binary Tree [ (Careful) Tree Traversal ]
544 Output Contest Matches [ Brute-force | O(n)-time Solution ]
543 Diameter of Binary Tree [ DP ]
542 01 Matrix [ BFS ]
541 Reverse String II [ Brute-force ]
540 Single Element in a Sorted Array [ Binary Search ]
539 Minimum Time Difference [ Sorting ]
538 Convert BST to Greater Tree [ Right-root-left-traversal ]
537 Complex Number Multiplication [ Brute-force ]
536 Construct Binary Tree from String [ LL(1)-parser ]
533 Lonely Pixel II [ Solution ]
532 K-diff Pairs in an Array [ O(n)-time Solution | Two-pointer ]
531 Lonely Pixel I [ Brute-force ]
530 Minimum Absolute Difference in BST [ DFS ]
529 Minesweeper [ DFS ]
527 Word Abbreviation [ Brute-force ]
526 Beautiful Arrangement [ Permutation ]
525 Contiguous Array [ Prefix Sum | Divide-and-conquer ]
524 Longest Word in Dictionary through Deleting [ Greedy ]
523 Continuous Subarray Sum [ Prefix Sum ]
520 Detect Capital [ Regex ]
517 Super Washing Machines [ O(n)-time Solution ]
515 Find Largest Value in Each Tree Row [ DFS ]
514 Freedom Trail [ DP | Faster DP ]
513 Find Bottom Left Tree Value [ DFS ]
509 Most Frequent Subtree Sum [ Tree Traversal ]
507 Perfect Number [ O(sqrt(n))-time Solution ]
506 Relative Ranks [ Sorting ]
505 The Maze II [ DFS + Pruning | A* Search | DFS + Multithreading ]
504 Base 7 [ 1-line Solution | Conventional Method ]
503 Next Greater Element II [ Monotone Stack ]
502 IPO [ Greedy ]
501 Find Mode in Binary Tree [ DFS + HashMap | O(1)-extra-space Solution ]
500 Keyboard Row [ 1-Line Solution ]
499 The Maze III [ A* | DFS ]
498 Diagonal Traversal [ Sorting | Direct Approach ]
496 Next Greater Element I [ Brute-force ]
495 Teemo Attacking [ Sweepline ]
494 Target Sum [ Knapsack ]
493 Reverse Pairs [ Merge-sort | Merge-sort Shorter Code | BIT ]
492 Construct the Rectangle [ Brute-force ]
491 Increasing Subsequences [ Brute-force ]
490 The Maze [ DFS ]
488 Zuma Game [ BFS ]
487 Max Consecutive Ones II [ O(1)-space Solution ]
486 Predict the Winner [ DP + Game Theory | Shorter Code ]
485 Max Consecutive Ones [ Brute-force ]
484 Find Permutation [ Topological-sort | Constructive Approach ]
483 Smallest Good Base [ Brute-force + Binary Search ]
482 License Key Formatting [ Short Solution ]
481 Magical String [ BFS ]
480 Sliding Window Median [ Order Statistic Tree via Fenwick Tree ]
477 Total Hamming Distance [ Bit-by-bit Counting ]
476 Number Complement [ One-line Solution ]
475 Heaters [ Direct Approach | Binary Search ]
474 One and Zeroes [ 0/1-Knapsack ]
473 Matchsticks to Square [ Backtracking ]
472 Concatenated Words [ DP + Trie ]
471 Encode String with Shortest Length [ DP ]
469 Convex Polygon [ Cross Product ]
468 Validate IP Address [ Solution ]
467 Unique Substring in Wraparound String [ String Breaking and Encoding ]
466 Count the Repetitions [ DP ]
465 Optimal Account Balancing [ Subset-Sum ]
464 Can I Win [ DP + Game Theory ]
463 Island Perimeter [ Brute-force ]
462 Minimum Moves to Equal Array Elements II [ Median Finding + Quick-Selection ]
461 Hamming Distance [ Brute-force ]
459 Repeated Substring Pattern [ O(n^1.5) Solution | 1-Liner | 1-Liner via Regex | Miller-Rabin | KMP ]
456 123 Pattern [ O(n log n) Solution via BST ]
455 Assign Cookies [ Greedy ]
454 4Sum II [ HashMap ]
453 Minimum Moves to Equal Array Elements [ Solution ]
452 Minimum Number of Arrows to Burst Balloons [ Greedy via Sweepline ]
451 Sort Characters by Frequency [ Counting-sort ]
450 Delete Node in a BST [ Iterative Solution | Shorter Solution ]
449 Serialize and Deserialize BST [ Pre-order Traversal | Optimized Version ]
448 Find All Numbers Disappeared in an Array [ Cycle-finding ]
447 Number of Boomerangs [ Counting via HashMap ]
446 Arithmetic Slices II - Subsequence [ Very Fast O(n^3) DP Solution | O(n^2) DP Solution with Pruning ]
444 Sequence Reconstruction [ Topological Sort ]
443 String Compression [ Solution ]
442 Find All Duplicates in an Array [ Mod Trick ]
441 Arranging Coins [ O(1) Brute-force ]
440 K-th Smallest in Lexicographical Order [ Counting + Greedy ]
439 Ternary Expression Parser [ Top-down Approach ]
438 Find All Anagrams in a String [ Sliding-window ]
437 Path Sum III [ One-pass DFS | One-pass DFS Version 2 | Two-pass DFS ]
436 Find Right Interval [ TreeMap ]
435 Non-overlapping Intervals [ Greedy | Activity Selection ]
435 Number of Segments in a String [ Regex ]
433 Minimum Genetic Mutation [ BFS ]
432 All O`one Data Structure [ HashMap + Doubly Circular Linked List ]
425 Word Squares [ Backtracking + Pruning with Prefix Structure | Hueristic Backtracking + Pruning with BitSet ]
424 Longest Repeating Character Replacement [ Binary Search | Sliding-window ]
423 Reconstruct Original Digits from English [ Greedy ]
422 Valid World Square [ Brute-force ]
421 Maximum XOR of Two Numbers in an Array [ Binary Trie ]
420 Strong Password Checker [ Stupid Solution ]
419 Battleships in a Board [ Single-pass + In-place + No modification ]
418 Sentence Screen Fitting [ Simulation ]
417 Pacific Atlantic Water Flow [ Graph Reachability | DP + Vertex Contraction ]
416 Partition Equal Subset Sum [ 0/1-Knapsack ]
415 Add Strings [ BigInteger Addition ]
414 Third Maximum Number [ One-pass Solution ]
413 Arithmetic Slices [ Solution | In-place Solution ]
412 Fizz Buzz [ Brute-force ]
411 Minimum Unique Word Abbreviation [ Brute-force + Pruning ]
410 Split Array Largest Sum [ Bisect + Greedy ]
409 Longest Palindrome [ Counting ]
408 Valid Word Abbreviation [ Brute-force ]
407 Trapping Rain Water II [ Priority Queue | Dijkstra | SPFA ]
406 Queue Reconstruction by Height [ Greedy + Sorting ]
405 Convert a Number to Hexadecimal [ Bit Manipulation ]
404 Sum of Left Leaves [ DFS ]
403 Frog Jump [ DP ]
402 Remove K Digits [ Greedy + Monotone Stack ]
401 Binary Watch [ Brute-force 1 | Brute-force 2]
400 Nth Digit [ Counting + Bisect ]
399 Evaluate Division [ Floyed | DFS ]
398 Random Pick Index [ Solution1 | Solution2 | Solution3 ]
397 Integer Replacement [ BFS ]
396 Rotate Fucntion [ Solution ]
395 Longest Substring with At Least K Repeating Characters [ O(256N) Solution | Solution with Pruning ]
394 Decode String [ Top-down Approach ]
393 UTF-8 Validation [ Solution ]
392 Is Subsequence [ Solution ]
391 Perfect Rectangle [ Sweepline + TreeMap | Sweepline + Segment Tree ]
390 Elimination Game [ O(log n) Math ]
389 Find the Difference [ Solution ]
388 Longest Absolute File Path [ Using a Stack | Recursively Solution ]
387 First Unique Character in a String [ Brute-Force ]
386 Lexicographical Numbers [ Using a stack | Recursive Solution ]
385 Mini Parser [ Char-by-char Approach | Using Scanner ]
384 Shuffle an Array [ Solution ]
383 Ransom Note [ Solution ]
381 Insert Delete GetRandom O(1) Duplicate Allowed [ Solution ]
379 Design Phone Directory [ Simple Solution ]
378 Kth Smallest Element in a Sorted Matrix [ Bisect + Young Tableau ]
377 Combination Sum IV [ DP ]
376 Wiggle Subsequence [ O(n) Climbing Mountain | O(n) In-place Maximal/Minimal Finding ]
375 Guess Number Higher or Lower II [ O(n^3) DP ]
374 Guess Number Higher or Lower [ Binary Search ]
373 Find K Pairs with Smallest Sums [ O(k log k) Solution | O(k log(min(k, m, n)) + min(k, m, n)) Solution ]
372 Super Pow [ Most-significant Bit -> Least-significant Bit | Least-significant Bit -> Most-significant Bit ]
371 Sum of Two Integers [ Bit Manipulation ]
370 Range Addition [ Fenwick Tree | Sweepline | O(n) Prefix Trick | Segment Tree ]
369 Plus One Linked Listđź”’
368 Largest Divisible Subset [ DP ]
367 Valid Perfect Square [ Binary Search ]
366 Find Leaves of Binary Tree [ Computing Tree Height ]
365 Water and Jug Problem [ Math ]
364 Nested List Weight Sum IIđź”’
363 Max Sum of Rectangle No Larger Than K [ BST ]
362 Design Hit Counter [ Sliding Window ]
361 Bomb Enemy [ DP ]
360 Sort Transformed Array [ O(n)-time Solution ]
359 Logger Rate Limiter [ Simple Solution | Sliding Window ]
358 Rearrange String k Distance Apart [ Greedy + Sliding Window ]
357 Count Numbers with Unique Digits [ Product Rule ]
356 Line Reflection [ In-place Solution ]
355 Design Twitter [ k-way Merging ]
354 Russian Doll Envelopes [ Longest Path | Longest Increasing Subsequence ]
353 Design Snake Game [ Deque + HashTable ]
352 Data Stream as Disjoint Intervals [ BST ]
351 Android Unlock Patternsđź”’
350 Intersection of Two Arrays II [ Mergesort ]
349 Intersection of Two Arrays [ Java Stream ]
348 Design Tic-Tac-Toe [ O(1)-time Solution ]
347 Top K Frequent Elements [ Map+QuickSelection | Map+CountingSort ]
346 Moving Average from Data Stream [ Sliding Window ]
345 Reverse Vowels of a String [ Two-Pointer ]
344 Reverse String [ String ]
343 Integer Break [ Math/DP ]
342 Power of Four [ Bit Manipulate ]
341 Flatten Nested List Iterator [ Stack/DFS | Lazier ]
340 Longest Substring with At Most K Distinct Characters [ O(n) Sliding Window | O(n log n) Bisect | Slinding Window Shorter Code | Sliding Window for Streaming Data (1 pass) ]
339 Nested List Weight Sum [ DFS ]
338 Counting Bits [ Counting ]
337 House Robber III [ Tree DP ]
336 Palindrome Pairs [ A Naive Solution ]
335 Self Crossing [ Geometry ]
334 Increasing Triplet Subsequence [ LIS ]
333 Largest BST Subtree [ Tree-DP ]
332 Reconstruct Itinerary [ Euler Path ]
331 Verify Preorder Serialization of a Binary Tree [ Using a Stack | Property of Full Binary Tree ]
330 Patching Array [ Greedy Algorithm ]
329 Longest Increasing Path in a Matrix [ O(nm) DP ]
328 Odd Even Linked List [ O(n) in-place ]
327 Count of Range Sum [ O(n log n) solution via Fenwick Tree ]
326 Power of Three [ An interesting O(log log n) solution ]
325 Maximum Size Subarray Sum Equals k [ Prefix-sum + HashTable ]
324 Wiggle Sort II [ Median Finding, Dutch National Flag ]
323 Number of Connected Components in an Undirected Graph [ DFS ]
322 Coin Change [ Knapsack ]
321 Create Maximum Number [ Stack + Greedy ]
320 Generalized Abbreviation [ Bit-manipulation ]
319 Bulb Switcher [ O(1) Math ]
318 Maximum Product of Word Lengths [ O(n^2) brute-force ]
317 Shortest Distance from All Buildings [ BFS ]
316 Remove Duplicate Letters [ O(n) Greedy Solution | O(n) Solution via Stack ]
315 Count of Small Numbers After Self [ Discretization + Fenwick Tree | Mergesort ]
314 Binary Tree Vertical Order TGraversal [ BFS | BFS (slower, but shorter) ]
313 Super Ugly Number [ O(nk) Constructive Algorithm ]
312 Burst Balloons [ O(n^3) DP ]
311 Sparse Matrix Multiplicationđź”’
310 Minimum Height Trees [ Longest Path in Tree | Tree DP ]
309 Best Time to Buy and Sell Stock with Cooldown [ O(n^2) DP | O(n) DP ]
308 Range Sum Query 2D - Mutable [ 2D-Sqrt Partition | 2D Fenwick Tree ]
307 Range Sum Query - Mutable [ sqrt(n) Trick | Fenwick Tree | Segment Tree ]
306 Additive Number [ Fibonacci Sequence ]
305 Number of Islands II [ Union-Find Set ]
304 Range Sum Query 2D - Immutable [ Inclusion-Exclusion ]
303 Range Sum Query - Immutable [ Prefix Sum ]
302 Smallest Rectangle Enclosing Black Pixels [ DFS ]
301 Remove Invalid Parentheses [ Backtracking | DP ]
298 Binary Tree Longest Consecutive Sequence [ Tree-DP | DFS | Another DFS Solution]
297 Serialize and Deserialize Binary Tree [ DFS ]
294 Flip Game II [ Nim + Sprague-Grundy Theorem ]
293 Flip Game [ Brute-force ]
291 Word Pattern II [ Backtracking | Backtracking + Pruning ]
289 Game of Life [ In-place Solution | Infinite Board ]
288 Unique Word Abbreviation [ HashMap ]
286 Walls and Gates [ BFS]
285 Inorder Successor in BST [ Top-down Approach | Using Parent Pointers ]
283 Move Zeroes [ Partition | Cheating ]
281 Zigzag Iterator [ Solution ]
280 Wiggle Sort [ One-pass Solution ]
277 Find the Celebrity [ Universal Sink ]
276 Paint Fence [ Combinatorial ]
274 H-Index [ Counting Sort ]
272 Closest Binary Search Tree Value II [ Predesessor + Successor in BST ]
271 Encode and Decode Strings [ Escaping Character | Trie Serialization/Deserialization ]
270 Closest Binary Search Tree Value [ Solution ]
269 Alien Dictionary [ Topological Sort (BFS) | BFS with Smaller Constant | Topological Sort (DFS)]
267 Palindrome Permutation II [ Counting + Next Permutation ]
266 Palindrome Permutation [ Counting ]
265 Paint House II [ O(nk) DP ]
262 Trips and Users [ Solution ]
261 Graph Valid Tree [ Union-find Set ]
259 3Sum Smaller [ Two-pointer ]
256 Paint House [ DP ]
255 Verify Preorder Sequence in Binary Search Tree [ Construction Method | RMQ + Binary Search ]
254 Factor Combinations [ Backtracking ]
253 Meeting Rooms II [ Sweepline Algorithm ]
252 Meeting Rooms [ Sweepline ]
251 Flatten 2D Vector [ Iterator ]
250 Count Univalue Subtrees [ DFS ]
249 Group Shifted Strings [ Keyed-by ]
246 Strobogrammatic Number [ Brute-force ]
245 Shortest Word Distance III [ Linear Scan ]
244 Shortest Word Distance II [ Solution ]
218 The Skyline Problem [ Sweepline | Java Code]
214 Shortest Palindrome [ Rabin-Karp rolling hash | KMP ]
212 Word Search II [ DP + Trie ]
206 Reverse Linked List [ Solution ]
197 Rising Temperature [ Solution ]
196 Delete Duplicate Emails [ Solution ]
186 Reverse Words in a String II [ In-place Solution ]
184 Department Highest Salary [ Solution ]
183 Customers Who Never Order [ Solution ]
182 Duplicate Emails [ Solution ]
181 Employees Earning More Than Their Managers [ Solution ]
180 Consecutive Numbers [ Solution ]
178 Rank Scores [ Solution ]
177 Nth Highest Salary [ Solution ]
176 Second Highest Salary [ Solution ]
175 Combine Two Tables [ Solution ]
170 Two Sum III - Data structure design [ Hash Table ]
167 Two Sum II - Input array is sorted [ Two-pointer ]
165 Compare version Numbers [ Lexicographical Order ]
163 Missing Ranges [ Sorting ]
161 One Edit Distance [ Short Java Code ]
159 Longest Substring with At Most Two Distinct Characters [ Sliding-window ]
158 Read N Characters Given Read4 II - Call multiple times [ Reader ]
157 Read N Characters Given Read4 [ Reader ]
156 Binary Tree Upside Down [ Post-order Traversal ]
155 Min Stack [ More Memory, Shorter Code | As Little Memory as Possible ]
152 Maximum Product Subarray [ Three Solutions ]
151 Reverse Words in a String [ Java Solution | C In-place Solution ]
146 LRU Cache [ Doubly Connected Linked List + Hash Table ]
140 Word Break II [ DP + DFS ]
139 Word Break [ Short DP | DP + Trie ]
136 Single Number [ Xor | Randomized Partition ]
128 Longest Consecutive Sequence [ O(n) HashSet ]
127 Word Ladder [ BFS ]
96 Unique Binary Search Trees [ DP ]
79 Word Search [ DFS ]
76 Minimum Window Substring [ Sliding-window ]
72 Edit Distance [ DP ]
47 Permutations II [ next_permutation ]
44 Wildcard Matching [ DP | Greedy ]
40 Combination Sum II [ DP Knapsack ]
39 Combination Sum [ DP + Backtracking ]
37 Sudoku Solver [ Greedy Backtracking Using Bitmask | Greedy Backtracking ]
36 Valid Sudoku [ Solution ]
22 Generate Parentheses [ DP | Recursion ]
10 Regular Expression Matching [ DP ]
4 Median of Two Sorted Arrays [ Binary Search ]
2 Add Two Numbers [ Not in-place | In-place ]
1 Two Sum [ Two Pointers | Hash Table ]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published