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 ...
随机推荐
- 前端进阶(12) - css 的弱化与 js 的强化
css 的弱化与 js 的强化 web 的三要素 html, css, js 在前端组件化的过程中,比如 react.vue 等组件化框架的运用,使 html 的弱化与 js 的强化 成为了一种趋势, ...
- 小程序输入框闪烁BUG解决方案
前言 本人所说的小程序,都是基于mpvue框架而上的,因此BUG可能是原生小程序的,也有可能是mpvue的. 问题描述 在小程序input组件中,如果使用v-model进行双向绑定,在输入时会出现光标 ...
- 大数据学习之路之ambari配置(二)
按照网上的教程配置,发现配置到hadoop虚拟机内存就开始不够了,心累
- 获取iframe引入页面内的元素
在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素.或者在iframe框架中使用父窗口的元素.js在父窗口中获取iframe中的元素1. 格式:window ...
- 前端复制粘贴文字clipBoard.js的使用
1. vue 中的复制粘贴: <div class="mainTextItem" @click="copyTXTOne" id="copyOn ...
- js手机号隐藏中间四位
var tel = "13122223333"; var reg = /^(\d{3})\d{4}(\d{4})$/; tel = tel.replace(reg, "$ ...
- FastAPI(六十六)实战开发《在线课程学习系统》接口开发--用户注册接口开发
在前面我们分析了接口的设计,那么我们现在做接口的开发. 我们先去设计下pydantic用户参数的校验 from pydantic import BaseModel from typing import ...
- 关于allegro找不到env文件解决方法
使用allegro的友人时对于env文件并不陌生.在我们设计的过程中经常使用env文件设置快捷键从而达到快速拉线的目的.但是新安装的allegro软件中会找不到env文件,因为今天自己碰到了这件事,并 ...
- 创建可以运行宿主机GPU的容器
1.安装NVIDIA Container Runtime apt-get参考https://blog.csdn.net/li_ellin/article/details/107180516 yum参考 ...
- Linux小工具的应用,grep,sort,wc,cut
小工具的使用: 1.管道(|):连接多个命令的工具,进程之间通讯的一种方式 用法:命令1 | 命令2 | 命令3....2.grep工具:行过滤,打印出的结果一行一行的 用法:grep options ...