给定字符串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)

最新文章

  1. GL_ARRAY_BUFFER 和 GL_ELEMENT_ARRAY_BUFFER
  2. 记”Uri.IsWellFormedUriString”中的BUG
  3. Codevs 1001 舒适的路线 2006年 NOIP全国联赛提高组
  4. lock语句的递归问题
  5. Mozilla对HTML5规范支持列表
  6. CodeFirst Fluent API
  7. 顶尖数据挖掘教学案例库(TipDM-C10)产品白皮书
  8. Python 实现类似PHP的strip_tags函数功能,并且可以自定义设置保留标签
  9. 学习任务在继续...css...
  10. ionic 的缓存 和局部刷新
  11. c# 后台分页 jqgrid
  12. spark查看DF的partition数目及每个partition中的数据量【集群模式】
  13. Win10升级.NET Framework 3.5或2.0遇到错误0x800f081f怎么办
  14. JavaScript 字典
  15. cocos2dx解决中文乱码方法
  16. Angularjs的directive封装ztree
  17. 《mysql必知必会》学习_sql文件导入数据库_20180724_欢
  18. 【转】【MySQL报错】ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 43, found 39.
  19. codeforces#514 Div2---1059ABCD
  20. Java基础——注释规范

热门文章

  1. vue+ElementUI 日期选择器 获取时间戳
  2. js实现的时间轴效果
  3. POJ 3762 The Bonus Salary!
  4. Android之——自己主动挂断电话的实现
  5. const指针总结
  6. hdu 2883 kebab(时间区间压缩 && dinic)
  7. 【iOS开发-80】Quartz2D画图简单介绍:直线/圆形/椭圆/方形以及上下文栈管理CGContextSaveGState/CGContextRestoreGState
  8. POJ 2553 The Bottom of a Graph(强连通分量)
  9. Android开机键失灵启动手机的解决的方法
  10. [POJ 1639] Picnic Planning