/// The approach is about counting the number of each character and verifies if exists zero or one
/// character with odd number of repetitions.
func hasPalindromePermutation(in theString: String) -> Bool {
// dictionary with chars and their repetitions in theString.
var charsRepDic: [Character: Int] = [:]
let val = Array(theString)
val.forEach { char in
let currentRep = charsRepDic[char] ?? 0
charsRepDic[char] = currentRep+1
}
// the first odd char was found
var hasAnOddChar: Bool = false
for key in charsRepDic.keys {
if charsRepDic[key]! % 2 != 0 {
if hasAnOddChar {
return false
} else {
hasAnOddChar = true
}
}
}
return true
}