771. Jewels and Stones - LeetCode
Question

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的更多相关文章
- 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 ...
- 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
(找了leetcode上最简单的一个题来找一下存在感) You're given strings J representing the types of stones that are jewels, ...
- LeetCode 771. Jewels and Stones (宝石与石头)
题目标签:Hash Table 这一题很简单,题目给了两个string:J 和 S. 只要把J 里面的 char 放入HashSet,再遍历S找出有多少个石头是宝石. Java Solution: R ...
- [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 解题报告
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 数组count 字典Counter 日期 题目地址 ...
- 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 ...
随机推荐
- ES6-11学习笔记--Reflect
Reflect 映射 将Object属于语言内部的方法放到Reflect上 修改某些Object方法的返回结果,让其变得更合理 让Object操作编程函数行为 Reflect对象的方法与Proxy对象 ...
- BootstrapBlazor实战 Tree树形控件使用(2)
继续上篇实战BootstrapBlazor树型控件Tree内容, 本篇主要讲解整合Freesql orm快速制作数据库后台维护页面 demo演示的是Sqlite驱动,FreeSql支持多种数据库,My ...
- 【编译原理】自底向上分析方法——LR文法分析方法的总结
LR(0).SLR(1).LR(1).LALR(1) de 若干方面的区别 目录 推导过程 分析能力 本质区别 文法对比 可以适当利用物理意义对二义性文法进行冲突处理 推导过程 LR(0)的基础上才有 ...
- CommonsCollection7反序列化链学习
CommonsCollections7 1.前置知识 Hashtable Hashtable实现了Map接口和Serializable接口,因此,Hashtable现在集成到了集合框架中.它和Hash ...
- Transactional事务,事务嵌套的时候,如果主事务出现问题,子事务执行不需要回滚怎么做?
如果调用的方法在不在同一个service当中,则只需要在子事务当中的方法上方添加注解即可 下方即是:这就话代表:重新开启一个新的事务 @Transactional(propagation = Prop ...
- HTML5的基本功能
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...
- vue 配置scss流程
引入相关的node包 npm install --save style-loader sass-loader node-sass file-loader 安装好之后,为了可以在.vue和.scss中使 ...
- Abp集成HangFire
简要说明 后台作业在系统开发的过程当中,是比较常用的功能.因为总是有一些长耗时的任务,而这些任务我们不是立即响应的,例如 Excel 文档导入.批量发送短信通知等. ABP vNext 提供了后台作业 ...
- [笔记] K-D Tree
一种可以 高效处理 \(k\) 维空间信息 的数据结构. 在正确使用的情况下,复杂度为 \(O(n^{1-\frac{1}{k}})\). K-D Tree 的实现 建树 随机一维选择最中间的点为当前 ...
- 一行代码如何隐藏 Linux 进程?
开源Linux 长按二维码加关注~ 上一篇:IPv6技术白皮书(附PDF下载) 总有朋友问隐藏Linux进程的方法,我说你想隐藏到什么程度,是大隐于内核,还是小隐于用户.网上通篇论述的无外乎 hook ...