[Leetcode] 771. Jewels and Stones 解题报告

LeetCode 771. 宝石与石头Jewels and Stones 题目描述 阅读详情

题目:

You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in Sis a type of stone you have.  You want to know how many of the stones you have are also jewels.

The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

Example 1:

Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:

Input: J = "z", S = "ZZ"
Output: 0

Note:

  • S and J will consist of letters and have length at most 50.
  • The characters in J are distinct.

思路:

练手题目。不过本题除了用哈希表之外,还可以用二分查找树以及向量等数据结构解决,J中的数量不同,将会导致不同的数据结构具有不同的运行效率。

代码:

class Solution {
public:
    int numJewelsInStones(string J, string S) {
        unordered_set<char> hash;
        for (auto j : J) {
            hash.insert(j);
        }
        int ans = 0;
        for (auto s : S) {
            ans += hash.count(s);
        }
        return ans;
    }
};
LeetCode --- 771. Jewels and Stones 解题报告 You're given stringsJrepresenting the types of stones that are jewels, andSrepresenting the stones you have. Each character inSis a type of stone you have. You want to know how many of the stones you have are also jewels. The letters inJare guar... 阅读详情

相关推荐

给jetson nano 安装AX200网卡驱动

几经波折,因为在网上看到的基本都是amd版本而非arm版,然后最终选定V5.5是因为更新的几个版本的arm版本是false的(在https://kernel.ubuntu.com/~kernel-ppa/mainline/处选择版本时,得看在arm64上是false还是build succeeded,之前没经验呀刚刚才顿悟的) 1,参考文章https://blog.csdn.net/MIRANA0/article/details/106696334 学到了得下载如下四个: wget https://k

发嘎嘎的博客 2345

[Leetcode] 771. Jewels and Stones

Description: You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how m...

Peggy_Chang的博客 623

OCV/AOCV/SOCV的介绍和应用

library中的cell delay是在某个固定的PVT(operating condition)下仿真得出的。,cell的delay并不是一个固定值,而是一个随机值,遵循高斯分布或门特卡洛分布,在STA中用OCV来模拟这一『特征』。OCV全称on chip variation,用于描述不同管子间由于工艺偏差、电压降、温度变化引起的delay变化。,也用于描述工艺偏差引起的net厚度宽度的变化从而导致net的电容电阻变化。优点:设置起来比较简单粗暴,对于不那么先进的工艺可行!的影响,更贴合实际。

m0_61003348的博客 8979

[Leetcode从零开刷]771. Jewels and Stones

Jewels and Stones leetcode 题目 You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. ...

legalhighhigh的博客 3653

C++上机——2023年“信息与未来”小学生编程思维展示官方题解

本次活动前三题是“根据问题描述实现代码”类型的问题,题解和示例代码由人工智能GPT-4直接阅读题面后生成――只要熟悉C++的语法和基本的编程、调试,即可解决p1、p2、p3。后三题有一定的算法性,我们给出命题思路和一些可能的解法。注意:本题解是面向指导教师的;指导教师在讲解时可以根据学生掌握程度进行调整。

qq_39127687的博客 2296

从稳压管到LDO芯片:一张图看懂线性电源的‘内卷’进化史

本文追溯了从稳压管到LDO芯片的线性电源技术进化历程,详细解析了各阶段的技术突破与局限。重点探讨了现代LDO在超低功耗、高精度控制等方面的创新,并提供了实战选型的黄金法则,帮助工程师在电子设备小型化与低功耗化趋势中做出最优选择。

weixin_42525551的博客 204

LeetCode之771:Jewels and Stones

1. 解法1 (遍历比较,时间复杂度O(J*S),空间复杂度O(1)) 1.1 C#代码 public class Solution { public int NumJewelsInStones(string J, string S) { int Jlen = J.Length; int Sle...

如切如磋,如琢如磨 468

1、CUDA 编程基础

GPU计算的发展历程与重要性。首先回顾了计算机技术的发展,特别是摩尔定律的影响,强调了计算能力的快速提升。然而,随着晶体管尺寸的缩小和频率的停滞,单线程性能增长放缓。为了继续提升性能,多核处理器开始普及,促使软件开发者开始考虑并行计算。介绍了延迟导向设计和吞吐量导向设计的概念,CPU和GPU分别代表了这两种设计方法。GPU是吞吐量导向的,拥有众多弱小的ALU,通过流水线处理提高算术吞吐量。GPU的成功在于其高并行性和高吞吐量,以及能够分摊高昂的固定成本的大量销售额。

Justinyh的博客 579

【leetcode】771. Jewels and Stones

一、题目描述 You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in S is a type of stone you have.  You want to know how m

小拳头的博客 945

【教程4>第1章>第11节】使用MATLAB快速产生批量verilog语句加快FPGA开发

...........如果手动写,那么就非常麻烦,这个时候,我们借助matlab,则可以快速生成上述类型的verilog程序,我们编写如下的MATLAB语句。\n");\n");end。

FPGA/MATLAB学习教程/源码/项目合作开发 1239

核磁共振常用的文件格式介绍:NIfTI volume 格式 (*.nii), GIFTI 格式 (*.gii), CIFTI 格式 (*.nii)

NIfTI volume 格式 (*.nii)GIFTI 格式 (*.gii)CIFTI 格式 (*.nii)Scene file文件 (*.scene)规格文件 (*.spec)解剖 (*.annot)一个场景文件包含一个或多个场景;每个场景实际上是保存时 wb_view 内部状态的快照。这包括有关加载哪些文件、如何显示、如何配置选项卡的信息(选择了哪些表面、在每个层中选择了哪些文件、打开了哪些层、哪些视图旋转、调色板设置、平铺选项卡等),以及在它们上面添加了哪些注释(文本、箭头、圆圈等)。

从事脑科学核磁共振方法学研究,在Nature communications等权威期刊发表研究论文,熟练掌握磁共振处理方法和统计学方法,欢迎大家和我交流。 3042

771. Jewels and Stones

https://leetcode.com/problems/jewels-and-stones/description/题解:You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in Sis a...

Y992yu的博客 240

【定位模块项目实战】正态分布变换(NDT)定位及建图(依赖高精度点云地图和三维激光雷达的定位方案)

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、正态分布变换(NDT)定位解决的主要问题二、正态分布变换(NDT)定位的核心思想三、NDT算法流程1.多元正态分布概念2.网格化并计算正态分布参数3.变换参数和最大似然四、使用C++实现NDT配准参考资料 前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对依赖高精度地图和激光雷达的定位技术–正态分布变换(NDT)定位做个简单的介绍,具体

qq_35635374的博客 4411

【LeetCode】771. Jewels and Stones 解题报告

【LeetCode】771. Jewels and Stones 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/jewels-and-stones/description/ 题目描述: You’re given strings J representing the types of stones that ar

负雪明烛 4122

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LeetCode 771 Jewels and Stones 解题报告

题目要求 You're given stringsJrepresenting the types of stones that are jewels, andSrepresenting the stones you have. Each character inSis a type of stone you have. You want to know how many of t...

weixin_30466953的博客 144

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

LeetCode刷题:771. Jewels and Stones

LeetCode刷题:771. Jewels and Stones 原题链接:https://leetcode.com/problems/jewels-and-stones/ You're given stringsJrepresenting the types of stones that are jewels, andSrepresenting the stones you hav...

梅森上校的博客 业精于勤荒于嬉,形成于思毁于随。 626

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

771. Jewels and Stones*

771. Jewels and Stones* https://leetcode.com/problems/jewels-and-stones/ 题目描述 You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each cha...

珍妮的选择的博客 601

LeetCode //C - 771. Jewels and Stones

This problem counts how many stones are also jewels given two strings. The solution uses a lookup table (boolean array) to mark jewel characters for O(1) checks. It iterates through stones, counting matches with jewels. The approach efficiently handles cas

Made in Code 1166

Leetcode PHP题解--D1 771. Jewels and Stones

771. Jewels and Stones 由于是按难易度排序的,因此本题是第一题。 题目链接 771. Jewels and Stones 题目分析 从第二个参数S中找第一个参数J 中出现的字符,返回找到的字符个数。 也就是说,第一个参数J是一个需要找的字符的列表。只是拼接成字符串了。 而第二个参数S是被查找的字符串。 简单地说就是要在S里找J。 先把问题简化为J中只有一个字符的情形,因为字符...

weixin_33972649的博客 444

python实现 leetcode 771 jewels and stones

说来惭愧,别人几年前干的事情,拖到今天自己才开始自己的leetcode之路。但是开始就好吧!题目描述不再摘抄。AC率最高的一题,一个寒假都没编程的我开始竟然有些懵,参考了discuss里大神lee215的方法得到结果:class solution: def numofJewels(self,J,S): setJ=set(J) return sum(s in setJ for s in S...

大胖子球花的博客 2504

LeetCode - 771. Jewels and Stones

在LeetCode的算法世界里,771题"Jewels and Stones"以其简洁的题目描述和多样的解法吸引着众多学习者。本题要求我们统计字符串stones中有多少字符同时出现在字符串jewels中,看似简单的问题背后却蕴含着不同的解题思路和性能优化技巧。

Amon的专栏 589

Leetcode学习笔记:#771 Jewels and Stones

Leetcode学习笔记:#771 Jewels and Stones You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. ...

ccystewart的博客 518

leetcode 771. Jewels and Stones(python)

描述 You’re given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters ar

王大呀呀的博客 695

[EASY]771. Jewels and Stones

https://leetcode.com/problems/jewels-and-stones/ 题目Jewels and Stones You're given stringsJrepresenting the types of stones that are jewels, andSrepresenting the stones you have. Each character...

菜鸡养成手册 492
上一篇: [Leetcode] 770. Basic Calculator IV 解题报告
下一篇: [Leetcode] 772. Basic Calculator III 解题报告
魔豆Magicbean
博客等级 码龄19年 146粉丝 742原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值