美文网首页
LeetCode-771-宝石与石头

LeetCode-771-宝石与石头

作者: 阿凯被注册了 | 来源:发表于2020-10-13 08:33 被阅读0次
    image.png

    解题思路

    1. J不重复,则令J为字典;
    2. 遍历S,若S[i]在J中则结果+1。

    Python3代码

    class Solution:
        def numJewelsInStones(self, J: str, S: str) -> int:
            j = set(J)
            ans=0
            for i in S:
                if i in j:
                    ans+=1
            return ans
    

    相关文章

      网友评论

          本文标题:LeetCode-771-宝石与石头

          本文链接:https://www.haomeiwen.com/subject/eszdpktx.html