Skip to content

Instantly share code, notes, and snippets.

@CollinShoop
CollinShoop / repair.sh
Created May 29, 2023 22:52
Repair author in commit history
# source: https://www.git-tower.com/learn/git/faq/change-author-name-email
# Used this to transfer authorship from an old github account to a new one.
git filter-branch --env-filter '
WRONG_EMAIL="wrong@example.com"
NEW_NAME="New Name Value"
NEW_EMAIL="correct@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
type RandomizedSet struct {
vStack []int
// maps key to the index in keyStack
vMap map[int]int
}
func Constructor() RandomizedSet {
return RandomizedSet {
vStack: []int{},
func sumZero(n int) []int {
nums := make([]int, n)[0:0]
if n % 2 == 1 {
nums = append(nums, 0)
}
n /= 2
for n > 0 {
nums = append(nums, -n)
nums = append(nums, n)
type OrderedStream struct {
index int
values []string
}
func Constructor(n int) OrderedStream {
return OrderedStream {
index: 0,
values: make([]string, n),
@CollinShoop
CollinShoop / file1.go
Created September 5, 2022 21:45
Java example for Indexing
test
@CollinShoop
CollinShoop / quick_sort.java
Last active March 13, 2022 21:56
[Java] Quick Sort
// https://en.wikipedia.org/wiki/Quicksort
// with upper pivot selection
public static void quickSort(int[] nums) {
qsSub(nums, 0, nums.length-1);
}
private static void qsSub(int[] nums, int lo, int hi) {
// base-case
if (lo >= hi) {
return;
@CollinShoop
CollinShoop / merge_sort.java
Last active March 13, 2022 17:18
[Java] Merge sort
// in-line recursive merge sort
public static void mergeSort(int[] nums) {
subMergeSort(nums, 0, nums.length-1, new int[nums.length]);
}
private static void subMergeSort(int[] nums, int start, int end, int[] swap) {
if (start == end) {
return;
}
// sort sub-lists
int pivot = (start + end) / 2;
func fullJustify(words []string, maxWidth int) []string {
// breakup input words into groups that
// won't exceed max width once spaces are added
lines := [][]string{}
lineWords := []string{}
width := 0
for _, word := range words {
// start new line if word cant fit on the current line
if maxWidth - width - len(lineWords) < len(word) {
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func findLeaves(root *TreeNode) [][]int {
leaves := [][]int{}
func evalRPN(tokens []string) int {
nums := []int{}
push := func(n int) {
nums = append(nums, n)
}
pop := func() int {
n := nums[len(nums)-1]
nums = nums[:len(nums)-1]
return n
}