Clover Blog

Love Piano, Love Roller Coaster

LeetCode UnionFind template

UnionFind in Java and relevant questions

UF Java Template Quick Union time = O(n^2) each union is O(n) if connect n items, the total time = O(n^2) space = O(n) class UF { private int count; private int[]...

Lambda Expression

Sort function, Compare function

Collections sort compare must return int when override For example, we define a new class Book Use lambda expression Collections.sort(listBooks, (b1, b2) -> (int) (b1.getPrice() - b2...

LeetCode Trie template

Trie in Java and relevant questions

Java Template Trie Template time = O(n) space = O(n) where n is the length of the longest word 208. Implement Trie (Prefix Tree) Array version public class Trie { class TrieNode { ...

LeetCode Appendix

Formular of useful algorithm

GCD of two numbers 辗转相除法 Euclidean algorithm // recursive version public int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } // iterative version int fin...

Network Protocols

What happened when you enter an url?

Basic concepts TCP/IP model layers Add header from the higher leyer to the lower layer Process of data transmission ...

LeetCode Topological Sort template

Topological Sort in Java and relevant questions

Java Template Use adjacent list for graph Update indegree and outdegree as BFS graph traversal time = O(E+V) space = O(E+V) 207. Course Schedule class Solution { public boolean canFini...

LeetCode Dijkstra template

Dijkstra in Java and relevant questions

Java Template Use priority Queue for BFS graph traversal time = O((E+V)logV) = O(ElogV) space = O(V) Leetcode 743. Network Delay Time class Solution { class Pair { int val; ...

JAVA version control

Switch Java version in Mac OS

Steps of Java version switch: Under some situations, we need to switch from the latest java version (e.g. java11) to olders and more stable versions (e.g java8) to compile with some libraries. Ste...

LeetCode Record Summary

first 300 round one

Record of Submissions # Name & Solution Difficulty Hint 1 Two Sum Easy (hashMap) 3 Longest Substr...

Git Tutorial (转载+总结)

Git concepts and steps

Start your git following instructions below Work dict, stage and master name function work dict What you can see in your computer ...