题目标签: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. Django基础之创建程序

    环境配置 安装python35 安装django:pip install django==1.9.5 创建django程序 1.命令行创建django程序 A django-admin startpr ...

  2. (转)WKT转换工具terraformers

    http://blog.csdn.net/gisshixisheng/article/details/53150111 概述: 前面的文章中,提到了Arcgis中实现wkt转换为geometry,但是 ...

  3. Xamarin View获取属性的绑定信息

    public static Binding GetBinding( BindableObject self, BindableProperty property) { var methodInfo = ...

  4. 14XML解析

    XML解析 XML解析 DOM4J DOM4J是dom4j.org出品的一个开源XML解析包Dom4j是一个易用的.开源的库,用于XML,XPath和XSLT的解析及相关应用.它应用于Java平台,采 ...

  5. 在添加新内容时,creatat没有数据

    首先找到controller中的add方法,然后是执行了Service.insert()方法 然后找到service对应的impl方法, impl方法中的 public void insert(Cus ...

  6. springmvc学习及源码地址

    http://jinnianshilongnian.iteye.com/blog/1634096

  7. 个人Linux(ubuntu)使用记录——更换软件源

    说明:记录自己的linux使用过程,并不打算把它当作一个教程,仅仅只是记录下自己使用过程中的一些命令,配置等东西,这样方便自己查阅,也就不用到处去网上搜索了,所以文章毫无章法可言,甚至会记录得很乱 s ...

  8. iconfig1

    #include<iostream> using namespace std; //测试 template 里面是否还可以有 template class alloc{ }; templa ...

  9. 爬虫之BeautifulSoup库

    文档:https://beautifulsoup.readthedocs.io/zh_CN/latest/ 一.开始 解析库 # 安装解析库 pip3 install lxml pip3 instal ...

  10. java 十三周总结