Guest User

Untitled

a guest
Dec 11th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import UIKit
  2. var str = "abcabcaaa"
  3. var count = [String: Int]()
  4. for char in str {
  5. let c = String(char)
  6.  
  7. if count[c] != nil {
  8. count[c] = count[c]! + 1
  9. } else {
  10. count[c] = 1
  11. }
  12. // if let tempCount = count[c] {
  13. // tempCount[c] = tempCount[c]! + 1
  14. // } else {
  15. // tempCount[c] = 1
  16. // }
  17.  
  18. }
  19. let sortedKeys = (count as NSDictionary).keysSortedByValue(using: #selector(NSNumber.compare(_:)))
  20. let key = sortedKeys.last! as! String
  21. print(key)
  22. print(count[key]!)
Add Comment
Please, Sign In to add comment