Skip to content

Kaminyou/MyLeetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

LeetCode user kaminyou LeetCode user kaminyou LeetCode user kaminyou

MyLeetcode

Problem list

Simple coding

Recursive

String

Rabin-Karp

KMP

Array

Prefix sum

Interval

Bucket sort

Difference array

Matrix

Misc

Prefix sum

Difference matrix

Linked list

Two pointers

Backtracking

BFS

DFS

Disjoint set

Hash

Stack

Monotonic stack

Queue

Deque

Monotonic deque

Tree

Quad Tree

Self balanced tree

Multiset

Heap

Graph

Dijkstra's algorithm

Bellman-Ford algorithm

Topological sort

Tarjan's algorithm

Hierholzer's algorithm

Minimum Spanning Tree

Floyd-warshall

Binary search

Longest Increasing Subsequence

Dynamic programming

MISC

Divide and conquer

Bit operation

Trie

Binary Index Tree (Fenwick tree)

Segment tree

Lazy segment tree

Geometry

Andrew’s Monotone Chain

System design

Special

De Bruijn sequence with Eulerian Circuit

Boyer-Moore Voting Algorithm

Kadane's algorithm

Sieve of Eratosthenes

Binary lifting

Math

Prime

Bézout's identity

Algorithm R (for Reservoir sampling)

Qubit

Learning materials

Tricks

// to iterate subset
for (int subset = state; subset; subset = (subset - 1) & state) {}
// to get difference set
int differentSet = state ^ subset;
// A is B's subset?
bool isSubset = (A & B) == A;
// to remove the rightest 1 (e.g., 0100100 & 0111011 -> 0100000)
x = x & (x - 1)

Combinations with module

long long mod = 1e9 + 7;
long long inv(long long a) {
    if (a == 1) return 1;
    return (mod - mod / a) * inv(mod % a) % mod;
}
int comb(int n, int k) {
    long long res = 1L;
    for (int i = 0; i < k; ++i) {
        res = res * (n - i) % mod;
        res = res * inv(i + 1) % mod;
    } 
    return (int)(res % mod);
}