Skip to content

Instantly share code, notes, and snippets.

View magicoder10's full-sized avatar
:octocat:
Focusing

Magic Coder magicoder10

:octocat:
Focusing
View GitHub Profile
@magicoder10
magicoder10 / BasicGit.go
Created July 28, 2022 07:59
Basic Git
package history
import (
"log"
"path"
"tstore/idgen"
"tstore/reliable"
"tstore/storage"
"tstore/types"
@magicoder10
magicoder10 / ebt.go
Created May 10, 2021 05:43
Equivalent Binary Tree
package main
import (
"fmt"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
class LRUCache {
private int capacity;
private int occupied;
private HashMap<Integer, Buffer> refs;
private Buffer head;
private Buffer tail;
public LRUCache(int capacity) {
public class Solution {
/**
* @param stringArray: a string array
* @return: return every strings'short peifix
*/
public String[] ShortPerfix(String[] stringArray) {
// write your code here
if (stringArray == null) {
return new String[]{};
}
class TrieNode {
boolean isWord;
HashMap<Character, TrieNode> children;
TrieNode() {
children = new HashMap<>();
}
}
public class Trie {
public class Solution {
/*
* @param A: An integer matrix
* @return: The index of the peak
*/
public List<Integer> findPeakII(int[][] A) {
// write your code here
if (A == null || A.length < 3 || A[0].length < 3) {
return new LinkedList<>();
}
public class Solution {
/**
* @param str: the string
* @param dict: the dictionary
* @return: return words which are subsequences of the string
*/
public List<String> findWords(String str, List<String> dict) {
// Write your code here.
List<String> words = new LinkedList<>();
if (str == null || str.length() < 1 || dict == null || dict.size() < 1) {
public class Solution {
/**
* @param side_length: the length of a side of the lake (it's a square)
* @param lake_grid: a 2D matrix representing the lake 0= ice, 1= snowbank, -1= hole
* @param albert_row: row of Albert's snowbank
* @param albert_column: column of Albert's snowbank
* @param kuna_row: row of Kuna's snowbank
* @param kuna_column: column of Kuna's snowbank
* @return: a bool - whether Albert can escape
*/
@magicoder10
magicoder10 / Bridges.java
Last active September 24, 2020 06:01
Critical connection
class Solution {
public List<List<Integer>> criticalConnections(int n, List<List<Integer>> connections) {
// write your code here
List<List<Integer>> bridges = new LinkedList<>();
if (n < 1 || connections == null || connections.size() < 1) {
return bridges;
}
// 1. Create edge set
// 2. Build Graph
class Solution {
public List<List<String>> accountsMerge(List<List<String>> accounts) {
List<List<String>> results = new ArrayList<>();
if (accounts == null || accounts.size() < 1) {
return results;
}
HashMap<String, List<Integer>> emailToIds = mapEmailToIds(accounts);
UnionFind unionFind = linkAccounts(accounts, emailToIds);
HashMap<Integer, HashSet<String>> idToEmails = mapIdToEmails(accounts, unionFind);