Skip to content

Latest commit

 

History

History
50 lines (45 loc) · 12.4 KB

README.md

File metadata and controls

50 lines (45 loc) · 12.4 KB

leetcode-go

This repository contains my solutions to LeetCode problems. I've been actively practicing to enhance my problem-solving skills and algorithmic knowledge.

leetcode linkedin gmail

leetcode_done_over_total

No. Title Solution Difficulty Note
0001 Two Sum Go [Array] Easy 1. Loop through array as 2d and find the sum of target
2. Return the founded index pair
0002 Add Two Numbers Go [Linked List] Medium 1. Loop through 2 linked list and add the value
2. If the sum is greater than 10, set the value to 0 and add 1 to the next node
3. If the last node is greater than 10, add new node with value 1
0007 Reverse Integer [Go] Easy 1. Loop with x % 10 to get original number from right to left, x = x /10 for shift to the remaining digits
2. add to result with result * 10 to shift result digit from right to left.
0026 Remove Duplicates from Sorted Array Go [Array] Easy 1. loop through nums array then append to new array when it's not duplicate to the latest value in new array
0027 Remove Element Go [Array] Easy 1. loop through array and replace wanted number to 999
2. Sort array
0036 Valid Sudoku Go [Array] Medium 1. Loop through array and check the duplicate number in row, column and 3x3 box
0048 Rotate Image Go [Array, Transpose, Swap] Medium (open cheat) 1. Transpose matrix
2. Swap left and right column
0066 Plus One Go [Array] Easy 1. Loop through array from last index to first index
2. Add 1 to the last index
3. If the value is 10, set the value to 0 and add 1 to the previous index
4. If the first index is 10, set the value to 0 and add 1 to the new index
0136 Single Number Go [Map] Easy 1. Use map to count the number of each element
2. Loop through map and return the key that has value = 1
0137 Single Number II Go [Map] Medium 1. Use map to count the number of each element
2. Loop through map and return the key that has value = 1
0189 Rotate Array Go [Array, Modular] Medium 1. Split array into 2 array by k.
2. Concat it back new order (2nd array + 1st array).
3. modify k % len(nums) to avoid bug when k > len(nums)
0217 Contains Duplicate Go [Array, Map] Easy 1. Use map to check the duplicate number
0260 Single Number III Go [Map] Medium 1. Use map to count the number of each element
2. Loop through map, push key to new array if val == 1
0283 Move Zeroes Go [Array, 2 Pointer] Easy 1. create to 2 index pointer
2. 1st pointer running for find zero index
3. 2nd pointer running to find non-zero index
4. swap data when 2nd pointer is greater than 1st pointer
5. 2nd pointer is always +1 at the end of loop
0383 Ransoms Note Go [Array, Map] Easy 1. Map magazine [char, count]
2. Loop through ransoms note and check char from Magazine map is enough for ransoms note by decrease -1 every time that found char in map
0344 Reverse String Gp [Array] Easy 1. Loop through array and swap the value from first index to last index
2. Loop until first index is greater than last index
0412 Fizz Buzz Go [Array, Modular] Easy 1. Loop through array and push to new array when mod by 3, 5
1342 Number of Steps to Reduce a Number to Zero Go [Math] Easy 1. Loop until result == 0
2. divided by 2 and -1 when result is odd number
3. Count every step of devide and minus operation
1347 Minimum Number of Steps to Make Two Strings Anagram Go [Map] Medium 1. create sMap of s string [char, count] by count the no. of char
2. loop through t string and find char in sMap
3. -1 from count when found (stop minus when 0)
4. return sum of remaining count in the sMap
1480 Running Sum of 1d Array Go [Array] Easy 1. Loop through array start from 2nd index and add previous value to current value
1672 Richest Customer Wealth Go [Array] Easy 1. Loop through array and sum each array then compare to max value