/leetcode

LeetCode Solutions

Primary LanguageC++

LeetCode Solutions

Index Title Solution
0001 Two Sum C++/Elixir/Erlang/Go/Java/Python/Rust
0002 Add Two Numbers C++/Elixir/Erlang/Go/Java/Python/Rust
0003 Longest Substring Without Repeating Characters C++/Elixir/Erlang/Go/Java/Python/Rust
0004 Median of Two Sorted Arrays C++/Elixir/Erlang/Go/Java/Python/Rust
0005 Longest Palindromic Substring C++/Go/Java/Python/Rust
0006 ZigZag Conversion C++/Go/Java/Python/Rust
0007 Reverse Integer C++/Go/Java/Python/Rust
0008 String to Integer (atoi) C++/Go/Java/Python/Rust
0009 Palindrome Number C++/Go/Java/Python/Rust
0010 Regular Expression Matching C++/Go/Java/Python/Rust
0011 Container With Most Water C++/Go/Java/Python/Rust
0012 Integer to Roman C++/Go/Java/Python/Rust
0013 Roman to Integer C++/Go/Java/Python/Rust
0014 Longest Common Prefix C++/Go/Java/Python/Rust
0015 3Sum C++/Go/Java/Python/Rust
0016 3Sum Closest C++/Go/Java/Python/Rust
0017 Letter Combinations of a Phone Number C++/Go/Java/Python/Rust
0018 4Sum C++/Go/Java/Python/Rust
0019 Remove Nth Node From End of List C++/Go/Java/Python/Rust
0020 Valid Parentheses C++/Go/Java/Python/Rust
0021 Merge Two Sorted Lists C++/Go/Java/Python/Rust
0022 Generate Parentheses C++
0023 Merge k Sorted Lists C++
0024 Swap Nodes in Pairs C++
0025 Reverse Nodes in k-Group C++
0026 Remove Duplicates from Sorted Array C++
0027 Remove Element C++
0028 Implement strStr() C++
0029 Divide Two Integers C++
0030 Substring with Concatenation of All Words C++
0031 Next Permutation C++
0032 Longest Valid Parentheses C++
0033 Search in Rotated Sorted Array C++
0034 Search for a Range C++
0035 Search Insert Position C++
0036 Valid Sudoku C++
0037 Sudoku Solver C++
0038 Count and Say C++
0039 Combination Sum C++
0040 Combination Sum II C++
0041 First Missing Positive C++
0042 Trapping Rain Water C++/Go/Java
0044 Wildcard Matching C++
0045 Jump Game II C++
0046 Permutations C++
0048 Rotate Image Go
0049 Group Anagrams Go
0050 Pow(x, n) C++
0053 Maximum Subarray C++
0055 Jump Game Go
0056 Merge Intervals Go
0058 Length of Last Word C++
0062 Unique Paths C++
0064 Minimum Path Sum Go
0065 Valid Number C++/Go/Java/Python
0066 Plus One C++
0067 Add Binary C++
0069 Sqrt(x) C++
0070 Climbing Stairs C++
0072 Edit Distance Go
0074 Search a 2D Matrix C++
0075 Sort Colors Go
0076 Minimum Window Substring Go
0078 Subsets C++/Go/Java
0079 Word Search Go
0081 Search in Rotated Sorted Array II C++
0083 Remove Duplicates from Sorted List C++
0084 Largest Rectangle in Histogram Go
0085 Maximal Rectangle Go
0088 Merge Sorted Array C++
0089 Gray Code C++
0094 Binary Tree Inorder Traversal C++
0096 Delete Duplicate Emails C++
0098 Validate Binary Search Tree Go
0100 Same Tree C++
0101 Symmetric Tree C++
0102 Binary Tree Level Order Traversal C++
0104 Maximum Depth of Binary Tree C++
0105 Construct Binary Tree from Preorder and Inorder Traversal Go
0107 Binary Tree Level Order Traversal II C++
0108 Convert Sorted Array to Binary Search Tree C++
0110 Balanced Binary Tree C++
0111 Minimum Depth of Binary Tree C++
0112 Path Sum C++
0114 Flatten Binary Tree to Linked List Go
0116 Populating Next Right Pointers in Each Node C++
0118 Pascal's Triangle C++
0119 Pascal's Triangle II C++
0121 Best Time to Buy and Sell Stock C++
0122 Best Time to Buy and Sell Stock II C++
0124 Binary Tree Maximum Path Sum Go
0125 Valid Palindrome C++
0126 Word Ladder II C++
0128 Longest Consecutive Sequence Go
0134 Gas Station C++
0135 Candy C++
0136 Single Number C++/Java
0137 Single Number II C++/Java
0138 Copy List with Random Pointer C++
0139 Word Break C++
0140 Word Break II C++
0141 Linked List Cycle C++
0142 Linked List Cycle II C++
0143 Reorder List C++
0144 Binary Tree Preorder Traversal C++
0145 Binary Tree Postorder Traversal C++
0146 LRU Cache C++
0147 Insertion Sort List C++
0148 Sort List C++
0149 Max Points on a Line C++
0150 Evaluate Reverse Polish Notation C++
0152 Maximum Product Subarray Go
0153 Find Minimum in Rotated Sorted Array C++
0154 Find Minimum in Rotated Sorted Array II C++
0155 Min Stack C++
0160 Intersection of Two Linked Lists C++
0162 Find Peak Element C++
0165 Compare Version Numbers C++
0168 Excel Sheet Column Title C++
0169 Majority Element C++/Java
0171 Excel Sheet Column Number C++
0172 Factorial Trailing Zeroes C++
0175 Combine Two Tables SQL
0176 Second Highest Salary SQL
0177 Nth Highest Salary SQL
0178 Rank Scores SQL
0180 Consecutive Numbers SQL
0181 Employees Earning More Than Their Managers SQL
0182 Duplicate Emails SQL
0183 Customers Who Never Order SQL
0184 Department Highest Salary SQL
0185 Department Top Three Salaries SQL
0187 Repeated DNA Sequences C++/Java
0189 Rotate Array C++
0190 Reverse Bits C++/Java
0191 Number of 1 Bits C++/Java
0197 Rising Temperature SQL
0198 House Robber C++
0201 Bitwise AND of Numbers Range C++/Java
0202 Happy Number C++
0203 Remove Linked List Elements C++
0204 Count Primes C++
0205 Isomorphic Strings C++
0206 Reverse Linked List C++
0207 Course Schedule C++
0208 Implement Trie (Prefix Tree) Go
0210 Course Schedule II C++
0215 Kth Largest Element in an Array Go
0217 Contains Duplicate C++
0219 Contains Duplicate II C++
0221 Maximal Square Go
0222 Count Complete Tree Nodes C++
0223 Rectangle Area C++
0225 Implement Stack using Queues C++
0226 Invert Binary Tree C++
0228 Summary Ranges C++
0229 Majority Element II C++
0230 Kth Smallest Element in a BST C++
0231 Power of Two C++/Java
0232 Implement Queue using Stacks C++
0233 Number of Digit One C++
0234 Palindrome Linked List C++
0235 Lowest Common Ancestor of a Binary Search Tree C++
0236 Lowest Common Ancestor of a Binary Tree C++
0237 Delete Node in a Linked List C++
0238 Product of Array Except Self C++
0239 Sliding Window Maximum C++
0240 Search a 2D Matrix II C++
0242 Valid Anagram C++
0257 Binary Tree Paths C++
0258 Add Digits C++
0260 Single Number III C++/Java
0262 Trips and Users SQL
0263 Ugly Number C++
0264 Ugly Number II C++
0268 Missing Number C++/Java
0273 Integer to English Words C++
0274 H-Index C++
0275 H-Index II C++
0278 First Bad Version C++
0279 Perfect Squares C++
0283 Move Zeroes C++
0284 Peeking Iterator C++
0287 Find the Duplicate Number C++
0289 Game of Life C++
0290 Word Pattern C++
0292 Nim Game C++
0295 Find Median from Data Stream C++
0297 Serialize and Deserialize Binary Tree C++
0299 Bulls and Cows C++
0300 Longest Increasing Subsequence C++
0301 Remove Invalid Parentheses C++
0303 Range Sum Query - Immutable C++
0304 Range Sum Query 2D - Immutable C++
0306 Additive Number C++
0307 Range Sum Query - Mutable C++
0308 Range Sum Query 2D - Mutable C++
0309 Best Time to Buy and Sell Stock with Cooldown C++
0310 Minimum Height Trees C++
0312 Burst Balloons Go
0315 Count of Smaller Numbers After Self C++
0318 Maximum Product of Word Lengths C++/Java
0319 Bulb Switcher C++
0322 Coin Change Go
0326 Power of Three C++
0328 Odd Even Linked List C++
0334 Increasing Triplet Subsequence C++
0337 House Robber III C++
0338 Counting Bits C++/Java
0341 Flatten Nested List Iterator C++
0342 Power of Four C++/Java
0343 Integer Break C++
0344 Reverse String C++
0345 Reverse Vowels of a String C++
0347 Top K Frequent Elements C++
0349 Intersection of Two Arrays C++
0350 Intersection of Two Arrays II C++
0352 Data Stream as Disjoint Intervals C++
0354 Russian Doll Envelopes C++
0365 Water and Jug Problem C/C++/Java/JS/Python
0367 Valid Perfect Square C++
0368 Largest Divisible Subset C++
0371 Sum of Two Integers C++/Java
0375 Guess Number Higher or Lower II C++
0382 Linked List Random Node C++
0389 Find the Difference C++/Java
0393 UTF-8 Validation C++/Java
0394 Decode String Go
0397 Integer Replacement C++/Java
0398 Random Pick Index C++
0401 Binary Watch C++/Java
0405 Convert a Number to Hexadecimal C++/Java
0406 Queue Reconstruction by Height Go
0414 Third Maximum Number C++
0416 Partition Equal Subset Sum Go
0420 Strong Password Checker C++
0421 Maximum XOR of Two Numbers in an Array C++/Java
0430 Flatten a Multilevel Doubly Linked List C++
0437 Path Sum III Go
0438 Find All Anagrams in a String Go
0445 Add Two Numbers II C++
0448 Find All Numbers Disappeared in an Array Go
0456 132 Pattern C++
0461 Hamming Distance C++/Go/Java
0464 Can I Win C++
0470 Implement Rand10() Using Rand7() C++/Java
0476 Number Complement C++/Java
0477 Total Hamming Distance C++/Java
0478 Generate Random Point in a Circle C++/Java
0485 Max Consecutive Ones C++
0493 Reverse Pairs C++
0494 Target Sum Go
0497 Random Point in Non-overlapping Rectangles C++/Java
0509 Fibonacci Number C++
0519 Random Flip Matrix C++/Java
0525 Contiguous Array C++
0528 Random Pick with Weight C++/Java
0530 Minimum Absolute Difference in BST C++
0532 K-diff Pairs in an Array C++
0538 Convert BST to Greater Tree Go
0543 Diameter of Binary Tree Go
0560 Subarray Sum Equals K Go
0561 Array Partition I C++
0564 Find the Closest Palindrome Python
0566 Reshape the Matrix C++
0572 Subtree of Another Tree Go
0578 Get Highest Answer Rate Question C++
0581 Shortest Unsorted Continuous Subarray Go
0595 Big Countries SQL
0596 Classes More Than 5 Students SQL
0601 Human Traffic of Stadium SQL
0605 Can Place Flowers C++
0617 Merge Two Binary Trees Go
0620 Not Boring Movies SQL
0621 Task Scheduler Go
0626 Exchange Seats SQL
0627 Swap Salary SQL
0628 Maximum Product of Three Numbers C++
0643 Maximum Average Subarray I C++
0647 Palindromic Substrings Go
0661 Image Smoother C++
0665 Non-decreasing Array C++
0674 Longest Continuous Increasing Subsequence C++
0679 24 Game Java
0680 Valid Palindrome II Java
0687 Longest Univalue Path C++
0693 Binary Number with Alternating Bits C++/Java
0697 Degree of an Array C++
0707 Design Linked List C++
0709 To Lower Case Go
0710 Random Pick with Blacklist C++/Java
0717 1-bit and 2-bit Characters C++
0720 Longest Word in Dictionary C++
0724 Find Pivot Index C++
0725 Split Linked List in Parts C++
0746 Min Cost Climbing Stairs C++
0747 Largest Number At Least Twice of Others C++
0748 Shortest Completing Word Python
0756 Pyramid Transition Matrix C++
0762 Prime Number of Set Bits in Binary Representation C++/Java
0766 Toeplitz Matrix C++
0771 Jewels and Stones C++/Go/Java/Python
0783 Minimum Distance Between BST Nodes C++
0784 Letter Case Permutation C++/Java
0786 K-th Smallest Prime Fraction C++
0793 Preimage Size of Factorial Zeroes Function C++
0804 Unique Morse Code Words Go
0811 Subdomain Visit Count Python
0817 Linked List Components C++
0827 Making A Large Island C++
0830 Positions of Large Groups C++
0832 Flipping an Image C++
0840 Magic Squares In Grid C++
0846 Hand of Straights C++
0849 Maximize Distance to Closest Person C++
0855 Exam Room C++
0862 Shortest Subarray with Sum at Least K C++
0867 Transpose Matrix C++
0876 Middle of the Linked List C++/Go/Java/Python/Rust
0881 Boats to Save People C++
0884 Uncommon Words from Two Sentences Python
0888 Fair Candy Swap C++
0889 Construct Binary Tree from Preorder and Postorder Traversal C++
0892 Surface Area of 3D Shapes C++
0896 Monotonic Array C++
0898 Bitwise ORs of Subarrays C++/Java
0905 Sort Array By Parity C++
0914 X of a Kind in a Deck of Cards C++
0922 Sort Array By Parity II C++
0926 Flip String to Monotone Increasing C++
0929 Unique Email Addresses Go
0933 Number of Recent Calls C++
0938 Range Sum of BST C++/Go/Java/Python
0941 Valid Mountain Array C++
0949 Largest Time for Given Digits C++
0953 Verifying an Alien Dictionary C++
0961 N-Repeated Element in Size 2N Array Go
0963 Minimum Area Rectangle II C++
0965 Univalued Binary Tree Go
0966 Vowel Spellchecker Go
0967 Numbers With Same Consecutive Differences Go
0968 Binary Tree Cameras Go
0969 Pancake Sorting Go
0970 Powerful Integers Go
0971 Flip Binary Tree To Match Preorder Traversal Go
0972 Equal Rational Numbers Go
0973 K Closest Points to Origin C++
0974 Subarray Sums Divisible by K Go
0975 Odd Even Jump C++
0976 Largest Perimeter Triangle Go
0977 Squares of a Sorted Array C++
0978 Longest Turbulent Subarray C++
0979 Distribute Coins in Binary Tree Go
0980 Unique Paths III C++
0981 Time Based Key-Value Store C++
0982 Triples with Bitwise AND Equal To Zero C++
0983 Minimum Cost For Tickets C++
0984 String Without AAA or BBB C++
0985 Sum of Even Numbers After Queries C++
0986 Interval List Intersections C++
0987 Vertical Order Traversal of a Binary Tree C++
0988 Smallest String Starting From Leaf C++
0989 Add to Array-Form of Integer C++
0990 Satisfiability of Equality Equations C++
0991 Broken Calculator C++
0992 Subarrays with K Different Integers C++
0993 Cousins in Binary Tree C++
0994 Rotting Oranges C++
0995 Minimum Number of K Consecutive Bit Flips C++
0996 Number of Squareful Arrays C++
0997 Find the Town Judge C++/Go/Java/Python
0998 Maximum Binary Tree II C++/Go/Java/Python
0999 Available Captures for Rook C++/Go/Java/Python
1000 Minimum Cost to Merge Stones C++
1001 Grid Illumination C++/Go/Java/Python
1002 Find Common Characters C++/Go/Java/Python
1003 Check If Word Is Valid After Substitutions C++
1004 Max Consecutive Ones III C++
1005 Maximize Sum Of Array After K Negations C++/Go/Java/Python
1006 Clumsy Factorial C++/Go/Java/Python
1007 Minimum Domino Rotations For Equal Row C++/Go/Java/Python
1008 Construct Binary Search Tree from Preorder Traversal C++/Go/Java/Python
1012 Complement of Base 10 Integer C++/Go/Java/Python
1013 Pairs of Songs With Total Durations Divisible by 60 C++/Go/Java/Python
1015 Numbers With 1 Repeated Digit C++
1019 Next Greater Node In Linked List C++/Go/Java/Python/Rust
1108 Defanging an IP Address C++/Go/Java/Python
1171 Remove Zero Sum Consecutive Nodes from Linked List C++/Go/Java/Python
1221 Split a String in Balanced Strings C++/Go/Java/Python
1227 Airplane Seat Assignment Probability C++/Go/Java
1266 Minimum Time Visiting All Points C++/Go/Java/Python
1267 Count Servers that Communicate C++
1268 Search Suggestions System C++
1269 Number of Ways to Stay in the Same Place After Some Steps C++
1275 Find Winner on a Tic Tac Toe Game C++
1276 Number of Burgers with No Waste of Ingredients C++
1277 Count Square Submatrices with All Ones C++
1278 Palindrome Partitioning III C++
1281 Subtract the Product and Sum of Digits of an Integer C++/Go/Java/Python
1282 Group the People Given the Group Size They Belong To C++
1283 Find the Smallest Divisor Given a Threshold C++
1284 Minimum Number of Flips to Convert Binary Matrix to Zero Matrix C++
1286 Iterator for Combination C++
1287 Element Appearing More Than 25% In Sorted Array C++
1288 Remove Covered Intervals C++
1289 Minimum Falling Path Sum II C++
1290 Convert Binary Number in a Linked List to Integer C++/Go/Java/Python/Rust
1291 Sequential Digits C++
1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold C++
1293 Shortest Path in a Grid with Obstacles Elimination C++
1295 Find Numbers with Even Number of Digits C++/Go/Java/Python
1296 Divide Array in Sets of K Consecutive Numbers C++
1297 Maximum Number of Occurrences of a Substring C++
1298 Maximum Candies You Can Get from Boxes C++
1299 Replace Elements with Greatest Element on Right Side C++
1300 Sum of Mutated Array Closest to Target C++
1301 Number of Paths with Max Score C++
1302 Deepest Leaves Sum C++
1304 Find N Unique Integers Sum up to Zero C++/Go/Java/Python
1305 All Elements in Two Binary Search Trees C++
1306 Jump Game III C++
1307 Verbal Arithmetic Puzzle C++
1309 Decrypt String from Alphabet to Integer Mapping C++
1310 XOR Queries of a Subarray C++
1311 Get Watched Videos by Your Friends C++
1312 Minimum Insertion Steps to Make a String Palindrome C++/Go/Java/Python/Rust
1342 Number of Steps to Reduce a Number to Zero Go
1480 Running Sum of 1d Array C++/Go/Java/Rust
1521 Find a Value of a Mysterious Function Closest to Target C++
1528 Shuffle String C++
1530 Number of Good Leaf Nodes Pairs C++
1531 String Compression II C++
1534 Count Good Triplets C++
1535 Find the Winner of an Array Game C++
1536 Minimum Swaps to Arrange a Binary Grid C++
1537 Get the Maximum Score C++
1818 Minimum Absolute Sum Difference C++