풀이
let word = readLine()!.uppercased()
var splitted: [Character] = []
word.forEach { character in
splitted.append(character)
}
let alphabetSet: Set<Character> = Set(splitted)
var counted: [Character: Int] = [:]
for alphabet in alphabetSet {
let number = splitted.filter { character in
return alphabet == character
}.count
counted[alphabet] = number
}
let filtered = counted.filter { dictionary in
return dictionary.value == counted.values.max()!
}
if filtered.count == 1 {
print(filtered.first!.key)
} else {
print("?")
}
사용한 개념