给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头。 S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。

J 中的字母不重复,J 和 S中的所有字符都是字母。字母区分大小写,因此"a"和"A"是不同类型的石头。

示例 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)
{
int len1 = J.size();
int len2 = S.size();
if(len1 == 0 || len2 == 0)
return 0;
map<char, int> check;
for(int i = 0; i < len1; i++)
{
check[J[i]]++;
}
int res = 0;
for(int i = 0; i < len2; i++)
{
if(check[S[i]] > 0)
res++;
}
return res;
}
};

Leetcode771.Jewels and Stones宝石与石头的更多相关文章

  1. 【LeetCode】Jewels and Stones(宝石与石头)

    这道题是LeetCode里的第771道题. 题目要求: 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝 ...

  2. LeetCode 771. Jewels and Stones (宝石与石头)

    题目标签:Hash Table 这一题很简单,题目给了两个string:J 和 S. 只要把J 里面的 char 放入HashSet,再遍历S找出有多少个石头是宝石. Java Solution: R ...

  3. [LeetCode] Jewels and Stones 珠宝和石头

    You're given strings J representing the types of stones that are jewels, and S representing the ston ...

  4. [LeetCode] 771. Jewels and Stones 珠宝和石头

    You're given strings J representing the types of stones that are jewels, and S representing the ston ...

  5. Leetcode#771.Jewels and Stones(宝石与石头)

    题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...

  6. LeetCode --> 771. Jewels and Stones

    Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...

  7. 【Leetcode】Jewels and Stones

    Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...

  8. Leet Code 771.宝石与石头

    Leet Code编程题 希望能从现在开始,有空就做一些题,自己的编程能力太差了. 771 宝石与石头 简单题 应该用集合来做 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S  ...

  9. 【Leetcode_easy】771. Jewels and Stones

    problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...

随机推荐

  1. jsp中 url传参到后台的参数获取

    datagrid传值url方法1:<input type="hidden" id="sortid"> <table id="dg&q ...

  2. SpringCloud是如何运行的?

    SpringCloud是基于SpringBoot这一高度自动化的应用开发框架,将各类业界比较知名的.得到过实践反馈的开元服务治理相关的技术框架进行优化整合的框架,是一种开发方式的优化和组合,,是一组框 ...

  3. 洛谷P5319 奥术神杖

    题意:给你若干个串和一个填了一部分的串.补完这个串使得 (每个串的匹配次数 * 权值) ^ (1 / 所有串匹配次数) 最大. 解:把这个东西随便取一个对数,就变成了分数规划. 二分.然后在AC自动机 ...

  4. c++设计模式:访问者模式(visitor模式)

    1.c语言中回调基本都过函数指针来完成.c++中主要通过接口的方式完成回调.而visitor就是实现接口回调的一种方式. 1.首先定义个一个接口visitor类, class classVisitor ...

  5. xhEditor 简单用法

    1.下载需要文件包: http://xheditor.com/ 2.解压文件中文件 xheditor-zh-cn.min.js以及xheditor_emot.xheditor_plugins和xhed ...

  6. HDU2056

    /*  * 指数型母函数  */ #include<cstdio> #define mod 100 typedef long long LL;//杭电需用int64 int powerMo ...

  7. 关于python的字符串操作

    字符串的判断操作: str = "fahaf asdkfja\t \r \n fjdhal 3453" print(str.isspace()) # 如果str中只包含空格,则返回 ...

  8. Ubuntu18.04 修改IP地址、查看网关、防火墙

    1. Ubuntu18.04 修改IP地址 修改 sudo vim /etc/netplan/50-cloud-init.yaml文件 # This file is generated from in ...

  9. 2019.9.16 csp-s模拟测试44 反思总结

    虽然说好像没有什么写这个的价值OAO 来了来了来写总结了,不能怨任何东西,就是自己垃圾x 开题顺序又和主流背道而驰,先一头扎进了公认最迷的T2,瞎搞两个小时头铁出来,然后T1和T3爆炸.基础很差,全靠 ...

  10. 配置管理 ACM 在高可用服务 AHAS 流控降级组件中的应用场景

    应用配置管理(Application Configuration Management,简称 ACM)是一款应用配置中心产品.基于ACM您可以在微服务.DevOps.大数据等场景下极大地减轻配置管理的 ...