문제
Python Code
def solution(name, yearning, photo):
name_yearning = dict(zip(name, yearning))
result = []
for p in photo:
total_score = 0
for person in p:
if person in name_yearning:
total_score += name_yearning[person]
result.append(total_score)
return result
Go Code
func solution(name []string, yearning []int, photo [][]string) []int {
m := make(map[string]int)
for i, p := range name {
m[p] = yearning[i]
}
s := make([]int, len(photo))
for i, pic := range photo {
for _, p := range pic {
s[i] += m[p]
}
}
return s
}
결과
문제출처 & 깃허브
programmers
Github