-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution1436.go
More file actions
40 lines (35 loc) · 821 Bytes
/
solution1436.go
File metadata and controls
40 lines (35 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package solution1436
// ============================================================================
// 1436. Destination City
// URL: https://leetcode.com/problems/destination-city/
// ============================================================================
/*
$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/1436---Destination-City
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_destCity-24 33474986 35.79 ns/op 0 B/op 0 allocs/op
PASS
*/
func destCity(paths [][]string) string {
m := make(map[string]int)
for _, v := range paths {
src := v[0]
dst := v[1]
_, ok := m[dst]
if !ok {
m[src] = 1
} else {
m[src]++
}
}
for _, v := range paths {
dst := v[1]
_, ok := m[dst]
if !ok {
return dst
}
}
return ""
}