leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0771.cpp (471B)


      1 class Solution {
      2   public:
      3     int numJewelsInStones(const string &jewels, const string &stones) const {
      4         static const auto convert = [](char c) { return isupper(c) ? c - 'A' : c - 'a' + 26; };
      5 
      6         static int seen[52];
      7         int res = 0;
      8 
      9         memset(seen, 0x00, sizeof(seen));
     10         for (const char c : jewels)
     11             seen[convert(c)] = true;
     12         for (const char c : stones)
     13             res += seen[convert(c)];
     14 
     15         return res;
     16     }
     17 };