• Leetcode 771. 宝石与石头(可以,一次过)


    在这里插入图片描述
    给你一个字符串 jewels 代表石头中宝石的类型,另有一个字符串 stones 代表你拥有的石头。 stones 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。

    字母区分大小写,因此 "a" 和 "A" 是不同类型的石头。

    示例 1:

    输入:jewels = "aA", stones = "aAAbbbb"
    输出:3
    

    示例 2:

    输入:jewels = "z", stones = "ZZ"
    输出:0
    

    提示:

    • 1 <= jewels.length, stones.length <= 50
    • jewels 和 stones 仅由英文字母组成
    • jewels 中的所有字符都是 唯一的

    Code:

    class Solution {
    public:
        int numJewelsInStones(string jewels, string stones) {
            map<int,char>mymap;
        
            for(int i=0;i<jewels.size();i++)
            {
                mymap[i]=jewels[i];
            }
            int res=0;
            for(int i=0;i<mymap.size();i++)
            {
                res+=count(stones.begin(),stones.end(),mymap[i]);
            }
            return res;
        }
    };
    
  • 相关阅读:
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    How to build and run ARM Linux on QEMU from scratch
    How to debug Android Native Application with eclipse
  • 原文地址:https://www.cnblogs.com/xiaohai123/p/16317753.html
Copyright © 2020-2023  润新知