771.Jewels and Stones
示例 1:
输入: J = "aA", S = "aAAbbbb"
输出: 3
示例 2:
输入: J = "z", S = "ZZ"
输出: 0
注意:
S 和 J 最多含有50个字母。
J 中的字符不重复。class Solution {
public:
int numJewelsInStones(string J, string S) {
unordered_set<char> temp(J.begin(),J.end());
// cout<< temp.count(J[0])<<endl;
int total=0;
for(auto i: S)
total= temp.count(i) ? total+1 : total;
return total;
}
};Last updated