You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.

Letters are case sensitive, so "a" is considered a different type of stone from "A".

&nbsp;
Example 1:
Input: jewels = "aA", stones = "aAAbbbb"
Output: 3
Example 2:
Input: jewels = "z", stones = "ZZ"
Output: 0

&nbsp;
Constraints:


	1 &lt;=&nbsp;jewels.length, stones.length &lt;= 50
	jewels and stones consist of only English letters.
	All the characters of&nbsp;jewels are unique.


class Solution:
    def numJewelsInStones(self, jewels: str, stones: str) -> int:
		# 1 : One line solution, My best runtime 38 with 13.9 MB
        return sum(1 for k in stones if k in jewels)
		
		# 2 : Traditional solution
		x=0
		for k in stones:
			if k in jewels:
				x+=1
		return x
class Solution {
    public int numJewelsInStones(String jewels, String stones) {
        HashSet<Character> hs=new HashSet<>();
        int count=0;
        for(int i=0;i<jewels.length();i++)
        {
            hs.add(jewels.charAt(i));
        }
        for(int i=0;i<stones.length();i++)
        {
            if(hs.contains(stones.charAt(i)))
                count++;
        }
        return count;
    }
}
class Solution {
public:
	int numJewelsInStones(string jewels, string stones) {

		unordered_map<char, int> mp;

		for(int i=0 ; i<jewels.size() ; i++){
			mp[jewels[i]]++;
		}

		int ans = 0;
		for(int i=0 ; i<stones.size() ; i++){
			if(mp.find(stones[i]) != mp.end()){
				ans++;
			}
		}

		return ans;
	}
};
var numJewelsInStones = function(jewels, stones) {
    let trackDict = new Map();
    let output = 0;

    for (let char of stones)
        trackDict.set(char, trackDict.has(char) ? trackDict.get(char) + 1 : 1);
    
    for (let char of jewels)
        output += trackDict.has(char) ? trackDict.get(char) : 0;

    return output;
};
Jewels and Stones