[LeetCode&Python] Problem 771: Jewels and Stones
2021-06-27 23:06
标签:aabb bbb out one you als guarantee note mos You‘re given strings The letters in Example 1: Example 2: Note: [LeetCode&Python] Problem 771: Jewels and Stones 标签:aabb bbb out one you als guarantee note mos 原文地址:https://www.cnblogs.com/chiyeung/p/9650663.htmlJ
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.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"
.Input: J = "aA", S = "aAAbbbb"
Output: 3
Input: J = "z", S = "ZZ"
Output: 0
S
and J
will consist of letters and have length at most 50.J
are distinct.class Solution:
def numJewelsInStones(self, J, S):
"""
:type J: str
:type S: str
:rtype: int
"""
return len([elem for elem in S if elem in J])
文章标题:[LeetCode&Python] Problem 771: Jewels and Stones
文章链接:http://soscw.com/index.php/essay/98634.html