Skip to content

Commit

Permalink
Regenerate leetcode_library.template
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaShkaruba committed Jul 14, 2023
1 parent 2240fec commit 4c75b95
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions build/leetcode_library.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//////////////////////////////////////////////////////////////////////

//////////////////////// Dijkstra high-level ////////////////////////
// You can find this data structure overview in docs/algorithms/dijkstra.md
// You can find this algorithm overview in docs/algorithms/dijkstra.md

// DijkstraToTarget finds the shortest path from sourceId to targetId in a sourceId connected component
func DijkstraToTarget(edges map[int]map[int]int, sourceId int, targetId int) int {
Expand Down Expand Up @@ -86,7 +86,7 @@ type dijkstraEdge struct {


//////////////////////// Eager dijkstra high-level ////////////////////////
// You can find this data structure overview in docs/algorithms/dijkstra.md
// You can find this algorithm overview in docs/algorithms/dijkstra.md

// EagerDijkstraToTarget finds the shortest path from sourceId to targetId in a sourceId connected component
func EagerDijkstraToTarget(edges map[int]map[int]int, sourceId int, targetId int) int {
Expand Down Expand Up @@ -221,6 +221,57 @@ func (h *EagerDijkstraIndexedHeap) getByNodeId(toNodeId int) (dijkstraEdge, bool
return h.values[i], true
}

////////////////////////// Greatest common divider (GCD) //////////////////////////
// You can find this algorithms overview in docs/algorithms/math.md

func GCD(a, b int) int {
for b != 0 {
t := b
b = a % b
a = t
}

return a
}

////////////////////////// Primes factorization //////////////////////////
// You can find this algorithms overview in docs/algorithms/math.md

func GetPrimeFactors(number int, maxNumber int) []int {
sieve := buildPrimeDividers(maxNumber)
primeFactors := make([]int, 0)

for number != 1 {
factor := sieve[number]
for number%factor == 0 {
number /= factor
}

primeFactors = append(primeFactors, factor)
}

return primeFactors
}

func buildPrimeDividers(maxNumber int) []int {
sieve := make([]int, maxNumber+1)

for i := 2; i <= maxNumber; i++ {
if sieve[i] != 0 {
continue
}

sieve[i] = i
for j := i * i; j <= maxNumber; j += i {
if sieve[j] == 0 {
sieve[j] = i
}
}
}

return sieve
}

////////////////////// AVL tree //////////////////////
// You can find this data structure overview in docs/data_structures/avl_tree.md

Expand Down

0 comments on commit 4c75b95

Please sign in to comment.