int Algorithm::numJewelsInStones(string J, string S)
{
int nCount = 0;
int nJ = J.length();
int nS = S.length();
map<char, int> mapCount;
map<char, int>::iterator itorKey;
for (int iS = 0; iS < nS; iS++)
{
char chS = S.at(iS);
itorKey = mapCount.find(chS);
if (itorKey != mapCount.end())
{
itorKey->second++;
}
else
{
mapCount.insert(make_pair(chS, 1));
}
}
for (int iJ = 0; iJ < nJ; iJ++)
{
char chJ = J.at(iJ);
itorKey = mapCount.find(chJ);
if (itorKey != mapCount.end())
{
nCount += itorKey->second;
}
}
return nCount;
}