Tag: Golang
-
[Go & MySQL] parseTime option
Intro When working with MySQL databases in Go, handling DATE, DATETIME, and TIMESTAMP fields can sometimes lead to confusion, especially when dealing with time parsing. By default, Go’s MySQL driver treats date and time fields as []uint8 (byte slices) unless explicitly configured to handle them as time.Time. This behavior can cause issues if you’re expecting…
-
[Go] How to deal with sort and heap (2)
1. Quick Recap In the previous post, we explored the concept of interfaces and how the sort package utilizes them. Understanding the abstract role that interfaces play, independent of specific implementations, was crucial. This abstraction allowed us to work with various types by tying them to the same interface, enabling them to be passed as…
-
[Go] How to deal with sort and heap (1)
1. Understanding Interface 1-a. What is an interface Before we take a look at sort and heap packages, we have to understand what Interface is and how it works. We use Interface to maintain flexible code. Instead of relying on concrete implementations, interfaces allow you to work with abstract method sets, enabling you to apply…
-
[LeetCode] 1062. Longest Repeating Substring
Description Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2: Input: s = “bbbbb” Output: 1 Explanation: The answer is “b”, with the length of 1. Example 3: Input: s = “pwwkew” Output:…
-
[Go] what is a time in go
Time is an agreement We often take time for granted, considering it as omnipresent and essential as air. Yet, when it comes to programming, handling time can be surprisingly complex. The Go programming language provides a robust time package to manage these complexities efficiently. Let’s take a simple look at the ‘Time’ struct. The wall…
-
[LeetCode] 271. Encode and Decode Strings
Description Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings. Machine 1 (sender) has the function: string encode(vector<string> strs) { // … your code return encoded_string; } Machine 2 (receiver) has the function: vector<string> decode(string s)…
-
[LeetCode] 49. Group Anagram
Description Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: strs = [“eat”,”tea”,”tan”,”ate”,”nat”,”bat”] Output: [[“bat”],[“nat”,”tan”],[“ate”,”eat”,”tea”]] Example 2: Input: strs = [“”] Output: [[“”]]…
-
[Leetcode] 217. Contains Duplicate
Problem Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true Constraints: Explanation The simplest approach involves iterating twice through the array to…
-
[Javascript] Closure
What is a Closure? In simple terms, an inner function captures the context of the outer function. But, what is a context? The context refers to the environment in which a function is declared. This environment includes any variables, parameters, and functions that are within the scope of the function when it is defined. When…