MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / newGraph

Function newGraph

tasks/332.go:30–55  ·  view source on GitHub ↗
(tickets [][]string)

Source from the content-addressed store, hash-verified

28type Graph map[string]*Queue
29
30func newGraph(tickets [][]string) *Graph {
31 g := make(Graph)
32
33 // edges init
34 ensureArray := func(node string) {
35 if _, ok := g[node]; !ok {
36 q := &Queue{}
37 g[node] = q
38 }
39 }
40
41 // edges add
42 for _, tiket := range tickets {
43 from, to := tiket[0], tiket[1]
44 ensureArray(from)
45 ensureArray(to)
46 *g[from] = append(*g[from], to)
47 }
48
49 // edges sort
50 for _, node := range g {
51 sort.Strings(*node)
52 }
53
54 return &g
55}
56
57func (g *Graph) dfs(itinerary *[]string, from string) {
58 q := (*g)[from]

Callers 1

findItineraryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected