This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tinuURL | |
import ( | |
"crypto/md5" | |
"fmt" | |
"time" | |
"github.com/google/uuid" | |
"github.com/jxskiss/base62" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package binarytree | |
// Tree is a binary tree. | |
type Tree struct { | |
Root *Node | |
} | |
// Invert reverses the binary tree. | |
func Invert(tree *Tree) { | |
_ = InvertFromNode(tree.Root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package slice | |
// For learning purpose only. | |
// Please, use the sort package of Go's Standard library: https://pkg.go.dev/sort | |
// Quicksort sorts the slice `vals` with the | |
// quicksort algorithm. | |
// Time: O(nlogn) | |
// Space: O(logn) | |
func Quicksort(vals []int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package slice | |
// For learning purpose only. | |
// Please, use the sort package of Go's Standard library: https://pkg.go.dev/sort | |
// SelectionSort sorts the slice `vals` with the | |
// selection sort algorithm. | |
// Time: O(n^2) | |
// Space: O(1) | |
func SelectionSort(vals []int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package slice | |
// For learning purpose only. | |
// Please, use the sort package of Go's Standard library: https://pkg.go.dev/sort | |
// InsertionSort sorts the slice `vals` with the | |
// insertion sort algorithm. | |
// Time: O(n^2) | |
// Space: O(1) | |
func InsertionSort(vals []int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package slice | |
// For learning purpose only. | |
// Please, use the sort package of Go's Standard library: https://pkg.go.dev/sort | |
// BubbleSort sorts the slice `vals` with the | |
// bubble sort algorithm. | |
// Time: O(n^2) | |
// Space: O(1) | |
func BubbleSort(vals []int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package slice | |
// BinarySearch searches a `target` value in `nums` | |
// using the "binary search" algorithm. | |
// It returns its position if found or -1 if not found. | |
func BinarySearch(nums []int, target int) int { | |
if len(nums) == 0 { | |
return -1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package matrix | |
// BinarySearch searches `target` in `matrix` | |
// with the "binary search" algorithm. | |
// It returns its position if found or `-1, -1` if not found. | |
func BinarySearch(matrix [][]int, target int) (int, int) { | |
if len(matrix) == 0 || len(matrix[0]) == 0 { | |
return -1, -1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package strings | |
// AreAnagram returns whether string `s` | |
// is an anagram of string `t` (true) or not (false). | |
func AreAnagram(s string, t string) bool { | |
if len(s) != len(t) { | |
return false | |
} | |
set1, set2 := buildMultiSets(s, t) | |
return set1.isEqualTo(set2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package binarytree | |
// Tree is a binary tree. | |
type Tree struct { | |
Root *Node | |
} | |
// Node is a binary tree node. | |
type Node struct { | |
Val int |
OlderNewer