Leetcode 782 Solution

This article provides solution to leetcode question 782 (jewels-and-stones)

https://leetcode.com/problems/jewels-and-stones

Solution

class Solution {
public:
    int numJewelsInStones(string J, string S) {
        unordered_set<char> jewels;

        for (auto jewel: J)
            jewels.insert(jewel);

        int total = 0;
        for (auto stone: S)
            total += jewels.find(stone) != jewels.end();
        return total;
    }
};