LEEDCODE 771宝石与石头

LEEDCODE 771宝石与石头_第1张图片

class Solution {
public:
    int numJewelsInStones(string jewels, string stones) {
        std::set<char> myset;
        int i = 0;
        int len_j = jewels.length();
        int len_s = stones.length();
        int count = 0;

        for(int i = 0; i < len_j; i++)
        {
            myset.insert(jewels[i]);
        }
        for(int i = 0; i < len_s; i++)
        {
            std::set<char>::iterator it = myset.find(stones[i]);
            if(it != myset.end())
            {
                count +=1;
            }
        }
        return count;
    }
};

LEEDCODE 771宝石与石头_第2张图片

你可能感兴趣的:(java,开发语言)