string에 filter를 사용해서 Character와 동일한 배열의 count를 구하면 된다.
// Qustion.
// You are given two strings s and t.
// String t is generated by random shuffling string s and then add one more letter at a random position.
// Return the letter that was added to t.
class Solution {
func findTheDifference(_ s: String, _ t: String) -> Character {
for c in t {
if s.filter({ $0 == c }).count != t.filter({ $0 == c }).count {
return c
}
}
// default value
return Character("a")
}
}