Hello World!

 Hello World!




func CommonCharacters(strings []string) []string {
	charCount := make(map[rune]int)

	for _, str := range strings {
		for _, chr := range withoutDuplicates(str) {
			charCount[chr]++
		}
	}

	result := make([]string, 0)
	for char, count := range charCount {
		if count == len(strings) {
			result = append(result, string(char))
		}
	}
	return result
}

func withoutDuplicates(s string) string {
	var res []rune
	marks := make(map[rune]bool)

	for _, v := range s {
		if _, ok := marks[v]; !ok {
			res = append(res, v)
		}
		marks[v] = true
	}

	return string(res)
}

Comments