leetcode
This page documents my attempts at solving LeetCode problems using Rust. It’s synced weekly through leech, I keep only the latest submission for each problem, and to keep things simple I write the solution intuition directly as a comment in the code. I aim to craft each solution in the most elegant and idiomatic Rust I can manage after studying others’ approaches, though LeetCode doesn’t always make that easy.
problems
- 0001 - Two Sum
- 0002 - Add Two Numbers
- 0009 - Palindrome Number
- 0011 - Container With Most Water
- 0014 - Longest Common Prefix
- 0020 - Valid Parentheses
- 0021 - Merge Two Sorted Lists
- 0022 - Generate Parentheses
- 0023 - Merge k Sorted Lists
- 0026 - Remove Duplicates from Sorted Array
- 0027 - Remove Element
- 0035 - Search Insert Position
- 0041 - First Missing Positive
- 0042 - Trapping Rain Water
- 0045 - Jump Game II
- 0048 - Rotate Image
- 0053 - Maximum Subarray
- 0055 - Jump Game
- 0056 - Merge Intervals
- 0058 - Length of Last Word
- 0069 - Sqrt(x)
- 0070 - Climbing Stairs
- 0072 - Edit Distance
- 0083 - Remove Duplicates from Sorted List
- 0088 - Merge Sorted Array
- 0096 - Unique Binary Search Trees
- 0100 - Same Tree
- 0101 - Symmetric Tree
- 0102 - Binary Tree Level Order Traversal
- 0103 - Binary Tree Zigzag Level Order Traversal
- 0104 - Maximum Depth of Binary Tree
- 0112 - Path Sum
- 0118 - Pascal's Triangle
- 0121 - Best Time to Buy and Sell Stock
- 0122 - Best Time to Buy and Sell Stock II
- 0123 - Best Time to Buy and Sell Stock III
- 0125 - Valid Palindrome
- 0136 - Single Number
- 0137 - Single Number II
- 0169 - Majority Element
- 0188 - Best Time to Buy and Sell Stock IV
- 0190 - Reverse Bits
- 0191 - Number of 1 Bits
- 0214 - Shortest Palindrome
- 0217 - Contains Duplicate
- 0228 - Summary Ranges
- 0231 - Power of Two
- 0258 - Add Digits
- 0260 - Single Number III
- 0309 - Best Time to Buy and Sell Stock with Cooldown
- 0396 - Rotate Function
- 0402 - Remove K Digits
- 0406 - Queue Reconstruction by Height
- 0459 - Repeated Substring Pattern
- 0496 - Next Greater Element I
- 0502 - IPO
- 0532 - K-diff Pairs in an Array
- 0551 - Student Attendance Record I
- 0575 - Distribute Candies
- 0605 - Can Place Flowers
- 0617 - Merge Two Binary Trees
- 0637 - Average of Levels in Binary Tree
- 0680 - Valid Palindrome II
- 0717 - 1-bit and 2-bit Characters
- 0740 - Delete and Earn
- 0763 - Partition Labels
- 0877 - Stone Game
- 0899 - Orderly Queue
- 0907 - Sum of Subarray Minimums
- 0957 - Prison Cells After N Days
- 0965 - Univalued Binary Tree
- 0976 - Largest Perimeter Triangle
- 1015 - Smallest Integer Divisible by K
- 1018 - Binary Prefix Divisible By 5
- 1091 - Shortest Path in Binary Matrix
- 1221 - Split a String in Balanced Strings
- 1262 - Greatest Sum Divisible by Three
- 1304 - Find N Unique Integers Sum up to Zero
- 1342 - Number of Steps to Reduce a Number to Zero
- 1354 - Construct Target Array With Multiple Sums
- 1437 - Check If All 1's Are at Least Length K Places Away
- 1488 - Avoid Flood in The City
- 1513 - Number of Substrings With Only 1s
- 1518 - Water Bottles
- 1526 - Minimum Number of Increments on Subarrays to Form a Target Array
- 1550 - Three Consecutive Odds
- 1578 - Minimum Time to Make Rope Colorful
- 1689 - Partitioning Into Minimum Number Of Deci-Binary Numbers
- 1716 - Calculate Money in Leetcode Bank
- 1720 - Decode XORed Array
- 1759 - Count Number of Homogenous Substrings
- 1769 - Minimum Number of Operations to Move All Balls to Each Box
- 1827 - Minimum Operations to Make the Array Increasing
- 1898 - Maximum Number of Removable Characters
- 1927 - Sum Game
- 1935 - Maximum Number of Words You Can Type
- 2037 - Minimum Number of Moves to Seat Everyone
- 2053 - Kth Distinct String in an Array
- 2085 - Count Common Words With One Occurrence
- 2125 - Number of Laser Beams in a Bank
- 2139 - Minimum Moves to Reach Target Score
- 2154 - Keep Multiplying Found Values by Two
- 2169 - Count Operations to Obtain Zero
- 2185 - Counting Words With a Given Prefix
- 2275 - Largest Combination With Bitwise AND Greater Than Zero
- 2300 - Successful Pairs of Spells and Potions
- 2315 - Count Asterisks
- 2380 - Time Needed to Rearrange a Binary String
- 2554 - Maximum Number of Integers to Choose From a Range I
- 2578 - Split With Minimum Sum
- 2594 - Minimum Time to Repair Cars
- 2611 - Mice and Cheese
- 2657 - Find the Prefix Common Array of Two Arrays
- 2696 - Minimum String Length After Removing Substrings
- 2826 - Sorting Three Groups
- 2894 - Divisible and Non-divisible Sums Difference
- 2942 - Find Words Containing Character
- 2951 - Find the Peaks
- 3019 - Number of Changing Keys
- 3101 - Count Alternating Subarrays
- 3147 - Taking Maximum Energy From the Mystic Dungeon
- 3190 - Find Minimum Operations to Make All Elements Divisible by Three
- 3217 - Delete Nodes From Linked List Present in Array
- 3318 - Find X-Sum of All K-Long Subarrays I
- 3370 - Smallest Number With All Set Bits
- 3407 - Substring Matching Pattern
- 3423 - Maximum Difference Between Adjacent Elements in a Circular Array
- 3432 - Count Partitions with Even Sum Difference
- 3461 - Check If Digits Are Equal in String After Operations I
- 3512 - Minimum Operations to Make Array Sum Divisible by K
- 3658 - GCD of Odd and Even Sums
- 3693 - Climbing Stairs II
- 3767 - Maximize Points After Choosing K Tasks
- 3833 - Count Dominant Indices
- 3840 - House Robber V
- 3898 - Find the Degree of Each Vertex
- 3940 - Limit Occurrences in Sorted Array
- 3945 - Digit Frequency Score
- 3994 - Minimum Adjacent Swaps to Partition Array