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 ...
随机推荐
- stm32学习总结)—SPI-FLASH 实验 _
SPI总线 SPI 简介 SPI 的全称是"Serial Peripheral Interface",意为串行外围接口,是Motorola 首先在其 MC68HCXX 系列处理器上 ...
- 从零开始开发一款H5小游戏(三) 攻守阵营,赋予粒子新的生命
本系列文章对应游戏代码已开源 Sinuous game. 每个游戏都会包含场景和角色.要实现一个游戏角色,就要清楚角色在场景中的位置,以及它的运动规律,并能通过数学表达式表现出来. 场景坐标 canv ...
- PhantomJS,隐身浏览器
PhantomJS PhantomJS是一个无界面的浏览器,实现了传统浏览器的所有功能,除了没有界面,因此,这是一个隐身浏览器. PhantomJS官网 API,特别需要注意的是Web Page Mo ...
- 将本地代码上传到gitLab
1. 在远程gitLab仓库创建项目, 执行下列命令 git init git remote add origin git@10.10.xxx.git (gitLab刚刚创建的工程地址) git ...
- Spring配置数据源(连接池)
1.数据源(连接池)的作用:为了提高程序的性能而出现的 2.数据源的原理: *事先实例化数据源,初始化部分连接资源 *使用连接资源时从数据源中获取 *使用完毕后将连接资源归还给数据源 使用c3p0的步 ...
- centos7.3 安装oracle 详细过程
centos7.3安装oracle详细过程1.下载Oracle安装包:linux.x64_11gR2_database_1of2.zip 和 linux.x64_11gR2_database_2of2 ...
- linux中sort、uniq、cut、tr、wc命令的使用
文本处理命令 1.sort命令 使用场景 : 用于将文件内容加以排序(可以和cat一起用) 参数 作用 -n 依照数值的大小排序 -r 以相反的顺序来排序(默认只比较第一个数,-rn是按所有数值比较) ...
- http协议 知识点
前端工程师,也叫Web前端开发工程师.他是随着web发展,细分出来的行业.第一步要学好HTML.CSS和JavaScript!接着就要学习交互,HTTP协议.Tomcat服务器.PHP服务器端技术是必 ...
- 基于全志A40i开发板——Linux-RT内核应用开发教程(1)
目录 1 Linux-RT内核简介 3 2 Linux系统实时性测试 3 3 rt_gpio_ctrl案例 10 4 rt_input案例 15 本文为Linux-RT内核应用开发教程的第一章节--L ...
- 用 GraphScope 像 NetworkX 一样做图分析
NetworkX 是 Python 上最常用的图分析包,GraphScoep 兼容 NetworkX 接口.本文中我们将分享如何用 GraphScope 像 NetworkX 一样在(大)图上进行分析 ...