You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in S is a type of stone you have.  You want to know how many of the stones you have are also jewels.

The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

Example 1:

Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:

Input: J = "z", S = "ZZ"
Output: 0

Note:

  • S and J will consist of letters and have length at most 50.
  • The characters in J are distinct.
class Solution {
public:
int numJewelsInStones(string J, string S) {
int res=;
map<char,int> m;
for(auto a:J){
m[a]++;
}
for(auto a:S){
if(m[a]!=) res++;
}
return res; }
};

771. Jewels and Stones的更多相关文章

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

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

  2. 【Leetcode_easy】771. Jewels and Stones

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

  3. 771. Jewels and Stones - LeetCode

    Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...

  4. LeetCode --> 771. Jewels and Stones

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

  5. LeetCode 771 Jewels and Stones 解题报告

    题目要求 You're given strings J representing the types of stones that are jewels, and S representing the ...

  6. [LeetCode&Python] Problem 771: Jewels and Stones

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

  7. 【Leetcode】771. Jewels and Stones

    (找了leetcode上最简单的一个题来找一下存在感) You're given strings J representing the types of stones that are jewels, ...

  8. 771. Jewels and Stones珠宝数组和石头数组中的字母对应

    [抄题]: You're given strings J representing the types of stones that are jewels, and S representing th ...

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

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

随机推荐

  1. TextView设置不同字段不同点击事件

    转载自:http://www.apkbus.com/blog-160625-59265.html package com.example.fortextdemo;   import java.util ...

  2. nginx,作为前端的你会多少?

    --现在阅读的你,如果是个FE,相信你不是个纯切图仔.反之,如果是,该进阶了,老铁! 前端的我们,已经不仅仅是做页面,写样式了,我们还需要会做相关的服务器部署.废话不多说,下面就从前端的角度来讲以下n ...

  3. C# 7.0特性

    一.out的形参变量无需再提前声明 befor: "; int numericResult; if (int.TryParse(input, out numericResult)) Cons ...

  4. .net core WebAPI 初探及连接MySQL

    1. 前言 笔者最近跟着微软官方文档学习.net core WebAPI,但发现其对 WebAPI 连接数据库.读取数据库方面讲得不够细致明了.写此文的目的,即实现 .net core WebAPI ...

  5. Django-ORM-单表操作

    ORM字段参数及单表操作 一.字段参数 1.字段 AutoField(Field) #当model中如果没有自增列,则会自动创建一个列名为id的列 -int 自增列,必须填入参数primary_key ...

  6. oracle INS-13001 环境不满足最低要求

    使用windows10等系统安装oracle 11g等版本的数据库时,经常会发现开始安装时弹出[INS-13001 环境不满足最低要求]的提示,此时可以点击[是]继续安装. 也可以点击[否]结束安装, ...

  7. jenkins+git(完全萌新的一篇,求指点)

    自己不熟悉所以打算写一份新手的自我理解,有错误欢迎大家指出 公司使用jenkins和git对代码进行管理 首先我们将代码放在git上,然后通过一些方法(我还不知道啥方法) 将git的代码放在jenki ...

  8. 微信小程序rich-text 文本首行缩进和图片居中

    微信小程序开发使用rich-text组件渲染html格式的代码,常常因为不能自定义css导致文本不能缩进,以及图片不能居中等问题,这里可以考虑使用js的replace方法,替换字符串,然后在渲染的同时 ...

  9. CSV文件导入导mysql数据库

    1.导入 基本语法: load data [low_priority] [local] infile 'file_name txt' [replace | ignore] into table tbl ...

  10. 2018年最新JAVA面试题总结之数据库(3)

    转自于:https://zhuanlan.zhihu.com/p/39804394 1.MySQL的delete与truncate区别? 回答:delete语句执行删除的过程是每次从表中删除一行,并且 ...