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".
jewels and stones consist of only English letters.
All the characters of jewels are unique.
Solutions
Solution 1: Hash Table or Array
We can first use a hash table or array \(s\) to record all types of jewels. Then traverse all the stones, and if the current stone is a jewel, increment the answer by one.
Time complexity is \(O(m+n)\), and space complexity is \(O(|\Sigma|)\), where \(m\) and \(n\) are the lengths of the strings \(jewels\) and \(stones\) respectively, and \(\Sigma\) is the character set, which in this problem is the set of all uppercase and lowercase English letters.