Question

771. Jewels and Stones

Solution

题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算

思路:Set记录字符串J中的每个字符,遍历S中的字符,如果出现在Set中,count加1

Java实现:

public int numJewelsInStones(String J, String S) {
Set<Character> set = new HashSet<>();
int count = 0;
for (char c : J.toCharArray()) {
set.add(c);
}
for (char c : S.toCharArray()) {
if (set.contains(c)) {
count++;
}
}
return count;
}

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

  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. LeetCode --> 771. Jewels and Stones

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

  4. 【Leetcode】771. Jewels and Stones

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

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

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

  6. [LeetCode] 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 解题报告

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 数组count 字典Counter 日期 题目地址 ...

  8. LeetCode 771 Jewels and Stones 解题报告

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

  9. [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 ...

随机推荐

  1. circle_clock 简单canvas实现圆弧时钟

    渣渣成品图:http://codepen.io/thewindswor... 最近对于圆形有种特别的感情呢...因为写了个cricle_process_bar就像到了用来做时钟大概会比较有趣吧,所以就 ...

  2. 前端面试题整理——关于EventLoop(1)

    下面代码输出打印值顺序: async function async1(){ console.log('async1 start'); await async2(); console.log('asyn ...

  3. 每日学习+AS小相册+导入图片标红的原因

    学习内容: 1.TextView(怎么设置文本). Button(怎么设置按钮事件). ImageView(怎么设置图片) 2.LinearLayout的基本使用 今日成果:做了一个小相册 遇到的问题 ...

  4. C++中的算法头文件<algorithm>,<numeric>和<functional>

    算法部分主要由头文件<algorithm>,<numeric>和<functional>组成.<algorithm>是所有STL头文件中最大的一个,它是 ...

  5. Myeclipse 中怎样更改web项目的访问名

    第一步:在要修改的项目名称上右击选择最下面一列的"prepertise"(属性),进入属性设置界面. 第二步:找到左侧菜单栏的"Myeclipse"中的web项 ...

  6. number(10,6)正则表达式

    /**     * 判断number(10,6)     * @param dateStr     * @return     */    public boolean isNumJW(String ...

  7. Idea导出jar包和使用自定义API

    自定义jar简单实现案例 学习内容 1. 自定义工具类 2. 导出jar 3. 加载Jar包 4. 调用自定义的API方法 总结 学习内容 1. 自定义工具类 新建一个java项目,然后创建包和工具类 ...

  8. 【Python打包成exe方法】——已解决导入第三方包无法打包的问题

    ​ 前言 在我们写代码的过程中,我们开发的脚本一般都会用到一些第三方包,可能别人也需要用到我们的脚本,如果我们将我们的xx.py文件发给他,他是不能直接用的,他还需要安装python解释器,甚至还要安 ...

  9. Wireshark-过滤器-数据包解析

    目录 过滤器 数据包解析 参考 推荐阅读: https://www.cnblogs.com/zwtblog/tag/计算机网络/ 过滤器 显示过滤器 和 捕获过滤器,俩者使用非常类似. 在Wiresh ...

  10. ubuntu下Docker配置阿里云镜像加速

    1.确认正确安装好docker,登录阿里云,打开如下界面 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 2.复制下面那段代码, ...