771. Jewels and Stones
Input: J = "aA", S = "aAAbbbb"
Output: 3Input: J = "z", S = "ZZ"
Output: 0// Hashset
int numJewelsInStones(string J, string S) { // time: O(m + n); space: O(n)
unordered_set<char> jewel(J.begin(), J.end());
int res = 0;
for (char c : S) {
if (jewel.count(c)) ++res;
}
return res;
}Last updated