博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【leecode】宝石与石头
阅读量:4619 次
发布时间:2019-06-09

本文共 1173 字,大约阅读时间需要 3 分钟。

 给定字符串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 numif __name__ == '__main__':    J = "Aa"    S = "aAAbbbb"    s = Solution()    res = s.numJewelsInStones(J=J,S=S)    print(res)

 

转载于:https://www.cnblogs.com/pandaboy1123/p/10017724.html

你可能感兴趣的文章
C语言学习笔记--字符串
查看>>
关于七牛进行图片添加文字水印操作小计
查看>>
DataSource数据库的使用
查看>>
Luogu4069 SDOI2016 游戏 树链剖分、李超线段树
查看>>
Java的内部类真的那么难以理解?
查看>>
一文搞懂Java环境,轻松实现Hello World!
查看>>
hash实现锚点平滑滚动定位
查看>>
也谈智能手机游戏开发中的分辨率自适应问题
查看>>
关于 IOS 发布的点点滴滴记录(一)
查看>>
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>
CSS——水平/垂直居中
查看>>
Eclipse连接mysql数据库jdbc下载(图文)
查看>>
Python中Selenium的使用方法
查看>>
三月23日测试Fiddler
查看>>
20171013_数据库新环境后期操作
查看>>
poj 1654 && poj 1675
查看>>
运维派 企业面试题1 监控MySQL主从同步是否异常
查看>>
Docker 版本
查看>>
poj 1753 Flip Game
查看>>
在深信服实习是怎样的体验(研发测试岗)
查看>>