LeetCode 771. Jewels and Stones (宝石与石头)
题目标签:Hash Table
这一题很简单,题目给了两个string:J 和 S。 只要把J 里面的 char 放入HashSet,再遍历S找出有多少个石头是宝石。
Java Solution:
Runtime beats 97.77%
完成日期:03/06/2019
关键点:HashSet
class Solution
{
public int numJewelsInStones(String J, String S)
{
int result = 0; Set<Character> jewels = new HashSet<>();
// put Jewels into HashSet
for(char c : J.toCharArray())
{
jewels.add(c);
} // iterate stones to find jewels
for(char c : S.toCharArray())
{
if(jewels.contains(c))
result++;
} return result;
}
}
参考资料:N/A
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
LeetCode 771. Jewels and Stones (宝石与石头)的更多相关文章
- 【LeetCode】Jewels and Stones(宝石与石头)
这道题是LeetCode里的第771道题. 题目要求: 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝 ...
- [LeetCode] 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(宝石与石头)
题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...
- 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 ...
- Leetcode771.Jewels and Stones宝石与石头
给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...
- 771. Jewels and Stones - LeetCode
Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...
- 【Leetcode_easy】771. Jewels and Stones
problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...
- 【Leetcode】Jewels and Stones
Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...
随机推荐
- Ubuntu安装配置Charles,抓取http网络请求包
http://blog.csdn.net/lylddinghffw/article/details/75322262
- Farseer.net轻量级开源框架 入门篇:逻辑层的选择
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 入门篇:增.删.改.查操作演示 下一篇:Farseer.net轻量级开源框架 入门 ...
- 富士康的盈利秒杀99%的A股公司:3星|《三联生活周刊》2018年10期
三联生活周刊·最美的数学:天才为何成群到来(2018年10期) 本期专题是数学和成都,我都跳过去没看.其他内容也还有点意思. 总体评价3星. 以下是本期一些内容的摘抄,#号后面是kindle电子版中的 ...
- extjs动态插入一列
StdDayWordQuery:function(btn,event){ var form=Ext.getCmp('queryFormSDW'); var userNameORuserCode = f ...
- 服务器的部署与Web项目的发布
今天给老师的服务器部署项目,这次是第二次,基于第一次的经验,这次可以说是驾轻就熟. 服务器的系统是Windows Server 2008 R2 (64位) 需要安装的软件是:jdk7.TomCat7. ...
- 十二届 - CSU 1803 :2016(同余定理)
题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Knowledge Point: 同余定理:两个整数a.b,若它们除以整数m所 ...
- 「 poj 2096 」 Collecting Bugs
先说一下题意 $s$ 个子系统还中有 $n$ 种 $\text{bug}$,每天可以随机选择一种 $\text{bug}$,问选出 $n$ 种 $\text{bug}$ 在 $s$ 种子系统中的期望天 ...
- Python学习笔记(3)动态类型
is运算符 ==是值相等而is必须是相同的引用才可以 l=[1,2,3] m=[1,2,3] print(l==m) # True print(l is m) # False sys模块 getref ...
- C语言二叉树的创建、(先中后序)遍历以及存在的问题
#include<stdlib.h> #include<stdio.h> #define True 1 #define False 0 typedef char TElemTy ...
- idea 类图显示
不得不说idea java开发的神器啊,免去了自己画图的很多工作量. 打开类图快捷键:Ctrl+Alt+Shift+U