771. Jewels and Stones
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:
SandJwill consist of letters and have length at most 50.- The characters in
Jare 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的更多相关文章
- Leetcode#771.Jewels and Stones(宝石与石头)
题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...
- 【Leetcode_easy】771. Jewels and Stones
problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...
- 771. Jewels and Stones - LeetCode
Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...
- LeetCode --> 771. Jewels and Stones
Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...
- LeetCode 771 Jewels and Stones 解题报告
题目要求 You're given strings J representing the types of stones that are jewels, and S representing the ...
- [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 ...
- 【Leetcode】771. Jewels and Stones
(找了leetcode上最简单的一个题来找一下存在感) You're given strings J representing the types of stones that are jewels, ...
- 771. Jewels and Stones珠宝数组和石头数组中的字母对应
[抄题]: You're given strings J representing the types of stones that are jewels, and S representing th ...
- LeetCode 771. Jewels and Stones (宝石与石头)
题目标签:Hash Table 这一题很简单,题目给了两个string:J 和 S. 只要把J 里面的 char 放入HashSet,再遍历S找出有多少个石头是宝石. Java Solution: R ...
随机推荐
- verdi\debussy的使用技巧
verdi\debussy的使用技巧 转载from 大西瓜FPGA 大西瓜FPGA-->https://daxiguafpga.taobao.com fsdb display Debussy本身 ...
- day12 函数对象,名称空间与作用域
""" 今日内容: 1.函数参数传值细节 2.三元表达式 3.列表及字典推导式 4.函数对象 5.名称空间与作用域 6.函数的嵌套定义初识 ""&qu ...
- codeforces 1151 B
codeforces 1151 B codeforces 1151 B 1600fen 题意:n*m的矩阵,问能否从n行中每行选一个数 异或 大于0 解析:刚开始看没思路,想用dfs跑一遍,看到 ...
- java学习笔记04-基本数据类型
编写一款可用的软件,离不开对数据的操作(经常有人说:程序=数据+算法).数据可能有很多类型,比如对于年龄来说,数据就是整数. 对于金额来,数据是带小数的.在java中,可以分为内置数据类型和引用数据类 ...
- C# this关键字的四种用法
Go to below URL to find more details and example. http://blog.csdn.net/longlong821/article/details/7 ...
- python学习第37天
MySQL数据库 数据库的优势 什么是数据(Data) 什么是数据库(DataBase,简称DB) 什么是数据库管理系统(DataBase Managerment System 简称DBMS) 数据库 ...
- pip安装mysql-python报错:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-enRreC/mysql-python/
公司业务开发,用python开发网站;需要使用模块MySQLdb. 我直接pip install MySQLdb,当然不成功了,模块名字因该是mysql-python pip install mysq ...
- 算法工程师<深度学习基础>
<深度学习基础> 卷积神经网络,循环神经网络,LSTM与GRU,梯度消失与梯度爆炸,激活函数,防止过拟合的方法,dropout,batch normalization,各类经典的网络结构, ...
- 集腋成裘-11-sql性能优化
SQL Nexus是一个用于将SQL Trace数据.性能监视日志及T-SQL输出整合进一个单独的SQL Server数据库的工具. 先决条件 开始使用SQL Nexus之前,注意下面要做的事项: 安 ...
- python+selenium自动测试之WebDriver的常用API(基础篇二)
本篇介绍一下python+selenium复杂操作的处理,基于python3.6,selenium3.141,详细资料介绍查看官方API文档,点击这里 一.常见特殊情况处理如iframe/弹窗处理 有 ...