Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
-
- var str = "abcabcaaa"
- var count = [String: Int]()
-
- for char in str {
- let c = String(char)
- if count[c] != nil {
- count[c] = count[c]! + 1
- } else {
- count[c] = 1
- }
- // if let tempCount = count[c] {
- // tempCount[c] = tempCount[c]! + 1
- // } else {
- // tempCount[c] = 1
- // }
- }
-
- let sortedKeys = (count as NSDictionary).keysSortedByValue(using: #selector(NSNumber.compare(_:)))
- let key = sortedKeys.last! as! String
- print(key)
- print(count[key]!)
Add Comment
Please, Sign In to add comment