You are viewing a single comment's thread. Return to all comments →
Swift solution
func makeAnagram(a: String, b: String) -> Int { let alphabetic = 26 var countsA = Array(repeating: 0, count: alphabetic) var countsB = Array(repeating: 0, count: alphabetic) for c in a.enumerated() { countsA[Int(c.element.asciiValue! - 97)] += 1 } for c in b.enumerated() { countsB[Int(c.element.asciiValue! - 97)] += 1 } var toBeRemoved = 0 for i in 0..<alphabetic { toBeRemoved += abs(countsA[i] - countsB[i]) } return toBeRemoved }
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
Swift solution