Guest User

Untitled

a guest
Oct 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. class FrequencySort {
  2. func frequencySort(_ s: String) -> String {
  3. var ans = ""
  4. var items:[Character:Int] = [:]
  5. for i in s{
  6. items[i] = items[i] == nil ? 1 : items[i]!+1
  7. }
  8.  
  9. let itemResult = items.sorted { (first: (key: Character, value: Int), second: (key: Character, value: Int)) -> Bool in
  10. return first.value > second.value
  11. }
  12.  
  13. for bas in itemResult{
  14. for _ in 0..<bas.value{
  15. ans.append(bas.key)
  16. }
  17. }
  18. return ans
  19. }
  20. }
Add Comment
Please, Sign In to add comment