Created
August 16, 2017 09:15
-
-
Save luojiyin1987/aaadd366a909d71d795e1eb05caf2eb7 to your computer and use it in GitHub Desktop.
Minimum Index Sum of Two Lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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