Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f180899

Browse files
author
Shuo
authored
Merge pull request #803 from openset/develop
A: Destination City
2 parents 5c66166 + 6c3b55f commit f180899

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package problem1436
2+
3+
func destCity(paths [][]string) string {
4+
m := make(map[string]bool)
5+
for _, path := range paths {
6+
m[path[0]] = true
7+
}
8+
for _, path := range paths {
9+
if !m[path[1]] {
10+
return path[1]
11+
}
12+
}
13+
return ""
14+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package problem1436
2+
3+
import "testing"
4+
5+
type testType struct {
6+
in [][]string
7+
want string
8+
}
9+
10+
func TestDestCity(t *testing.T) {
11+
tests := [...]testType{
12+
{
13+
in: [][]string{
14+
{"London", "New York"},
15+
{"New York", "Lima"},
16+
{"Lima", "Sao Paulo"},
17+
},
18+
want: "Sao Paulo",
19+
},
20+
{
21+
in: [][]string{
22+
{"B", "C"},
23+
{"D", "B"},
24+
{"C", "A"},
25+
},
26+
want: "A",
27+
},
28+
{
29+
in: [][]string{
30+
{"A", "Z"},
31+
},
32+
want: "Z",
33+
},
34+
{
35+
in: [][]string{
36+
{"A", "B"},
37+
{"B", "A"},
38+
},
39+
want: "",
40+
},
41+
}
42+
for _, tt := range tests {
43+
got := destCity(tt.in)
44+
if got != tt.want {
45+
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
46+
}
47+
}
48+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /