【leecode】宝石与石头
2024-08-31 08:13:39
给定字符串J
代表石头中宝石的类型,和字符串 S
代表你拥有的石头。 S
中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。
J
中的字母不重复,J
和 S
中的所有字符都是字母。字母区分大小写,因此"a"
和"A"
是不同类型的石头。
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 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"
.
示例 1: 输入: J = "aA", S = "aAAbbbb"
输出: 3
示例1
输入: J = "z", S = "ZZ"
输出: 0
示例2
class Solution:
def __init__(self):
pass
def numJewelsInStones(self, J, S):
"""
输入: J = "aA", S = "aAAbbbb"
输出: 3
:type J: str
:type S: str
:rtype: int
"""
num = 0
for j in list(J):
if j in S:
for s in list(S):
if j == s:
num += 1
return num if __name__ == '__main__':
J = "Aa"
S = "aAAbbbb"
s = Solution()
res = s.numJewelsInStones(J=J,S=S)
print(res)
最新文章
- GL_ARRAY_BUFFER 和 GL_ELEMENT_ARRAY_BUFFER
- 记”Uri.IsWellFormedUriString”中的BUG
- Codevs 1001 舒适的路线 2006年 NOIP全国联赛提高组
- lock语句的递归问题
- Mozilla对HTML5规范支持列表
- CodeFirst Fluent API
- 顶尖数据挖掘教学案例库(TipDM-C10)产品白皮书
- Python 实现类似PHP的strip_tags函数功能,并且可以自定义设置保留标签
- 学习任务在继续...css...
- ionic 的缓存 和局部刷新
- c# 后台分页 jqgrid
- spark查看DF的partition数目及每个partition中的数据量【集群模式】
- Win10升级.NET Framework 3.5或2.0遇到错误0x800f081f怎么办
- JavaScript 字典
- cocos2dx解决中文乱码方法
- Angularjs的directive封装ztree
- 《mysql必知必会》学习_sql文件导入数据库_20180724_欢
- 【转】【MySQL报错】ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 43, found 39.
- codeforces#514 Div2---1059ABCD
- Java基础——注释规范
热门文章
- vue+ElementUI 日期选择器 获取时间戳
- js实现的时间轴效果
- POJ 3762 The Bonus Salary!
- Android之——自己主动挂断电话的实现
- const指针总结
- hdu 2883 kebab(时间区间压缩 &;amp;&;amp; dinic)
- 【iOS开发-80】Quartz2D画图简单介绍:直线/圆形/椭圆/方形以及上下文栈管理CGContextSaveGState/CGContextRestoreGState
- POJ 2553 The Bottom of a Graph(强连通分量)
- Android开机键失灵启动手机的解决的方法
- [POJ 1639] Picnic Planning