Skip to content

Solutions to LeetCode problems written in Go programming language

License

Notifications You must be signed in to change notification settings

CodeMonkey80s/GoLeetCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go LeetCode Solutions

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.

Tips & Tricks

Read this document for all tips and tricks that are useful for solving these problems.

Solutions

# 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
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
476 Number Complement Bit Manipulation 🟒 Easy
482 License Key Formatting String 🟒 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
709 To Lower Case String 🟒 Easy
746 Min Cost Climbing Stairs Array, Dynamic Programming 🟒 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
844 Backspace String Compare Simulation, Stack, String, Two Pointers 🟒 Easy
884 Uncommon Words from Two Sentences Hash Table, String 🟒 Easy
944 Delete Columns to Make Sorted Array, String 🟒 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
1309 Decrypt String from Alphabet to Integer Mapping String 🟒 Easy
1313 Decompress Run-Length Encoded List Array 🟒 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
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
2160 Minimum Sum of Four Digit Number After Splitting Digits Greedy, Math, Sorting 🟒 Easy
2185 Counting Words With a Given Prefix Array, String 🟒 Easy
2194 Cells in a Range on an Excel Sheet String 🟒 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
2942 Find Words Containing Character Array, String 🟒 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
3046 Split the Array Array, Hash Table, Counting 🟒 Easy
3099 Harshad Number Math 🟒 Easy
3110 Score of String String 🟒 Easy
3120 Count the Number of Special Characters I Hash Table, 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

Legend:

  • BFS - Breadth-First Search
  • DFS - Depth-First Search

Todo

Solve problems related to other tags and difficulties... πŸ€”

Static Analysis

Run golangci-lint command. There is a hidden configuration file for this tool inside root directory .golangci.yml.

$ golangci-lint --color always run --verbose ./...

Testing

$ go test -v ./...

Benchmarking

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

Credits

The gopher image at the top is taken from: https://github.com/MariaLetta/free-gophers-pack

Releases

No releases published

Packages

No packages published