给定字符串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. linux负载均衡(什么是负载均衡)

    linux负载均衡(什么是负载均衡) 一.总结 一句话总结: 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用 ...

  2. skyline中遍历fly工程树

    在skyline二次开发过程中,做空间分析总是要去读取工程中的shp图层.假设想获取工程树中“建筑物”图层,图层结构如下: 传统的方法是: var itemId=SGWorld.ProjectTree ...

  3. name和value的简单js用法

    name和value: 例如: <input type="text" name="txt"/> name用于定义这个input收到的值的变量名,在上 ...

  4. Scrapy下载器中间件实现随机请求头和代理ip

    一.设置随机请求头 class UAMiddleWare(object): UA_LIST = [ 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; ...

  5. js 中直接调用和new的区别

    var test = new Test(); // 这里的 test 是什么?  是一个 Test 对象吗?错!这里 test 是一个函数——Test 中返回的 function() { return ...

  6. Leetcode199. Binary Tree Right Side View二叉树的右视图

    给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值. 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 先求深度,中 ...

  7. Leetcode106. Construct Binary Tree from Inorder and Postorder Traversal中序后续构造二叉树

    根据一棵树的中序遍历与后序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 例如,给出 中序遍历 inorder = [9,3,15,20,7] 后序遍历 postorder = [9,15, ...

  8. Django--多对多表的创建、contentType、ajax、ajax传输json数据格式、ajax传输文件数据、 自定义分页器

    MTV与MVC(了解): MTV模型(Django用的就是MTV): M:模型层(models.py) T:templates C:views MVC模型: M:模型层(models.py) V:视图 ...

  9. oracle-PL/SQL1

    PL/SQL程序设计 一 PL/SQL简介 到目前为止,在数据库上一直使用单一的SQL语句进行数据操作,没有流程控制,无法开发复杂的应用.Sql是结构化语言; Oracle PL/SQL语言(Proc ...

  10. hive-hbase表的建立

    HIVE-HBASE表CDH4的时候不成熟select*的时候会查询不出(必须通过字段名称),CDH5已经修复这点需要注意 接口表hive部分一般不做join select会占性能,因为hbase接口 ...