Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func numJewelsInStones(_ J: String, _ S: String) -> Int {
- var jewelsWithCount = [Character: Int]()
- for jewel in J {
- jewelsWithCount.updateValue(0, forKey: jewel)
- }
- for stone in S {
- if let jewelCount = jewelsWithCount[stone] {
- jewelsWithCount[stone] = jewelCount + 1
- }
- }
- return jewelsWithCount.reduce(0) { $0 + $1.value }
- }
- }
Add Comment
Please, Sign In to add comment