Leetcode Note: Go - Destination City

Destination City - LeetCode
https://leetcode.com/problems/destination-city/

  • Go 言語で取り組んだメモ

回答

Java and Golang solution with explanation and different ideas - Destination City - LeetCode
https://leetcode.com/problems/destination-city/solutions/973311/java-and-golang-solution-with-explanation-and-different-ideas/

func destCity(paths [][]string) string {
	start := make(map[string]int)
	destination := make(map[string]int)

	for _, path := range paths {
		if destination[path[0]] == 1 {
			delete(destination, path[0])
		} else {
			start[path[0]] = 1
		}
		if start[path[1]] == 1 {
			delete(start, path[1])
		} else {
			destination[path[1]] = 1
		}
	}
	
	for s, _ := range destination {
		return s
	}
	return ""
}