Guest User

Untitled

a guest
Jun 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class Solution {
  2. func numJewelsInStones(_ J: String, _ S: String) -> Int {
  3. var jewelsWithCount = [Character: Int]()
  4. for jewel in J {
  5. jewelsWithCount.updateValue(0, forKey: jewel)
  6. }
  7. for stone in S {
  8. if let jewelCount = jewelsWithCount[stone] {
  9. jewelsWithCount[stone] = jewelCount + 1
  10. }
  11. }
  12. return jewelsWithCount.reduce(0) { $0 + $1.value }
  13. }
  14. }
Add Comment
Please, Sign In to add comment