Repository with my solutions to various LeetCode problems.
To solve these problems I use functions from Golang Standard Library where applicable...
- unicode, strings, sort, slices, time, strconv...
My main focus is these tags: Array, Hash Table, String.
Read this document for all tips and tricks that are useful for solving these problems.
# | Title | Tags | Difficulty |
---|---|---|---|
1 | Two Sum | Array, Hash Table | π’ Easy |
3 | Longest Substring Without Repeating Characters | Hash Table, Sliding Window, String | π‘ Medium |
9 | Palindrome Number | Math | π’ Easy |
13 | Roman to Integer | Hash Table, Math, String | π’ Easy |
14 | Longest Common Prefix | String, Trie | π’ Easy |
20 | Valid Parentheses | Stack, String | π’ Easy |
21 | Merge Two Sorted Lists | Linked List, Recursion | π’ Easy |
26 | Remove Duplicates from Sorted Array | Array, Two Pointers | π’ Easy |
27 | Remove Element | Array, Two Pointers | π’ Easy |
28 | Find the Index of the First Occurrence in a String | String, String Matching, Two Pointers | π’ Easy |
35 | Search Insert Position | Array, Binary Search | π’ Easy |
58 | Length of Last Word | String | π’ Easy |
66 | Plus One | Array, Math | π’ Easy |
67 | Add Binary | Bit Manipulation, Math, Simulation, String | π’ Easy |
69 | Sqrt(x) | Bit Search, Math | π’ Easy |
70 | Climbing Stairs | Dynamic Programming, Math, Memoization | π’ Easy |
83 | Remove Duplicates from Sorted List | Linked List | π’ Easy |
88 | Merge Sorted Array | Array, Sorting, Two Pointers | π’ Easy |
94 | Binary Tree Inorder Traversal | Binary Tree, DFS, Stack, Tree | π’ Easy |
100 | Same Tree | Binary Tree, BFS, DFS, Stack, Tree | π’ Easy |
101 | Symmetric Tree | Binary Tree, BFS, DFS, Stack, Tree | π’ Easy |
104 | Maximum Depth of Binary Tree | Binary Tree, BFS, DFS, Stack, Tree | π’ Easy |
118 | Pascal's Triangle | Array, Dynamic Programming | π’ Easy |
119 | Pascal's Triangle II | Array, Dynamic Programming | π’ Easy |
121 | Best Time to Buy and Sell Stock | Array, Dynamic Programming | π’ Easy |
125 | Valid Palindrome | String, Two Pointers | π’ Easy |
136 | Single Number | Array, Bit Manipulation | π’ Easy |
151 | Reverse Words in a String | String, Two Pointers | π‘ Medium |
167 | Two Sum II | Array, Binary Search, Two Pointers | π‘ Medium |
168 | Excel Sheet Column Title | Math, String | π’ Easy |
169 | Majority Element | Array, Counting, Hash Table, Sorting | π’ Easy |
171 | Excel Sheet Column Number | Math, String | π’ Easy |
190 | Reverse Bits | Bit Manipulation, Divide and Conquer | π’ Easy |
191 | Number of 1 Bits | Bit Manipulation, Divide and Conquer | π’ Easy |
198 | House Robber | Array, Dynamic Programming | π‘ Medium |
205 | Isomorphic Strings | Hash Table, String | π’ Easy |
206 | Reverse Linked List | Linked List, Recursion | π’ Easy |
217 | Contains Duplicate | Array, Hash Table, Sorting | π’ Easy |
219 | Contains Duplicate II | Array, Hash Table, Sliding Window | π’ Easy |
228 | Summary Ranges | Array | π’ Easy |
242 | Valid Anagram | Hash Table, Sorting, String | π’ Easy |
257 | Binary Tree Paths | Backtracking, Binary Tree, DFS, Tree, String | π’ Easy |
258 | Add Digits | Number Theory, Math, Simulation | π’ Easy |
268 | Missing Number | Array, Bit Manipulation, Hash Table, Sorting | π’ Easy |
283 | Move Zeroes | Array, Two Pointers | π’ Easy |
290 | Word Pattern | Hash Table, String | π’ Easy |
338 | Counting Bits | Bit Manipulation, Dynamic Programming | π’ Easy |
344 | Reverse String | String, Two Pointers | π’ Easy |
345 | Reverse Vowels of a String | String, Two Pointers | π’ Easy |
349 | Intersection of Two Arrays | Array, Harsh Table, Sorting | π’ Easy |
350 | Intersection of Two Arrays II | Array, Harsh Table, Sorting | π’ Easy |
383 | Ransom Note | Counting, Hash Table, String | π’ Easy |
387 | First Unique Character in a String | Counting, Hash Table, String, Queue | π’ Easy |
389 | Find the Difference | Bit Manipulation, Hash Table, Sorting, String | π’ Easy |
392 | Is Subsequence | Dynamic Programming, String, Two Pointers | π’ Easy |
401 | Binary Watch | Backtracking, Bit Manipulation | π’ Easy |
405 | Convert a Number to Hexadecimal | Bit Manipulation, Math | π’ Easy |
412 | Fizz Buzz | Math, Simulation, String | π’ Easy |
415 | Add Strings | Math, Simulation, String | π’ Easy |
434 | Number of Segments in a String | String | π’ Easy |
448 | Find All Numbers Disappeared in an Array | Array, Hash Table | π’ Easy |
455 | Assign Cookies | Array, Greedy, Sorting, Two Pointers | π’ Easy |
459 | Repeated Substring Pattern | String, String Matching | π’ Easy |
463 | Island Perimeter | Array, DFS, BFS, Matrix | π’ Easy |
476 | Number Complement | Bit Manipulation | π’ Easy |
482 | License Key Formatting | String | π’ Easy |
485 | Max Consecutive Ones | Array | π’ Easy |
500 | Keyboard Row | Array, Hash Table, String | π’ Easy |
509 | Fibonacci Number | Dynamic Programming, Math, Memoization, Recursion | π’ Easy |
520 | Detect Capital | String | π’ Easy |
551 | Student Attendance Record I | String | π’ Easy |
557 | Reverse Words in a String III | String, Two Pointers | π’ Easy |
599 | Minimum Index Sum of Two Lists | Array, Hash Table, String | π’ Easy |
657 | Robot Return to Origin | Simulation, String | π’ Easy |
682 | Baseball Game | Array, Stack, Simulation | π’ Easy |
693 | Binary Number with Alternating Bits | Bit Manipulation | π’ Easy |
709 | To Lower Case | String | π’ Easy |
746 | Min Cost Climbing Stairs | Array, Dynamic Programming | π’ Easy |
762 | Prime Number of Set Bits in Binary Representation | Math, Bit Manipulation | π’ Easy |
771 | Jewels and Stones | Hash Table, String | π’ Easy |
796 | Rotate String | String Matching, String | π’ Easy |
804 | Unique Morse Code Words | Array, Hash Table, String | π’ Easy |
806 | Number of Lines To Write String | Array, String | π’ Easy |
819 | Most Common Word | Counting, Hash Table, String | π’ Easy |
821 | Shortest Distance to a Character | Array, String, Two Pointers | π’ Easy |
824 | Goat Latin | String | π’ Easy |
830 | Positions of Large Groups | String | π’ Easy |
832 | Flipping an Image | Array, Simulation, Matrix | π’ Easy |
844 | Backspace String Compare | Simulation, Stack, String, Two Pointers | π’ Easy |
868 | Binary Gap | Bit Manipulation | π’ Easy |
884 | Uncommon Words from Two Sentences | Hash Table, String | π’ Easy |
944 | Delete Columns to Make Sorted | Array, String | π’ Easy |
961 | N-Repeated Element in Size 2N Array | Array, Hash Table | π’ Easy |
1002 | Find Common Characters | Array, Hash Table, String | π’ Easy |
1047 | Remove All Adjacent Duplicates In String | Stack, String | π’ Easy |
1051 | Height Checker | Array, Counting Sort, Sorting | π’ Easy |
1078 | Occurrences After Bigram | String | π’ Easy |
1089 | Duplicate Zeros | Array, Two Pointers | π’ Easy |
1108 | Defanging an IP Address | String | π’ Easy |
1154 | Day of the Year | Math, String | π’ Easy |
1189 | Maximum Number of Balloons | Counting, Hash Table, String | π’ Easy |
1207 | Unique Number of Occurrences | Array, Hash Table | π’ Easy |
1221 | Split a String in Balanced Strings | Counting, Greedy, String | π’ Easy |
1275 | Find Winner on a Tic Tac Toe Game | Array, Hash Table, Matrix, Simulation | π’ Easy |
1287 | Element Appearing More Than 25% In Sorted Array | Array | π’ Easy |
1304 | Find N Unique Integers Sum up to Zero | Array, Math | π’ Easy |
1309 | Decrypt String from Alphabet to Integer Mapping | String | π’ Easy |
1313 | Decompress Run-Length Encoded List | Array | π’ Easy |
1331 | Rank Transform of an Array | Array, Hash Table, Sorting | π’ Easy |
1346 | Check If N and Its Double Exist | Array, Binary Search, Hash Table | π’ Easy |
1351 | Count Negative Numbers in a Sorted Matrix | Array, Binary Search, Matrix | π’ Easy |
1360 | Number of Days Between Two Dates | Math, String | π’ Easy |
1365 | How Many Numbers Are Smaller Than the Current Number | Array, Counting, Hash Table, Sorting | π’ Easy |
1389 | Create Target Array in the Given Order | Array, Simulation | π’ Easy |
1408 | String Matching in an Array | Array, String, String Matching | π’ Easy |
1431 | Kids With the Greatest Number of Candies | Array | π’ Easy |
1436 | Destination City | Hash Table, String | π’ Easy |
1455 | Check If a Word Occurs As a Prefix | String Manipulation, String | π’ Easy |
1470 | Shuffle the Array | Array | π’ Easy |
1480 | Running Sum of 1d Array | Array, Prefix Sum | π’ Easy |
1486 | XOR Operation in an Array | Bit Manipulation, Math | π’ Easy |
1496 | Path Crossing | Hash Table, String | π’ Easy |
1507 | Reformat Date | String | π’ Easy |
1512 | Number of Good Pairs | Array, Counting, Hash Table, Math | π’ Easy |
1518 | Water Bottles | Math, Simulation | π’ Easy |
1528 | Shuffle String | Array, String | π’ Easy |
1550 | Three Consecutive Odds | Array | π’ Easy |
1556 | Thousand Separator | String | π’ Easy |
1588 | Sum of All Odd Length Subarrays | Array, Math, Prefix Sum | π’ Easy |
1592 | Rearrange Spaces Between Words | String | π’ Easy |
1614 | Maximum Nesting Depth of the Parentheses | Stack, String | π’ Easy |
1624 | Largest Substring Between Two Equal Characters | Hash Table, String | π’ Easy |
1662 | Check If Two String Arrays are Equivalent | Array, String | π’ Easy |
1670 | Richest Customer Wealth | Array, Matrix | π’ Easy |
1678 | Goal Parser Interpretation | String | π’ Easy |
1684 | Count the Number of Consistent Strings | Array, Bit Manipulation, Hash Table, String | π’ Easy |
1704 | Determine if String Halves Are Alike | Counting, String | π’ Easy |
1720 | Decode XORed Array | Array, Bit Manipulation | π’ Easy |
1742 | Maximum Number of Balls in a Box | Counting, Hash Table, Math | π’ Easy |
1768 | Merge Strings Alternately | String, Two Pointers | π’ Easy |
1773 | Count Items Matching a Rule | Array, String | π’ Easy |
1796 | Second Largest Digit in a String | Hash Table, String | π’ Easy |
1805 | Number of Different Integers in a String | Hash Table, String | π’ Easy |
1812 | Determine Color of a Chessboard Square | Math, String | π’ Easy |
1816 | Truncate Sentence | Array, String | π’ Easy |
1832 | Check if the Sentence Is Pangram | Hash Table, String | π’ Easy |
1844 | Replace All Digits with Characters | String | π’ Easy |
1859 | Sorting the Sentence | Sorting, String | π’ Easy |
1863 | Sum of All Subset XOR Totals | Array, Bit Manipulation | π’ Easy |
1876 | Substrings of Size Three with Distinct Characters | Counting, Hash Table, Sliding Window, String | π’ Easy |
1880 | Check if Word Equals Summation of Two Words | String | π’ Easy |
1913 | Maximum Product Difference Between Two Pairs | Array, Sorting | π’ Easy |
1920 | Build Array from Permutation | Array, Simulation | π’ Easy |
1929 | Concatenation of Array | Array | π’ Easy |
1941 | Check if All Characters Have Equal Number of Occurrences | Counting, Hash Table, String | π’ Easy |
1967 | Number of Strings That Appear as Substrings in Word | String | π’ Easy |
2000 | Reverse Prefix of Word | String, Two Pointers | π’ Easy |
2006 | Count Number of Pairs With Absolute Difference K | Array, Hash Table, Counting, | π’ Easy |
2011 | Final Value of Variable After Performing Operations | Array, Simulation, String | π’ Easy |
2085 | Count Common Words With One Occurrence | Array, Counting, Hash Table, String | π’ Easy |
2103 | Rings and Rods | Hash Table, String | π’ Easy |
2114 | Maximum Number of Words Found in Sentences | Array, String | π’ Easy |
2119 | A Number After a Double Reversal | Math | π’ Easy |
2129 | Capitalize the Title | String | π’ Easy |
2160 | Minimum Sum of Four Digit Number After Splitting Digits | Greedy, Math, Sorting | π’ Easy |
2169 | Count Operations to Obtain Zero | Math, Simulation | π’ Easy |
2185 | Counting Words With a Given Prefix | Array, String | π’ Easy |
2194 | Cells in a Range on an Excel Sheet | String | π’ Easy |
2215 | Find the Difference of Two Arrays | Array, Hash Table | π’ Easy |
2283 | Check if Number Has Equal Digit Count and Digit Value | Counting, Hash Table, String | π’ Easy |
2309 | Greatest English Letter in Upper and Lower Case | Enumeration, Hash Table, String | π’ Easy |
2315 | Count Asterisks | String | π’ Easy |
2325 | Decode the Message | Hash Table, String | π’ Easy |
2418 | Sort the People | Array, Hash Table, Sorting, String | π’ Easy |
2446 | Determine if Two Events Have Conflict | Array, String | π’ Easy |
2451 | Odd String Difference | Array, Hash Table, String | π’ Easy |
2496 | Maximum Value of a String in an Array | Array, String | π’ Easy |
2506 | Count Pairs of Similar Strings | Array, Hash Table, String | π’ Easy |
2540 | Minimum Common Value | Array, Binary Search, Hash Table, Two Pointers | π’ Easy |
2553 | Separate the Digits in an Array | Array, Simulation | π’ Easy |
2574 | Left and Right Sum Differences | Array, Prefix Sum | π’ Easy |
2586 | Count the Number of Vowel Strings in Range | Array, String | π’ Easy |
2595 | Number of Even and Odd Bits | Bit Manipulation | π’ Easy |
2656 | Maximum Sum With Exactly K Elements | Array, Greedy | π’ Easy |
2696 | Minimum String Length After Removing Substrings | Simulation, Stack, String | π’ Easy |
2716 | Minimize String Length | Hash Table, String | π’ Easy |
2744 | Find Maximum Number of String Pairs | Array, Hash Table, Simulation, String | π’ Easy |
2778 | Sum of Squares of Special Elements | Array, Simulation | π’ Easy |
2788 | Split Strings by Separator | Array, String | π’ Easy |
2798 | Number of Employees Who Met the Target | Array, Enumeration | π’ Easy |
2810 | Faulty Keyboard | Simulation, String | π’ Easy |
2824 | Count Pairs Whose Sum is Less than Target | Array, Sorting, Two Pointers | π’ Easy |
2828 | Check if a String Is an Acronym of Words | Array, String | π’ Easy |
2843 | Count Symmetric Integers | Enumeration, Math | π’ Easy |
2848 | Points That Intersect With Cars | Hash Table, Math, Prefix Sum | π’ Easy |
2859 | Sum of Values at Indices With K Set Bits | Array, Bit Manipulation | π’ Easy |
2864 | Maximum Odd Binary Number | Greedy, Math, String | π’ Easy |
2894 | Divisible and Non-divisible Sums Difference | Math | π’ Easy |
2917 | Find the K-or of an Array | Array, Bit Manipulation | π’ Easy |
2932 | Maximum Strong Pair XOR I | Array, Bit Manipulation, Hash Table | π’ Easy |
2942 | Find Words Containing Character | Array, String | π’ Easy |
2960 | Count Tested Devices After Test Operations | Array, Counting, Simulation | π’ Easy |
2974 | Minimum Number Game | Array, Simulation, Sorting | π’ Easy |
3005 | Count Elements With Maximum Frequency | Array, Counting, Hash Table | π’ Easy |
3019 | Number of Changing Keys | String | π’ Easy |
3028 | Ant on the Boundary | Array, Simulation, Prefix Sum | π’ Easy |
3046 | Split the Array | Array, Hash Table, Counting | π’ Easy |
3074 | Apple Redistribution into Boxes | Array, Greedy, Sorting | π’ Easy |
3095 | Shortest Subarray With OR at Least K I | Array, Bit Manipulation, Sliding Window | π’ Easy |
3099 | Harshad Number | Math | π’ Easy |
3110 | Score of String | String | π’ Easy |
3120 | Count the Number of Special Characters I | Hash Table, String | π’ Easy |
3136 | Valid Word | String | π’ Easy |
3151 | Special Array I | Array | π’ Easy |
3158 | Find the XOR of Numbers Which Appear Twice | Array, Bit Manipulation, Hash Table | π’ Easy |
3162 | Find the Number of Good Pairs I | Array, Hash Table | π’ Easy |
3168 | Minimum Number of Chairs in a Waiting Room | Simulation, String | π’ Easy |
3174 | Clear Digits | Hash Table, Simulation, String | π’ Easy |
3194 | Minimum Average of Smallest and Largest Elements | Array, Sorting | π’ Easy |
3206 | Alternating Groups I | Array, Sliding Window | π’ Easy |
3210 | Find the Encrypted String | String | π’ Easy |
3216 | Lexicographically Smallest String After a Swap | Greedy, String | π’ Easy |
3226 | Number of Bit Changes to Make Two Integers Equal | Bit Manipulation | π’ Easy |
3232 | Find if Digit Game Can Be Won | Array, Math | π’ Easy |
3242 | Design Neighbor Sum Service | Array, Hash Table, Matrix, Simulation | π’ Easy |
3248 | Snake in Matrix | Array, Simulation, String | π’ Easy |
3258 | Count Substrings That Satisfy K-Constraint I | Sliding Window, String | π’ Easy |
3264 | Final Array State After K Multiplication Operations I | Array, Math, Simulation | π’ Easy |
3289 | The Two Sneaky Numbers of Digitville | Array, Hash Table, Math | π’ Easy |
3280 | Convert Date to Binary | Math, String | π’ Easy |
3285 | Find Indices of Stable Mountains | Array | π’ Easy |
3270 | Find the Key of the Numbers | Math | π’ Easy |
3274 | Check if Two Chessboard Squares Have the Same Color | Math, String | π’ Easy |
3300 | Minimum Element After Replacement With Digit Sum | Array, Math | π’ Easy |
3304 | Find the K-th Character in String Game I | Bit Manipulation, Math, Simulation | π’ Easy |
Legend:
- BFS - Breadth-First Search
- DFS - Depth-First Search
Solve problems related to other tags and difficulties... π€
Run golangci-lint
command. There is a hidden configuration file for this tool inside root directory .golangci.yml
.
$ golangci-lint --color always run --verbose ./...
$ go test -v ./...
Many solutions contain benchmarks.
$ go test -bench=. -benchmem ./1---Two-Sum
goos: linux
goarch: amd64
cpu: 13th Gen Intel(solutions/R) Core(solutions/TM) i7-13700K
Benchmark_twoSum_Iterations-24 100000000 13.83 ns/op 16 B/op 1 allocs/op
Benchmark_twoSum_Map-24 43644519 25.72 ns/op 16 B/op 1 allocs/op
PASS
The gopher image at the top is taken from: https://github.com/MariaLetta/free-gophers-pack