题目标签: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 (宝石与石头)的更多相关文章

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

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

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

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

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

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

  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. Leetcode771.Jewels and Stones宝石与石头

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

  7. 771. Jewels and Stones - LeetCode

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

  8. 【Leetcode_easy】771. Jewels and Stones

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

  9. 【Leetcode】Jewels and Stones

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

随机推荐

  1. 学习RFT之:TestObject.find方法的了解与使用

    第一部分:了解TestObject.find 一.TestObject.find方法的作用 1.测试过程中动态的找到测试对象(控件.标签等),使我们的测试用例不再依赖RFT自带的对象地图(Object ...

  2. Context Switches msdn

    Context Switches  https://msdn.microsoft.com/en-us/library/ms682105(VS.85).aspx The scheduler mainta ...

  3. java byte

    项目中有段代码,一直让我疑惑不解,但我是个很会偷懒的人,只要拷贝来改改能用的代码,万万不会自己动手写,虽然一直有疑惑,也懒得搭理是怎么个原理. 直到今天,又要解析协议,又要动这个地方的代码,还是来盘他 ...

  4. ubuntu 16.04 添加网卡

    root@ubuntu:~# ls /sys/class/net/ enp0s3 enp0s8 lo root@ubuntu:~# vim /etc/network/interfaces # This ...

  5. 暴力搜索+散列--P1008 三连击

    题目描述 将1,2, ⋯,9共9个数分成3组,分别组成3个三位数,且使这3个三位数构成1:2:3的比例,试求出所有满足条件的3个三位数. 输入输出格式 输入格式: 木有输入 输出格式: 若干行,每行3 ...

  6. css--小白入门篇1

    一.引入 css用来描述html,学习css前我们先来学习html的基础标签的用法,再进入css的学习. 本教程面向小白对象,不会讲细枝末节深入的东西. 二.列表 列表有3种 2.1 无序列表 无序列 ...

  7. 洛谷——P2090 数字对

    P2090 数字对 题目描述 对于一个数字对(a, b),我们可以通过一次操作将其变为新数字对(a+b, b)或(a, a+b). 给定一正整数n,问最少需要多少次操作可将数字对(1, 1)变为一个数 ...

  8. centos7+VMware Workstation创建共享文件夹

    1.第一步设置宿主机共享文件夹路径 2.挂载VMware Tools,如下操作会将tools以光盘挂载点的方式进入到系统中. 3.centos7 挂载存有VMware Tools的光盘并进行安装 1) ...

  9. MyBatis 的基本要素—SQL 映射文件

    MyBatis 真正的强大在于映射语句,相对于它强大的功能,SQL 映射文件的配置却是相当简单.对比 SQL 映射配置和 JDBC 代码,发现使用 SQL 映射文件配置可减少 50% 以上的代码,并且 ...

  10. linux ifstat-统计网络接口流量状态

    推荐:更多linux 性能监测与优化 关注:linux命令大全 ifstat命令就像iostat/vmstat描述其它的系统状况一样,是一个统计网络接口活动状态的工具.ifstat工具系统中并不默认安 ...