Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created August 16, 2017 09:15
Show Gist options
  • Save luojiyin1987/aaadd366a909d71d795e1eb05caf2eb7 to your computer and use it in GitHub Desktop.
Save luojiyin1987/aaadd366a909d71d795e1eb05caf2eb7 to your computer and use it in GitHub Desktop.
Minimum Index Sum of Two Lists
func findRestaurant(list1 []string, list2 []string) []string {
temp1 := make(map[string]int)
temp2 := make(map[string]int)
temp3 := make(map[string]int)
min := 0
temp :=[]int{}
result := []string{}
for k,v := range list1{
temp1[v]= k
}
for k,v :=range list2 {
temp2[v] =k
}
for _, v := range list1 {
_, ok := temp2[v]
if ok {
temp3[v] = temp1[v] + temp2[v]
temp = append(temp, temp1[v]+temp2[v])
}
}
sort.Ints(temp)
min = temp[0]
for k,v := range temp3{
if v== min {
result = append(result, k)
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment